From cc506517584e5bec940fcf0ce150395f6f365f48 Mon Sep 17 00:00:00 2001 From: Nicolas Gailly Date: Fri, 15 Nov 2024 17:17:39 +0100 Subject: [PATCH] change dialect to generic (#410) --- parsil/src/parser.rs | 19 ++++++++++++++----- parsil/src/utils.rs | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/parsil/src/parser.rs b/parsil/src/parser.rs index ddd907550..a50d438c3 100644 --- a/parsil/src/parser.rs +++ b/parsil/src/parser.rs @@ -2,15 +2,13 @@ use anyhow::*; use log::*; use sqlparser::{ ast::{Query, Statement}, - dialect::AnsiDialect, + dialect::GenericDialect, parser::Parser, }; -use crate::{symbols::ContextProvider, utils::ParsilSettings}; +const DIALECT: GenericDialect = GenericDialect {}; -const DIALECT: AnsiDialect = AnsiDialect {}; - -pub fn parse(_settings: &ParsilSettings, req: &str) -> Result { +pub fn parse(req: &str) -> Result { debug!("Parsing `{req}`"); let mut parsed = Parser::parse_sql(&DIALECT, req).with_context(|| format!("trying to parse `{req}`"))?; @@ -27,3 +25,14 @@ pub fn parse(_settings: &ParsilSettings, req: &str) -> Re bail!("expected query, found `{}`", parsed[0]) } } + +#[cfg(test)] +mod test { + use super::parse; + + #[test] + fn test_parsing_query_underscore() { + let req = "SELECT AVG(value / _totalSupply) FROM myTable;"; + parse(req).unwrap(); + } +} diff --git a/parsil/src/utils.rs b/parsil/src/utils.rs index a45022b55..f328ace39 100644 --- a/parsil/src/utils.rs +++ b/parsil/src/utils.rs @@ -191,7 +191,7 @@ pub fn parse_and_validate( query: &str, settings: &ParsilSettings, ) -> anyhow::Result { - let mut query = parser::parse(&settings, query)?; + let mut query = parser::parse(query)?; expand::expand(&settings, &mut query)?; placeholders::validate(settings, &query)?;