-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Improved ergonomy for CREATE EXTERNAL TABLE OPTIONS
: Don't require quotations for simple namespaced keys like foo.bar
#10483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -462,7 +462,18 @@ impl<'a> DFParser<'a> { | |
pub fn parse_option_key(&mut self) -> Result<String, ParserError> { | ||
let next_token = self.parser.next_token(); | ||
match next_token.token { | ||
Token::Word(Word { value, .. }) => Ok(value), | ||
Token::Word(Word { value, .. }) => { | ||
let mut parts = vec![value]; | ||
while self.parser.consume_token(&Token::Period) { | ||
let next_token = self.parser.next_token(); | ||
if let Token::Word(Word { value, .. }) = next_token.token { | ||
parts.push(value); | ||
} else { | ||
return self.parser.expected("key name", next_token); | ||
} | ||
} | ||
Ok(parts.join(".")) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main change, the rest is clean-up. |
||
Token::SingleQuotedString(s) => Ok(s), | ||
Token::DoubleQuotedString(s) => Ok(s), | ||
Token::EscapedStringLiteral(s) => Ok(s), | ||
|
@@ -712,15 +723,15 @@ impl<'a> DFParser<'a> { | |
} else { | ||
self.parser.expect_keyword(Keyword::HEADER)?; | ||
self.parser.expect_keyword(Keyword::ROW)?; | ||
return parser_err!("WITH HEADER ROW clause is no longer in use. Please use the OPTIONS clause with 'format.has_header' set appropriately, e.g., OPTIONS ('format.has_header' 'true')"); | ||
return parser_err!("WITH HEADER ROW clause is no longer in use. Please use the OPTIONS clause with 'format.has_header' set appropriately, e.g., OPTIONS (format.has_header true)"); | ||
} | ||
} | ||
Keyword::DELIMITER => { | ||
return parser_err!("DELIMITER clause is no longer in use. Please use the OPTIONS clause with 'format.delimiter' set appropriately, e.g., OPTIONS ('format.delimiter' ',')"); | ||
return parser_err!("DELIMITER clause is no longer in use. Please use the OPTIONS clause with 'format.delimiter' set appropriately, e.g., OPTIONS (format.delimiter ',')"); | ||
} | ||
Keyword::COMPRESSION => { | ||
self.parser.expect_keyword(Keyword::TYPE)?; | ||
return parser_err!("COMPRESSION TYPE clause is no longer in use. Please use the OPTIONS clause with 'format.compression' set appropriately, e.g., OPTIONS ('format.compression' 'gzip')"); | ||
return parser_err!("COMPRESSION TYPE clause is no longer in use. Please use the OPTIONS clause with 'format.compression' set appropriately, e.g., OPTIONS (format.compression gzip)"); | ||
} | ||
Keyword::PARTITIONED => { | ||
self.parser.expect_keyword(Keyword::BY)?; | ||
|
@@ -933,7 +944,7 @@ mod tests { | |
expect_parse_ok(sql, expected)?; | ||
|
||
// positive case with delimiter | ||
let sql = "CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV LOCATION 'foo.csv' OPTIONS ('format.delimiter' '|')"; | ||
let sql = "CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV LOCATION 'foo.csv' OPTIONS (format.delimiter '|')"; | ||
let display = None; | ||
let expected = Statement::CreateExternalTable(CreateExternalTable { | ||
name: "t".into(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,8 +190,8 @@ LOCATION 'test_files/scratch/create_external_table/manual_partitioning/'; | |
statement error DataFusion error: Error during planning: Option format.delimiter is specified multiple times | ||
CREATE EXTERNAL TABLE t STORED AS CSV OPTIONS ( | ||
'format.delimiter' '*', | ||
'format.has_header' 'true', | ||
'format.delimiter' '|') | ||
'format.has_header' 'true', | ||
'format.delimiter' '|') | ||
LOCATION 'foo.csv'; | ||
|
||
# If a config does not belong to any namespace, we assume it is a 'format' option and apply the 'format' prefix for backwards compatibility. | ||
|
@@ -201,7 +201,20 @@ CREATE EXTERNAL TABLE IF NOT EXISTS region ( | |
r_name VARCHAR, | ||
r_comment VARCHAR, | ||
r_rev VARCHAR, | ||
) STORED AS CSV LOCATION 'test_files/tpch/data/region.tbl' | ||
) STORED AS CSV LOCATION 'test_files/tpch/data/region.tbl' | ||
OPTIONS ( | ||
'format.delimiter' '|', | ||
'has_header' 'false'); | ||
'has_header' 'false'); | ||
|
||
# Verify that we do not need quotations for simple namespaced keys. | ||
statement ok | ||
CREATE EXTERNAL TABLE IF NOT EXISTS region ( | ||
r_regionkey BIGINT, | ||
r_name VARCHAR, | ||
r_comment VARCHAR, | ||
r_rev VARCHAR, | ||
) STORED AS CSV LOCATION 'test_files/tpch/data/region.tbl' | ||
OPTIONS ( | ||
format.delimiter '|', | ||
has_header false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
compression gzip); |
Uh oh!
There was an error while loading. Please reload this page.