Skip to content

Commit b0758c0

Browse files
committed
fix bugs for explain supporting non-correlated subquery
1 parent 813220d commit b0758c0

File tree

7 files changed

+34
-81
lines changed

7 files changed

+34
-81
lines changed

datafusion/core/src/datasource/listing/table.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -880,18 +880,18 @@ impl TableProvider for ListingTable {
880880
None => {} // no ordering required
881881
};
882882

883-
let filters = conjunction(filters.to_vec())
884-
.map(|expr| -> Result<_> {
885-
// NOTE: Use the table schema (NOT file schema) here because `expr` may contain references to partition columns.
883+
let filters = match conjunction(filters.to_vec()) {
884+
Some(expr) => {
886885
let table_df_schema = self.table_schema.as_ref().clone().to_dfschema()?;
887886
let filters = create_physical_expr(
888887
&expr,
889888
&table_df_schema,
890889
state.execution_props(),
891890
)?;
892-
Ok(Some(filters))
893-
})
894-
.unwrap_or(Ok(None))?;
891+
Some(filters)
892+
}
893+
None => None,
894+
};
895895

896896
let Some(object_store_url) =
897897
self.table_paths.first().map(ListingTableUrl::object_store)

datafusion/core/src/physical_planner.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,8 +1792,7 @@ impl DefaultPhysicalPlanner {
17921792
Err(e) => return Err(e),
17931793
}
17941794
}
1795-
Err(e) => stringified_plans
1796-
.push(StringifiedPlan::new(InitialPhysicalPlan, e.to_string())),
1795+
Err(e) => return plan_err!("{}", e.to_string()),
17971796
}
17981797
}
17991798

datafusion/core/tests/dataframe/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ async fn test_count_wildcard_on_where_in() -> Result<()> {
134134
Ok(())
135135
}
136136

137+
/// this should return Err: Physical plan does not support
138+
/// logical expression Exists ignore for now
139+
#[ignore]
137140
#[tokio::test]
138141
async fn test_count_wildcard_on_where_exist() -> Result<()> {
139142
let ctx = create_join_context()?;

datafusion/sqllogictest/test_files/explain.slt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,19 @@ logical_plan
411411
physical_plan
412412
01)ProjectionExec: expr=[{c0:1,c1:2.3,c2:abc} as struct(Int64(1),Float64(2.3),Utf8("abc"))]
413413
02)--PlaceholderRowExec
414+
415+
416+
statement ok
417+
create table t1(a int);
418+
419+
statement ok
420+
create table t2(b int);
421+
422+
query error DataFusion error: Error during planning: This feature is not implemented: Physical plan does not support logical expression Exists\(Exists \{ subquery: <subquery>, negated: false \}\)
423+
explain select a from t1 where exists (select count(*) from t2);
424+
425+
statement ok
426+
drop table t1;
427+
428+
statement ok
429+
drop table t2;

datafusion/sqllogictest/test_files/group_by.slt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4070,18 +4070,12 @@ physical_plan
40704070
08)--------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[c, d], output_ordering=[c@0 ASC NULLS LAST], has_header=true
40714071

40724072
# we do not generate physical plan for Repartition yet (e.g Distribute By queries).
4073-
query TT
4073+
query error DataFusion error: Error during planning: This feature is not implemented: Physical plan does not support DistributeBy partitioning
40744074
EXPLAIN SELECT a, b, sum1
40754075
FROM (SELECT c, b, a, SUM(d) as sum1
40764076
FROM multiple_ordered_table_with_pk
40774077
GROUP BY c)
40784078
DISTRIBUTE BY a
4079-
----
4080-
logical_plan
4081-
01)Repartition: DistributeBy(multiple_ordered_table_with_pk.a)
4082-
02)--Projection: multiple_ordered_table_with_pk.a, multiple_ordered_table_with_pk.b, sum(multiple_ordered_table_with_pk.d) AS sum1
4083-
03)----Aggregate: groupBy=[[multiple_ordered_table_with_pk.c, multiple_ordered_table_with_pk.a, multiple_ordered_table_with_pk.b]], aggr=[[sum(CAST(multiple_ordered_table_with_pk.d AS Int64))]]
4084-
04)------TableScan: multiple_ordered_table_with_pk projection=[a, b, c, d]
40854079

40864080
# union with aggregate
40874081
query TT

datafusion/sqllogictest/test_files/joins.slt

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,19 +4049,8 @@ physical_plan
40494049

40504050

40514051
# Test CROSS JOIN LATERAL syntax (planning)
4052-
query TT
4052+
query error DataFusion error: Error during planning: This feature is not implemented: Physical plan does not support logical expression OuterReferenceColumn\(UInt32, Column \{ relation: Some\(Bare \{ table: "t1" \}\), name: "t1_int" \}\)
40534053
explain select t1_id, t1_name, i from join_t1 t1 cross join lateral (select * from unnest(generate_series(1, t1_int))) as series(i);
4054-
----
4055-
logical_plan
4056-
01)Cross Join:
4057-
02)--SubqueryAlias: t1
4058-
03)----TableScan: join_t1 projection=[t1_id, t1_name]
4059-
04)--SubqueryAlias: series
4060-
05)----Subquery:
4061-
06)------Projection: unnest_placeholder(generate_series(Int64(1),outer_ref(t1.t1_int)),depth=1) AS i
4062-
07)--------Unnest: lists[unnest_placeholder(generate_series(Int64(1),outer_ref(t1.t1_int)))|depth=1] structs[]
4063-
08)----------Projection: generate_series(Int64(1), CAST(outer_ref(t1.t1_int) AS Int64)) AS unnest_placeholder(generate_series(Int64(1),outer_ref(t1.t1_int)))
4064-
09)------------EmptyRelation
40654054

40664055

40674056
# Test CROSS JOIN LATERAL syntax (execution)
@@ -4071,19 +4060,8 @@ select t1_id, t1_name, i from join_t1 t1 cross join lateral (select * from unnes
40714060

40724061

40734062
# Test INNER JOIN LATERAL syntax (planning)
4074-
query TT
4063+
query error DataFusion error: Error during planning: This feature is not implemented: Physical plan does not support logical expression OuterReferenceColumn\(UInt32, Column \{ relation: Some\(Bare \{ table: "t2" \}\), name: "t1_int" \}\)
40754064
explain select t1_id, t1_name, i from join_t1 t2 inner join lateral (select * from unnest(generate_series(1, t1_int))) as series(i) on(t1_id > i);
4076-
----
4077-
logical_plan
4078-
01)Inner Join: Filter: CAST(t2.t1_id AS Int64) > series.i
4079-
02)--SubqueryAlias: t2
4080-
03)----TableScan: join_t1 projection=[t1_id, t1_name]
4081-
04)--SubqueryAlias: series
4082-
05)----Subquery:
4083-
06)------Projection: unnest_placeholder(generate_series(Int64(1),outer_ref(t2.t1_int)),depth=1) AS i
4084-
07)--------Unnest: lists[unnest_placeholder(generate_series(Int64(1),outer_ref(t2.t1_int)))|depth=1] structs[]
4085-
08)----------Projection: generate_series(Int64(1), CAST(outer_ref(t2.t1_int) AS Int64)) AS unnest_placeholder(generate_series(Int64(1),outer_ref(t2.t1_int)))
4086-
09)------------EmptyRelation
40874065

40884066

40894067
# Test INNER JOIN LATERAL syntax (execution)

datafusion/sqllogictest/test_files/update.slt

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,50 +26,22 @@ create table t1(a int, b varchar, c double, d int);
2626
statement ok
2727
set datafusion.optimizer.max_passes = 0;
2828

29-
query TT
29+
query error DataFusion error: Error during planning: This feature is not implemented: Unsupported logical plan: Dml\(Update\)
3030
explain update t1 set a=1, b=2, c=3.0, d=NULL;
31-
----
32-
logical_plan
33-
01)Dml: op=[Update] table=[t1]
34-
02)--Projection: CAST(Int64(1) AS Int32) AS a, CAST(Int64(2) AS Utf8) AS b, Float64(3) AS c, CAST(NULL AS Int32) AS d
35-
03)----TableScan: t1
3631

37-
query TT
32+
query error DataFusion error: Error during planning: This feature is not implemented: Unsupported logical plan: Dml\(Update\)
3833
explain update t1 set a=c+1, b=a, c=c+1.0, d=b;
39-
----
40-
logical_plan
41-
01)Dml: op=[Update] table=[t1]
42-
02)--Projection: CAST(t1.c + CAST(Int64(1) AS Float64) AS Int32) AS a, CAST(t1.a AS Utf8) AS b, t1.c + Float64(1) AS c, CAST(t1.b AS Int32) AS d
43-
03)----TableScan: t1
4434

4535
statement ok
4636
create table t2(a int, b varchar, c double, d int);
4737

4838
## set from subquery
49-
query TT
39+
query error DataFusion error: Error during planning: This feature is not implemented: Physical plan does not support logical expression ScalarSubquery\(<subquery>\)
5040
explain update t1 set b = (select max(b) from t2 where t1.a = t2.a)
51-
----
52-
logical_plan
53-
01)Dml: op=[Update] table=[t1]
54-
02)--Projection: t1.a AS a, (<subquery>) AS b, t1.c AS c, t1.d AS d
55-
03)----Subquery:
56-
04)------Projection: max(t2.b)
57-
05)--------Aggregate: groupBy=[[]], aggr=[[max(t2.b)]]
58-
06)----------Filter: outer_ref(t1.a) = t2.a
59-
07)------------TableScan: t2
60-
08)----TableScan: t1
6141

6242
# set from other table
63-
query TT
43+
query error DataFusion error: Error during planning: This feature is not implemented: Unsupported logical plan: Dml\(Update\)
6444
explain update t1 set b = t2.b, c = t2.a, d = 1 from t2 where t1.a = t2.a and t1.b > 'foo' and t2.c > 1.0;
65-
----
66-
logical_plan
67-
01)Dml: op=[Update] table=[t1]
68-
02)--Projection: t1.a AS a, t2.b AS b, CAST(t2.a AS Float64) AS c, CAST(Int64(1) AS Int32) AS d
69-
03)----Filter: t1.a = t2.a AND t1.b > Utf8("foo") AND t2.c > Float64(1)
70-
04)------Cross Join:
71-
05)--------TableScan: t1
72-
06)--------TableScan: t2
7345

7446
statement ok
7547
create table t3(a int, b varchar, c double, d int);
@@ -79,14 +51,5 @@ query error DataFusion error: SQL error: ParserError\("Expected end of statement
7951
explain update t1 set b = t2.b, c = t3.a, d = 1 from t2, t3 where t1.a = t2.a and t1.a = t3.a;
8052

8153
# test table alias
82-
query TT
54+
query error DataFusion error: Error during planning: This feature is not implemented: Unsupported logical plan: Dml\(Update\)
8355
explain update t1 as T set b = t2.b, c = t.a, d = 1 from t2 where t.a = t2.a and t.b > 'foo' and t2.c > 1.0;
84-
----
85-
logical_plan
86-
01)Dml: op=[Update] table=[t1]
87-
02)--Projection: t.a AS a, t2.b AS b, CAST(t.a AS Float64) AS c, CAST(Int64(1) AS Int32) AS d
88-
03)----Filter: t.a = t2.a AND t.b > Utf8("foo") AND t2.c > Float64(1)
89-
04)------Cross Join:
90-
05)--------SubqueryAlias: t
91-
06)----------TableScan: t1
92-
07)--------TableScan: t2

0 commit comments

Comments
 (0)