From da59ec1565557248d10039e9bb6a3e5d2fe9a3cf Mon Sep 17 00:00:00 2001 From: Dandandan Date: Fri, 12 Jun 2020 07:47:57 +0200 Subject: [PATCH 1/3] Make FileFormat case insensitive --- src/parser.rs | 2 +- tests/sqlparser_common.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index d2ab7b1ae..7abc2d249 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1006,7 +1006,7 @@ impl Parser { let table_name = self.parse_object_name()?; let (columns, constraints) = self.parse_columns()?; self.expect_keywords(&[Keyword::STORED, Keyword::AS])?; - let file_format = self.parse_identifier()?.value.parse::()?; + let file_format = self.parse_identifier()?.value.to_ascii_uppercase().parse::()?; self.expect_keyword(Keyword::LOCATION)?; let location = self.parse_literal_string()?; diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 3b55f8b8f..5599eab91 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -1289,6 +1289,24 @@ fn parse_create_external_table() { } } +#[test] +fn parse_create_external_table_lowercase() { + let sql = "create external table uk_cities (\ + name varchar(100) not null,\ + lat double null,\ + lng double)\ + stored as parquet location '/tmp/example.csv'"; + let ast = one_statement_parses_to( + sql, + "CREATE EXTERNAL TABLE uk_cities (\ + name character varying(100) NOT NULL, \ + lat double NULL, \ + lng double) \ + STORED AS PARQUET LOCATION '/tmp/example.csv'", + ); + assert_matches!(ast, Statement::CreateTable{..}); +} + #[test] fn parse_create_table_empty() { // Zero-column tables are weird, but supported by at least PostgreSQL. From e32a9dadf294319befe8493409fcf65561fd47cf Mon Sep 17 00:00:00 2001 From: Dandandan Date: Fri, 12 Jun 2020 08:51:32 +0200 Subject: [PATCH 2/3] Formatting --- src/parser.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index 7abc2d249..e3784b357 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1006,7 +1006,11 @@ impl Parser { let table_name = self.parse_object_name()?; let (columns, constraints) = self.parse_columns()?; self.expect_keywords(&[Keyword::STORED, Keyword::AS])?; - let file_format = self.parse_identifier()?.value.to_ascii_uppercase().parse::()?; + let file_format = self + .parse_identifier()? + .value + .to_ascii_uppercase() + .parse::()?; self.expect_keyword(Keyword::LOCATION)?; let location = self.parse_literal_string()?; From e994b6858049cb9f4c20130eaa3bdec98b39094c Mon Sep 17 00:00:00 2001 From: Nickolay Ponomarev Date: Fri, 12 Jun 2020 18:09:51 +0300 Subject: [PATCH 3/3] Add a note about `parse_identifier` being inappropriate here --- src/parser.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/parser.rs b/src/parser.rs index e3784b357..4993eb29a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1006,6 +1006,7 @@ impl Parser { let table_name = self.parse_object_name()?; let (columns, constraints) = self.parse_columns()?; self.expect_keywords(&[Keyword::STORED, Keyword::AS])?; + // We probably shouldn't parse the file format as an identifier.. let file_format = self .parse_identifier()? .value