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 b67c6f20b3d8e..a0784ff96def8 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 ccd94edd0f815..b1116af3cfea0 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()?);