Skip to content

Commit

Permalink
change dialect to generic (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkolasg authored Nov 15, 2024
1 parent a03e407 commit cc50651
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions parsil/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C: ContextProvider>(_settings: &ParsilSettings<C>, req: &str) -> Result<Query> {
pub fn parse(req: &str) -> Result<Query> {
debug!("Parsing `{req}`");
let mut parsed =
Parser::parse_sql(&DIALECT, req).with_context(|| format!("trying to parse `{req}`"))?;
Expand All @@ -27,3 +25,14 @@ pub fn parse<C: ContextProvider>(_settings: &ParsilSettings<C>, 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();
}
}
2 changes: 1 addition & 1 deletion parsil/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub fn parse_and_validate<C: ContextProvider>(
query: &str,
settings: &ParsilSettings<C>,
) -> anyhow::Result<Query> {
let mut query = parser::parse(&settings, query)?;
let mut query = parser::parse(query)?;
expand::expand(&settings, &mut query)?;

placeholders::validate(settings, &query)?;
Expand Down

0 comments on commit cc50651

Please sign in to comment.