Skip to content

Commit acd1f40

Browse files
authored
Update sql parser to v0.20.0 (#3072)
* add test case nestedjoin_with_alias (issue2867) * upgrade sqlparser to 0.20 * add test case for nestedjoin without alias
1 parent 68b205f commit acd1f40

6 files changed

Lines changed: 44 additions & 6 deletions

File tree

datafusion/common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ ordered-float = "3.0"
4646
parquet = { version = "19.0.0", features = ["arrow"], optional = true }
4747
pyo3 = { version = "0.16", optional = true }
4848
serde_json = "1.0"
49-
sqlparser = "0.19"
49+
sqlparser = "0.20"

datafusion/core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pyo3 = { version = "0.16", optional = true }
8585
rand = "0.8"
8686
rayon = { version = "1.5", optional = true }
8787
smallvec = { version = "1.6", features = ["union"] }
88-
sqlparser = "0.19"
88+
sqlparser = "0.20"
8989
tempfile = "3"
9090
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "fs", "parking_lot"] }
9191
tokio-stream = "0.1"

datafusion/core/tests/sql/joins.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,41 @@ async fn inner_join_qualified_names() -> Result<()> {
897897
Ok(())
898898
}
899899

900+
#[tokio::test]
901+
async fn nestedjoin_with_alias() -> Result<()> {
902+
// repro case for https://github.com/apache/arrow-datafusion/issues/2867
903+
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;";
904+
let expected = vec![
905+
"+---+---+---+---+",
906+
"| a | b | a | d |",
907+
"+---+---+---+---+",
908+
"| 1 | 2 | 1 | 3 |",
909+
"+---+---+---+---+",
910+
];
911+
let ctx = SessionContext::new();
912+
let actual = execute_to_batches(&ctx, sql).await;
913+
assert_batches_eq!(expected, &actual);
914+
915+
Ok(())
916+
}
917+
918+
#[tokio::test]
919+
async fn nestedjoin_without_alias() -> Result<()> {
920+
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;";
921+
let expected = vec![
922+
"+---+---+---+---+",
923+
"| a | b | a | d |",
924+
"+---+---+---+---+",
925+
"| 1 | 2 | 1 | 3 |",
926+
"+---+---+---+---+",
927+
];
928+
let ctx = SessionContext::new();
929+
let actual = execute_to_batches(&ctx, sql).await;
930+
assert_batches_eq!(expected, &actual);
931+
932+
Ok(())
933+
}
934+
900935
#[tokio::test]
901936
async fn issue_3002() -> Result<()> {
902937
// repro case for https://github.com/apache/arrow-datafusion/issues/3002

datafusion/expr/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ path = "src/lib.rs"
3838
ahash = { version = "0.7", default-features = false }
3939
arrow = { version = "19.0.0", features = ["prettyprint"] }
4040
datafusion-common = { path = "../common", version = "10.0.0" }
41-
sqlparser = "0.19"
41+
sqlparser = "0.20"

datafusion/sql/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ arrow = { version = "19.0.0", features = ["prettyprint"] }
4242
datafusion-common = { path = "../common", version = "10.0.0" }
4343
datafusion-expr = { path = "../expr", version = "10.0.0" }
4444
hashbrown = "0.12"
45-
sqlparser = "0.19"
45+
sqlparser = "0.20"
4646
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "fs", "parking_lot"] }

datafusion/sql/src/planner.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
728728
alias,
729729
)
730730
}
731-
TableFactor::NestedJoin(table_with_joins) => (
731+
TableFactor::NestedJoin {
732+
table_with_joins,
733+
alias,
734+
} => (
732735
self.plan_table_with_joins(*table_with_joins, ctes, outer_query_schema)?,
733-
None,
736+
alias,
734737
),
735738
// @todo Support TableFactory::TableFunction?
736739
_ => {

0 commit comments

Comments
 (0)