From 045f9c1d0511032bb78c7e38c09060d1e1b1c69c Mon Sep 17 00:00:00 2001 From: Chris Allen Date: Tue, 27 Sep 2022 19:03:18 -0500 Subject: [PATCH] Patch to deal with backticked identifiers in GenericDialect --- src/dialect/mod.rs | 2 +- tests/sqlparser_hive.rs | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/dialect/mod.rs b/src/dialect/mod.rs index e174528b0..2b21f3762 100644 --- a/src/dialect/mod.rs +++ b/src/dialect/mod.rs @@ -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>) -> bool { diff --git a/tests/sqlparser_hive.rs b/tests/sqlparser_hive.rs index 6ca47e12c..8e58516c9 100644 --- a/tests/sqlparser_hive.rs +++ b/tests/sqlparser_hive.rs @@ -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] @@ -32,6 +32,20 @@ fn parse_table_create() { hive().verified_stmt(iof); } +fn generic(options: Option) -> 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"#; @@ -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() )