Skip to content

Commit

Permalink
Improve error message for CREATE EXTERNAL TABLE (apache#6291)
Browse files Browse the repository at this point in the history
* Improve error message for CREATE EXTERNAL TABLE

* change error message by using expect_keyword
parkma99 authored May 10, 2023
1 parent 7cf248b commit 6cdfbc6
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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';
20 changes: 10 additions & 10 deletions datafusion/sql/src/parser.rs
Original file line number Diff line number Diff line change
@@ -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()?);

0 comments on commit 6cdfbc6

Please sign in to comment.