You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2021/11/07 10:33:35 UTC

[arrow-datafusion] branch master updated: ignore case of `with header row` in sql when creating external table (#1237)

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 a8029e5  ignore case of `with header row` in sql when creating external table (#1237)
a8029e5 is described below

commit a8029e5033c413064a3e0a3fe015240acc2d1664
Author: lichuan6 <74...@users.noreply.github.com>
AuthorDate: Sun Nov 7 18:33:27 2021 +0800

    ignore case of `with header row` in sql when creating external table (#1237)
    
    * Fix `with header row` in sql when creating external table
    
    * adjust comment
    
    * fix ci failed
---
 datafusion/src/sql/parser.rs | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/datafusion/src/sql/parser.rs b/datafusion/src/sql/parser.rs
index c4822c8..49ae869 100644
--- a/datafusion/src/sql/parser.rs
+++ b/datafusion/src/sql/parser.rs
@@ -293,8 +293,10 @@ impl<'a> DFParser<'a> {
         }
     }
 
-    fn consume_token(&mut self, expected: &str) -> bool {
-        if self.parser.peek_token().to_string() == *expected {
+    fn consume_token(&mut self, expected: &Token) -> bool {
+        let token = self.parser.peek_token().to_string().to_uppercase();
+        let token = Token::make_keyword(&token);
+        if token == *expected {
             self.parser.next_token();
             true
         } else {
@@ -303,9 +305,9 @@ impl<'a> DFParser<'a> {
     }
 
     fn parse_csv_has_header(&mut self) -> bool {
-        self.consume_token("WITH")
-            & self.consume_token("HEADER")
-            & self.consume_token("ROW")
+        self.consume_token(&Token::make_keyword("WITH"))
+            & self.consume_token(&Token::make_keyword("HEADER"))
+            & self.consume_token(&Token::make_keyword("ROW"))
     }
 }
 
@@ -372,6 +374,22 @@ mod tests {
         });
         expect_parse_ok(sql, expected)?;
 
+        // positive case: it is ok for case insensitive sql stmt with `WITH HEADER ROW` tokens
+        let sqls = vec![
+            "CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV WITH HEADER ROW LOCATION 'foo.csv'",
+            "CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV with header row LOCATION 'foo.csv'"
+        ];
+        for sql in sqls {
+            let expected = Statement::CreateExternalTable(CreateExternalTable {
+                name: "t".into(),
+                columns: vec![make_column_def("c1", DataType::Int(display))],
+                file_type: FileType::CSV,
+                has_header: true,
+                location: "foo.csv".into(),
+            });
+            expect_parse_ok(sql, expected)?;
+        }
+
         // positive case: it is ok for parquet files not to have columns specified
         let sql = "CREATE EXTERNAL TABLE t STORED AS PARQUET LOCATION 'foo.parquet'";
         let expected = Statement::CreateExternalTable(CreateExternalTable {