This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/master by this push:
new 0bb5d4d9b Fix bugs in parsing `with header row` and `partitioned by`
(#4268)
0bb5d4d9b is described below
commit 0bb5d4d9b885b909bbdd27230880c8a94602f295
Author: Remzi Yang <[email protected]>
AuthorDate: Sun Nov 20 19:55:18 2022 +0800
Fix bugs in parsing `with header row` and `partitioned by` (#4268)
* fix header and partitioned
Signed-off-by: remzi <[email protected]>
* fix comment bug
Signed-off-by: remzi <[email protected]>
Signed-off-by: remzi <[email protected]>
---
datafusion/sql/src/parser.rs | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/datafusion/sql/src/parser.rs b/datafusion/sql/src/parser.rs
index fe0c24b46..23deafee6 100644
--- a/datafusion/sql/src/parser.rs
+++ b/datafusion/sql/src/parser.rs
@@ -428,15 +428,15 @@ impl<'a> DFParser<'a> {
false
}
}
+
fn parse_has_file_compression_type(&mut self) -> bool {
self.consume_token(&Token::make_keyword("COMPRESSION"))
& self.consume_token(&Token::make_keyword("TYPE"))
}
fn parse_csv_has_header(&mut self) -> bool {
- self.consume_token(&Token::make_keyword("WITH"))
- & self.consume_token(&Token::make_keyword("HEADER"))
- & self.consume_token(&Token::make_keyword("ROW"))
+ self.parser
+ .parse_keywords(&[Keyword::WITH, Keyword::HEADER, Keyword::ROW])
}
fn parse_has_delimiter(&mut self) -> bool {
@@ -454,8 +454,8 @@ impl<'a> DFParser<'a> {
}
fn parse_has_partition(&mut self) -> bool {
- self.consume_token(&Token::make_keyword("PARTITIONED"))
- & self.consume_token(&Token::make_keyword("BY"))
+ self.parser
+ .parse_keywords(&[Keyword::PARTITIONED, Keyword::BY])
}
}
@@ -715,6 +715,17 @@ mod tests {
"CREATE EXTERNAL TABLE t STORED AS x OPTIONS ('k1' 'v1', k2 v2,
k3) LOCATION 'blahblah'";
expect_parse_error(sql, "sql parser error: Expected literal string,
found: )");
+ // Error case: `with header` is an invalid syntax
+ let sql = "CREATE EXTERNAL TABLE t STORED AS CSV WITH HEADER LOCATION
'abc'";
+ expect_parse_error(sql, "sql parser error: Expected LOCATION, found:
WITH");
+
+ // Error case: `partitioned` is an invalid syntax
+ let sql = "CREATE EXTERNAL TABLE t STORED AS CSV PARTITIONED LOCATION
'abc'";
+ expect_parse_error(
+ sql,
+ "sql parser error: Expected LOCATION, found: PARTITIONED",
+ );
+
Ok(())
}
}