Skip to content

Commit 2aed032

Browse files
committed
Differentiate 0-row and 1-row EmptyRelation in EXPLAIN
The `LogicalPlan::EmptyRelation` can produce no rows or exactly 1 null (placeholder) row of the requested schema. When viewing EXPLAIN output of a LogicalPlan it's good to know which one is the case.
1 parent 7d52145 commit 2aed032

File tree

21 files changed

+123
-121
lines changed

21 files changed

+123
-121
lines changed

datafusion/core/tests/dataframe/mod.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ async fn join_on_filter_datatype() -> Result<()> {
12131213
JoinType::Inner,
12141214
Some(Expr::Literal(ScalarValue::Null, None)),
12151215
)?;
1216-
assert_snapshot!(join.into_optimized_plan().unwrap(), @"EmptyRelation");
1216+
assert_snapshot!(join.into_optimized_plan().unwrap(), @"EmptyRelation: rows=0");
12171217

12181218
// JOIN ON expression must be boolean type
12191219
let join = left.join_on(right, JoinType::Inner, Some(lit("TRUE")))?;
@@ -4940,11 +4940,11 @@ async fn test_dataframe_placeholder_missing_param_values() -> Result<()> {
49404940

49414941
assert_snapshot!(
49424942
actual,
4943-
@r###"
4943+
@r"
49444944
Filter: a = $0 [a:Int32]
49454945
Projection: Int32(1) AS a [a:Int32]
4946-
EmptyRelation []
4947-
"###
4946+
EmptyRelation: rows=1 []
4947+
"
49484948
);
49494949

49504950
// Executing LogicalPlans with placeholders that don't have bound values
@@ -4973,11 +4973,11 @@ async fn test_dataframe_placeholder_missing_param_values() -> Result<()> {
49734973

49744974
assert_snapshot!(
49754975
actual,
4976-
@r###"
4976+
@r"
49774977
Filter: a = Int32(3) [a:Int32]
49784978
Projection: Int32(1) AS a [a:Int32]
4979-
EmptyRelation []
4980-
"###
4979+
EmptyRelation: rows=1 []
4980+
"
49814981
);
49824982

49834983
// N.B., the test is basically `SELECT 1 as a WHERE a = 3;` which returns no results.
@@ -5004,10 +5004,10 @@ async fn test_dataframe_placeholder_column_parameter() -> Result<()> {
50045004

50055005
assert_snapshot!(
50065006
actual,
5007-
@r###"
5007+
@r"
50085008
Projection: $1 [$1:Null;N]
5009-
EmptyRelation []
5010-
"###
5009+
EmptyRelation: rows=1 []
5010+
"
50115011
);
50125012

50135013
// Executing LogicalPlans with placeholders that don't have bound values
@@ -5034,10 +5034,10 @@ async fn test_dataframe_placeholder_column_parameter() -> Result<()> {
50345034

50355035
assert_snapshot!(
50365036
actual,
5037-
@r###"
5037+
@r"
50385038
Projection: Int32(3) AS $1 [$1:Null;N]
5039-
EmptyRelation []
5040-
"###
5039+
EmptyRelation: rows=1 []
5040+
"
50415041
);
50425042

50435043
assert_snapshot!(
@@ -5073,11 +5073,11 @@ async fn test_dataframe_placeholder_like_expression() -> Result<()> {
50735073

50745074
assert_snapshot!(
50755075
actual,
5076-
@r###"
5076+
@r#"
50775077
Filter: a LIKE $1 [a:Utf8]
50785078
Projection: Utf8("foo") AS a [a:Utf8]
5079-
EmptyRelation []
5080-
"###
5079+
EmptyRelation: rows=1 []
5080+
"#
50815081
);
50825082

50835083
// Executing LogicalPlans with placeholders that don't have bound values
@@ -5106,11 +5106,11 @@ async fn test_dataframe_placeholder_like_expression() -> Result<()> {
51065106

51075107
assert_snapshot!(
51085108
actual,
5109-
@r###"
5109+
@r#"
51105110
Filter: a LIKE Utf8("f%") [a:Utf8]
51115111
Projection: Utf8("foo") AS a [a:Utf8]
5112-
EmptyRelation []
5113-
"###
5112+
EmptyRelation: rows=1 []
5113+
"#
51145114
);
51155115

51165116
assert_snapshot!(

datafusion/core/tests/execution/logical_plan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn inline_scan_projection_test() -> Result<()> {
128128
@r"
129129
SubqueryAlias: ?table?
130130
Projection: a
131-
EmptyRelation
131+
EmptyRelation: rows=0
132132
"
133133
);
134134

datafusion/core/tests/optimizer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn select_arrow_cast() {
6262
plan,
6363
@r#"
6464
Projection: Float64(1234) AS f64, LargeUtf8("foo") AS large
65-
EmptyRelation
65+
EmptyRelation: rows=1
6666
"#
6767
);
6868
}

datafusion/expr/src/logical_plan/plan.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,10 @@ impl LogicalPlan {
17201720
impl Display for Wrapper<'_> {
17211721
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
17221722
match self.0 {
1723-
LogicalPlan::EmptyRelation(_) => write!(f, "EmptyRelation"),
1723+
LogicalPlan::EmptyRelation(EmptyRelation { produce_one_row, schema: _ }) => {
1724+
let rows = if *produce_one_row { 1 } else { 0 };
1725+
write!(f, "EmptyRelation: rows={rows}")
1726+
},
17241727
LogicalPlan::RecursiveQuery(RecursiveQuery {
17251728
is_distinct, ..
17261729
}) => {

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,15 @@ logical_plan
410410
04)------SubqueryAlias: a
411411
05)--------Union
412412
06)----------Projection: Int64(1) AS id, Int64(2) AS foo
413-
07)------------EmptyRelation
413+
07)------------EmptyRelation: rows=1
414414
08)----------Projection: Int64(1) AS id, Int64(NULL) AS foo
415-
09)------------EmptyRelation
415+
09)------------EmptyRelation: rows=1
416416
10)----------Projection: Int64(1) AS id, Int64(NULL) AS foo
417-
11)------------EmptyRelation
417+
11)------------EmptyRelation: rows=1
418418
12)----------Projection: Int64(1) AS id, Int64(3) AS foo
419-
13)------------EmptyRelation
419+
13)------------EmptyRelation: rows=1
420420
14)----------Projection: Int64(1) AS id, Int64(2) AS foo
421-
15)------------EmptyRelation
421+
15)------------EmptyRelation: rows=1
422422
physical_plan
423423
01)ProjectionExec: expr=[array_length(array_agg(DISTINCT a.foo)@1) as array_length(array_agg(DISTINCT a.foo)), sum(DISTINCT Int64(1))@2 as sum(DISTINCT Int64(1))]
424424
02)--AggregateExec: mode=FinalPartitioned, gby=[id@0 as id], aggr=[array_agg(DISTINCT a.foo), sum(DISTINCT Int64(1))], ordering_mode=Sorted
@@ -6820,15 +6820,15 @@ logical_plan
68206820
04)------SubqueryAlias: a
68216821
05)--------Union
68226822
06)----------Projection: Int64(1) AS id, Int64(2) AS foo
6823-
07)------------EmptyRelation
6823+
07)------------EmptyRelation: rows=1
68246824
08)----------Projection: Int64(1) AS id, Int64(4) AS foo
6825-
09)------------EmptyRelation
6825+
09)------------EmptyRelation: rows=1
68266826
10)----------Projection: Int64(1) AS id, Int64(5) AS foo
6827-
11)------------EmptyRelation
6827+
11)------------EmptyRelation: rows=1
68286828
12)----------Projection: Int64(1) AS id, Int64(3) AS foo
6829-
13)------------EmptyRelation
6829+
13)------------EmptyRelation: rows=1
68306830
14)----------Projection: Int64(1) AS id, Int64(2) AS foo
6831-
15)------------EmptyRelation
6831+
15)------------EmptyRelation: rows=1
68326832
physical_plan
68336833
01)ProjectionExec: expr=[last_value(a.foo) ORDER BY [a.foo ASC NULLS LAST]@1 as last_value(a.foo) ORDER BY [a.foo ASC NULLS LAST], sum(DISTINCT Int64(1))@2 as sum(DISTINCT Int64(1))]
68346834
02)--AggregateExec: mode=FinalPartitioned, gby=[id@0 as id], aggr=[last_value(a.foo) ORDER BY [a.foo ASC NULLS LAST], sum(DISTINCT Int64(1))], ordering_mode=Sorted

datafusion/sqllogictest/test_files/array.slt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7367,7 +7367,7 @@ explain select [1,2,3] @> [1,3];
73677367
----
73687368
logical_plan
73697369
01)Projection: Boolean(true) AS array_has_all(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(1),Int64(3)))
7370-
02)--EmptyRelation
7370+
02)--EmptyRelation: rows=1
73717371
physical_plan
73727372
01)ProjectionExec: expr=[true as array_has_all(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(1),Int64(3)))]
73737373
02)--PlaceholderRowExec
@@ -7390,7 +7390,7 @@ explain select [1,3] <@ [1,2,3];
73907390
----
73917391
logical_plan
73927392
01)Projection: Boolean(true) AS array_has_all(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(1),Int64(3)))
7393-
02)--EmptyRelation
7393+
02)--EmptyRelation: rows=1
73947394
physical_plan
73957395
01)ProjectionExec: expr=[true as array_has_all(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(1),Int64(3)))]
73967396
02)--PlaceholderRowExec

datafusion/sqllogictest/test_files/count_star_rule.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ logical_plan
3434
01)Projection: count(Int64(1)) AS count()
3535
02)--Aggregate: groupBy=[[]], aggr=[[count(Int64(1))]]
3636
03)----SubqueryAlias: t
37-
04)------EmptyRelation
37+
04)------EmptyRelation: rows=1
3838
physical_plan
3939
01)ProjectionExec: expr=[1 as count()]
4040
02)--PlaceholderRowExec

datafusion/sqllogictest/test_files/cte.slt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ EXPLAIN WITH "NUMBERS" AS (SELECT 1 as a, 2 as b, 3 as c) SELECT "NUMBERS".* FRO
3333
logical_plan
3434
01)SubqueryAlias: NUMBERS
3535
02)--Projection: Int64(1) AS a, Int64(2) AS b, Int64(3) AS c
36-
03)----EmptyRelation
36+
03)----EmptyRelation: rows=1
3737
physical_plan
3838
01)ProjectionExec: expr=[1 as a, 2 as b, 3 as c]
3939
02)--PlaceholderRowExec
@@ -107,7 +107,7 @@ logical_plan
107107
01)SubqueryAlias: nodes
108108
02)--RecursiveQuery: is_distinct=false
109109
03)----Projection: Int64(1) AS id
110-
04)------EmptyRelation
110+
04)------EmptyRelation: rows=1
111111
05)----Projection: nodes.id + Int64(1) AS id
112112
06)------Filter: nodes.id < Int64(10)
113113
07)--------TableScan: nodes
@@ -720,14 +720,14 @@ logical_plan
720720
01)SubqueryAlias: recursive_cte
721721
02)--RecursiveQuery: is_distinct=false
722722
03)----Projection: Int64(1) AS val
723-
04)------EmptyRelation
723+
04)------EmptyRelation: rows=1
724724
05)----Projection: Int64(2) AS val
725725
06)------Cross Join:
726726
07)--------Filter: recursive_cte.val < Int64(2)
727727
08)----------TableScan: recursive_cte
728728
09)--------SubqueryAlias: sub_cte
729729
10)----------Projection: Int64(2) AS val
730-
11)------------EmptyRelation
730+
11)------------EmptyRelation: rows=1
731731
physical_plan
732732
01)RecursiveQueryExec: name=recursive_cte, is_distinct=false
733733
02)--ProjectionExec: expr=[1 as val]
@@ -869,7 +869,7 @@ explain with numbers(a,b,c) as (select 1 as x, 2 as y, 3 as z) select * from num
869869
logical_plan
870870
01)SubqueryAlias: numbers
871871
02)--Projection: Int64(1) AS a, Int64(2) AS b, Int64(3) AS c
872-
03)----EmptyRelation
872+
03)----EmptyRelation: rows=1
873873
physical_plan
874874
01)ProjectionExec: expr=[1 as a, 2 as b, 3 as c]
875875
02)--PlaceholderRowExec
@@ -880,7 +880,7 @@ explain with numbers(a,b,c) as (select 1,2,3) select * from numbers;
880880
logical_plan
881881
01)SubqueryAlias: numbers
882882
02)--Projection: Int64(1) AS a, Int64(2) AS b, Int64(3) AS c
883-
03)----EmptyRelation
883+
03)----EmptyRelation: rows=1
884884
physical_plan
885885
01)ProjectionExec: expr=[1 as a, 2 as b, 3 as c]
886886
02)--PlaceholderRowExec
@@ -891,7 +891,7 @@ explain with numbers as (select 1 as a, 2 as b, 3 as c) select * from numbers;
891891
logical_plan
892892
01)SubqueryAlias: numbers
893893
02)--Projection: Int64(1) AS a, Int64(2) AS b, Int64(3) AS c
894-
03)----EmptyRelation
894+
03)----EmptyRelation: rows=1
895895
physical_plan
896896
01)ProjectionExec: expr=[1 as a, 2 as b, 3 as c]
897897
02)--PlaceholderRowExec
@@ -931,7 +931,7 @@ logical_plan
931931
02)--TableScan: j1 projection=[a]
932932
03)--SubqueryAlias: j2
933933
04)----Projection: Int64(1)
934-
05)------EmptyRelation
934+
05)------EmptyRelation: rows=1
935935
physical_plan
936936
01)CrossJoinExec
937937
02)--DataSourceExec: partitions=1, partition_sizes=[0]
@@ -955,7 +955,7 @@ logical_plan
955955
01)SubqueryAlias: numbers
956956
02)--RecursiveQuery: is_distinct=false
957957
03)----Projection: Int64(1) AS n
958-
04)------EmptyRelation
958+
04)------EmptyRelation: rows=1
959959
05)----Projection: numbers.n + Int64(1)
960960
06)------Filter: numbers.n < Int64(10)
961961
07)--------TableScan: numbers
@@ -981,7 +981,7 @@ logical_plan
981981
01)SubqueryAlias: numbers
982982
02)--RecursiveQuery: is_distinct=false
983983
03)----Projection: Int64(1) AS n
984-
04)------EmptyRelation
984+
04)------EmptyRelation: rows=1
985985
05)----Projection: numbers.n + Int64(1)
986986
06)------Filter: numbers.n < Int64(10)
987987
07)--------TableScan: numbers
@@ -1039,7 +1039,7 @@ logical_plan
10391039
02)--Limit: skip=0, fetch=5
10401040
03)----RecursiveQuery: is_distinct=false
10411041
04)------Projection: Int64(0) AS k, Int64(0) AS v
1042-
05)--------EmptyRelation
1042+
05)--------EmptyRelation: rows=1
10431043
06)------Sort: r.v ASC NULLS LAST, fetch=1
10441044
07)--------Projection: r.k, r.v
10451045
08)----------TableScan: r

datafusion/sqllogictest/test_files/explain.slt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ explain select make_array(make_array(1, 2, 3), make_array(4, 5, 6));
388388
----
389389
logical_plan
390390
01)Projection: List([[1, 2, 3], [4, 5, 6]]) AS make_array(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(4),Int64(5),Int64(6)))
391-
02)--EmptyRelation
391+
02)--EmptyRelation: rows=1
392392
physical_plan
393393
01)ProjectionExec: expr=[[[1, 2, 3], [4, 5, 6]] as make_array(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(4),Int64(5),Int64(6)))]
394394
02)--PlaceholderRowExec
@@ -398,7 +398,7 @@ explain select [[1, 2, 3], [4, 5, 6]];
398398
----
399399
logical_plan
400400
01)Projection: List([[1, 2, 3], [4, 5, 6]]) AS make_array(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(4),Int64(5),Int64(6)))
401-
02)--EmptyRelation
401+
02)--EmptyRelation: rows=1
402402
physical_plan
403403
01)ProjectionExec: expr=[[[1, 2, 3], [4, 5, 6]] as make_array(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(4),Int64(5),Int64(6)))]
404404
02)--PlaceholderRowExec
@@ -410,7 +410,7 @@ explain select struct(1, 2.3, 'abc');
410410
----
411411
logical_plan
412412
01)Projection: Struct({c0:1,c1:2.3,c2:abc}) AS struct(Int64(1),Float64(2.3),Utf8("abc"))
413-
02)--EmptyRelation
413+
02)--EmptyRelation: rows=1
414414
physical_plan
415415
01)ProjectionExec: expr=[{c0:1,c1:2.3,c2:abc} as struct(Int64(1),Float64(2.3),Utf8("abc"))]
416416
02)--PlaceholderRowExec

datafusion/sqllogictest/test_files/expr/date_part.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,4 +1089,4 @@ SELECT EXTRACT("isodow" FROM to_timestamp('2020-09-08T12:00:00+00:00'))
10891089
query I
10901090
SELECT EXTRACT('isodow' FROM to_timestamp('2020-09-08T12:00:00+00:00'))
10911091
----
1092-
1
1092+
1

0 commit comments

Comments
 (0)