Skip to content

Commit 032dcde

Browse files
committed
Update parser and external table
1 parent 0eb9e7e commit 032dcde

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ recursive = "0.1.1"
164164
regex = "1.8"
165165
rstest = "0.24.0"
166166
serde_json = "1"
167-
sqlparser = { git = "https://github.com/Embucket/datafusion-sqlparser-rs.git", rev = "3ca4928b7c582121eb2bf42dc343d4756267dae3", features = [
167+
sqlparser = { git = "https://github.com/Embucket/datafusion-sqlparser-rs.git", rev = "4a91f2fd6af1b6d413621949e724c55c34f8a29b", features = [
168168
"visitor",
169169
] }
170170
tempfile = "3"

datafusion/sql/src/parser.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,14 @@ impl<'a> DFParser<'a> {
695695

696696
/// Parse a SQL `CREATE` statement handling `CREATE EXTERNAL TABLE`
697697
pub fn parse_create(&mut self) -> Result<Statement, DataFusionError> {
698-
if self.parser.parse_keyword(Keyword::EXTERNAL) {
698+
if self
699+
.parser
700+
.parse_keywords(&[Keyword::EXTERNAL, Keyword::TABLE])
701+
{
699702
self.parse_create_external_table(false)
700703
} else if self.parser.parse_keyword(Keyword::UNBOUNDED) {
701-
self.parser.expect_keyword(Keyword::EXTERNAL)?;
704+
self.parser
705+
.expect_keywords(&[Keyword::EXTERNAL, Keyword::TABLE])?;
702706
self.parse_create_external_table(true)
703707
} else {
704708
// Push back CREATE
@@ -856,7 +860,6 @@ impl<'a> DFParser<'a> {
856860
.parser
857861
.parse_one_of_keywords(&[Keyword::TEMP, Keyword::TEMPORARY])
858862
.is_some();
859-
self.parser.expect_keyword(Keyword::TABLE)?;
860863
let if_not_exists =
861864
self.parser
862865
.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
@@ -1595,6 +1598,24 @@ mod tests {
15951598
Ok(())
15961599
}
15971600

1601+
#[test]
1602+
fn skip_external_volume() -> Result<(), DataFusionError> {
1603+
let sql = "CREATE OR REPLACE EXTERNAL VOLUME exvol STORAGE_LOCATIONS =
1604+
((NAME = 's3' STORAGE_PROVIDER = 'S3' STORAGE_BASE_URL = 's3://my-example-bucket/' ))";
1605+
let dialect = Box::new(SnowflakeDialect);
1606+
let statements = DFParser::parse_sql_with_dialect(sql, dialect.as_ref())?;
1607+
1608+
assert_eq!(
1609+
statements.len(),
1610+
1,
1611+
"Expected to parse exactly one statement"
1612+
);
1613+
if let Statement::CreateExternalTable(_) = &statements[0] {
1614+
panic!("Expected non CREATE EXTERNAL TABLE statement, but was successful: {statements:?}");
1615+
}
1616+
Ok(())
1617+
}
1618+
15981619
#[test]
15991620
fn explain_copy_to_table_to_table() -> Result<(), DataFusionError> {
16001621
let cases = vec![

0 commit comments

Comments
 (0)