Skip to content

Commit

Permalink
Patch to deal with backticked identifiers in GenericDialect
Browse files Browse the repository at this point in the history
  • Loading branch information
bitemyapp authored and Chris A. committed Oct 19, 2023
1 parent 83cb734 commit 045f9c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub trait Dialect: Debug + Any {
/// MySQL, MS SQL, and sqlite). You can accept one of characters listed
/// in `Word::matching_end_quote` here
fn is_delimited_identifier_start(&self, ch: char) -> bool {
ch == '"'
ch == '"' || ch == '`'
}
/// Determine if quoted characters are proper for identifier
fn is_proper_identifier_inside_quotes(&self, mut _chars: Peekable<Chars<'_>>) -> bool {
Expand Down
23 changes: 16 additions & 7 deletions tests/sqlparser_hive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use sqlparser::ast::{
SelectItem, Statement, TableFactor, UnaryOperator, Value,
};
use sqlparser::dialect::{GenericDialect, HiveDialect};
use sqlparser::parser::ParserError;
use sqlparser::parser::{ParserError, ParserOptions};
use sqlparser::test_utils::*;

#[test]
Expand All @@ -32,6 +32,20 @@ fn parse_table_create() {
hive().verified_stmt(iof);
}

fn generic(options: Option<ParserOptions>) -> TestedDialects {
TestedDialects {
dialects: vec![Box::new(GenericDialect {})],
options,
}
}

#[test]
fn parse_describe() {
let describe = r#"DESCRIBE namespace.`table`"#;
hive().verified_stmt(describe);
generic(None).verified_stmt(describe);
}

#[test]
fn parse_insert_overwrite() {
let insert_partitions = r#"INSERT OVERWRITE TABLE db.new_table PARTITION (a = '1', b) SELECT a, b, c FROM db.table"#;
Expand Down Expand Up @@ -265,13 +279,8 @@ fn parse_create_function() {
_ => unreachable!(),
}

let generic = TestedDialects {
dialects: vec![Box::new(GenericDialect {})],
options: None,
};

assert_eq!(
generic.parse_sql_statements(sql).unwrap_err(),
generic(None).parse_sql_statements(sql).unwrap_err(),
ParserError::ParserError(
"Expected an object type after CREATE, found: FUNCTION".to_string()
)
Expand Down

0 comments on commit 045f9c1

Please sign in to comment.