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 2023/05/10 00:21:14 UTC

[arrow-datafusion] branch main updated: Improve error message for CREATE EXTERNAL TABLE (#6291)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 6cdfbc6f1d Improve error message for CREATE EXTERNAL TABLE (#6291)
6cdfbc6f1d is described below

commit 6cdfbc6f1d04dbe1fe22a2ec362f096b3de4d155
Author: parkma99 <84...@users.noreply.github.com>
AuthorDate: Wed May 10 08:21:08 2023 +0800

    Improve error message for CREATE EXTERNAL TABLE (#6291)
    
    * Improve error message for CREATE EXTERNAL TABLE
    
    * change error message by using expect_keyword
---
 .../test_files/create_external_table.slt             |  8 ++++++++
 datafusion/sql/src/parser.rs                         | 20 ++++++++++----------
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/datafusion/core/tests/sqllogictests/test_files/create_external_table.slt b/datafusion/core/tests/sqllogictests/test_files/create_external_table.slt
index b67c6f20b3..a0784ff96d 100644
--- a/datafusion/core/tests/sqllogictests/test_files/create_external_table.slt
+++ b/datafusion/core/tests/sqllogictests/test_files/create_external_table.slt
@@ -91,3 +91,11 @@ create EXTERNAL TABLE t(c1 int, c2 int) STORED AS CSV PARTITIONED BY (c1) partit
 # Duplicate `OPTIONS` clause
 statement error DataFusion error: SQL error: ParserError\("OPTIONS specified more than once"\)
 CREATE EXTERNAL TABLE t STORED AS CSV OPTIONS ('k1' 'v1', 'k2' 'v2') OPTIONS ('k3' 'v3') LOCATION 'foo.csv'
+
+# With typo error
+statement error DataFusion error: SQL error: ParserError\("Expected HEADER, found: HEAD"\)
+CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV WITH HEAD ROW LOCATION 'foo.csv';
+
+# Missing `anything` in WITH clause
+statement error DataFusion error: SQL error: ParserError\("Expected HEADER, found: LOCATION"\)
+CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV WITH LOCATION 'foo.csv';
diff --git a/datafusion/sql/src/parser.rs b/datafusion/sql/src/parser.rs
index ccd94edd0f..b1116af3cf 100644
--- a/datafusion/sql/src/parser.rs
+++ b/datafusion/sql/src/parser.rs
@@ -434,16 +434,16 @@ impl<'a> DFParser<'a> {
             } else if self.parser.parse_keyword(Keyword::LOCATION) {
                 ensure_not_set(&builder.location, "LOCATION")?;
                 builder.location = Some(self.parser.parse_literal_string()?);
-            } else if self
-                .parser
-                .parse_keywords(&[Keyword::WITH, Keyword::HEADER])
-            {
-                self.parser.expect_keyword(Keyword::ROW)?;
-                ensure_not_set(&builder.has_header, "WITH HEADER ROW")?;
-                builder.has_header = Some(true);
-            } else if self.parser.parse_keywords(&[Keyword::WITH, Keyword::ORDER]) {
-                ensure_not_set(&builder.order_exprs, "WITH ORDER")?;
-                builder.order_exprs = Some(self.parse_order_by_exprs()?);
+            } else if self.parser.parse_keyword(Keyword::WITH) {
+                if self.parser.parse_keyword(Keyword::ORDER) {
+                    ensure_not_set(&builder.order_exprs, "WITH ORDER")?;
+                    builder.order_exprs = Some(self.parse_order_by_exprs()?);
+                } else {
+                    self.parser.expect_keyword(Keyword::HEADER)?;
+                    self.parser.expect_keyword(Keyword::ROW)?;
+                    ensure_not_set(&builder.has_header, "WITH HEADER ROW")?;
+                    builder.has_header = Some(true);
+                }
             } else if self.parser.parse_keyword(Keyword::DELIMITER) {
                 ensure_not_set(&builder.delimiter, "DELIMITER")?;
                 builder.delimiter = Some(self.parse_delimiter()?);