Skip to content

Apache DataFusion SQL Query Engine

Update sql parser to v0.20.0 (#3072)

Wei-Ting Kuoacd1f40e7b5b
diff --git a/datafusion/common/Cargo.toml b/datafusion/common/Cargo.toml
index 33d6af087d..9bab66adab 100644
--- a/datafusion/common/Cargo.toml
+++ b/datafusion/common/Cargo.toml
@@ -46,4 +46,4 @@ ordered-float = "3.0"
parquet = { version = "19.0.0", features = ["arrow"], optional = true }
pyo3 = { version = "0.16", optional = true }
serde_json = "1.0"
-sqlparser = "0.19"
+sqlparser = "0.20"
diff --git a/datafusion/core/Cargo.toml b/datafusion/core/Cargo.toml
index 073b951ffb..a76b2fc49b 100644
--- a/datafusion/core/Cargo.toml
+++ b/datafusion/core/Cargo.toml
@@ -85,7 +85,7 @@ pyo3 = { version = "0.16", optional = true }
rand = "0.8"
rayon = { version = "1.5", optional = true }
smallvec = { version = "1.6", features = ["union"] }
-sqlparser = "0.19"
+sqlparser = "0.20"
tempfile = "3"
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "fs", "parking_lot"] }
tokio-stream = "0.1"
diff --git a/datafusion/core/tests/sql/joins.rs b/datafusion/core/tests/sql/joins.rs
index d1632277a3..19de20d613 100644
--- a/datafusion/core/tests/sql/joins.rs
+++ b/datafusion/core/tests/sql/joins.rs
@@ -897,6 +897,41 @@ async fn inner_join_qualified_names() -> Result<()> {
Ok(())
}
+#[tokio::test]
+async fn nestedjoin_with_alias() -> Result<()> {
+ // repro case for https://github.com/apache/arrow-datafusion/issues/2867
+ let sql = "select * from ((select 1 as a, 2 as b) c INNER JOIN (select 1 as a, 3 as d) e on c.a = e.a) f;";
+ let expected = vec![
+ "+---+---+---+---+",
+ "| a | b | a | d |",
+ "+---+---+---+---+",
+ "| 1 | 2 | 1 | 3 |",
+ "+---+---+---+---+",
+ ];
+ let ctx = SessionContext::new();
+ let actual = execute_to_batches(&ctx, sql).await;
+ assert_batches_eq!(expected, &actual);
+
+ Ok(())
+}
+
+#[tokio::test]
+async fn nestedjoin_without_alias() -> Result<()> {
+ let sql = "select * from (select 1 as a, 2 as b) c INNER JOIN (select 1 as a, 3 as d) e on c.a = e.a;";
+ let expected = vec![
+ "+---+---+---+---+",
+ "| a | b | a | d |",
+ "+---+---+---+---+",
+ "| 1 | 2 | 1 | 3 |",
+ "+---+---+---+---+",
+ ];
+ let ctx = SessionContext::new();
+ let actual = execute_to_batches(&ctx, sql).await;
+ assert_batches_eq!(expected, &actual);
+
+ Ok(())
+}
+
#[tokio::test]
async fn issue_3002() -> Result<()> {
// repro case for https://github.com/apache/arrow-datafusion/issues/3002
diff --git a/datafusion/expr/Cargo.toml b/datafusion/expr/Cargo.toml
index e99a24c320..923015ae57 100644
--- a/datafusion/expr/Cargo.toml
+++ b/datafusion/expr/Cargo.toml
@@ -38,4 +38,4 @@ path = "src/lib.rs"
ahash = { version = "0.7", default-features = false }
arrow = { version = "19.0.0", features = ["prettyprint"] }
datafusion-common = { path = "../common", version = "10.0.0" }
-sqlparser = "0.19"
+sqlparser = "0.20"
diff --git a/datafusion/sql/Cargo.toml b/datafusion/sql/Cargo.toml
index 760a58587e..17e6583995 100644
--- a/datafusion/sql/Cargo.toml
+++ b/datafusion/sql/Cargo.toml
@@ -42,5 +42,5 @@ arrow = { version = "19.0.0", features = ["prettyprint"] }
datafusion-common = { path = "../common", version = "10.0.0" }
datafusion-expr = { path = "../expr", version = "10.0.0" }
hashbrown = "0.12"
-sqlparser = "0.19"
+sqlparser = "0.20"
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "fs", "parking_lot"] }
diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs
index d93076fbdd..6c3e80e322 100644
--- a/datafusion/sql/src/planner.rs
+++ b/datafusion/sql/src/planner.rs
@@ -728,9 +728,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
alias,
)
}
- TableFactor::NestedJoin(table_with_joins) => (
+ TableFactor::NestedJoin {
+ table_with_joins,
+ alias,
+ } => (
self.plan_table_with_joins(*table_with_joins, ctes, outer_query_schema)?,
- None,
+ alias,
),
// @todo Support TableFactory::TableFunction?
_ => {