From c02de2fb7598cc05091bc48c60f63d724a4cbf26 Mon Sep 17 00:00:00 2001 From: jackwener Date: Thu, 23 Feb 2023 21:35:18 +0800 Subject: [PATCH] minor: port predicates tests to sqllogictests --- datafusion/core/src/datasource/view.rs | 1 - datafusion/core/tests/sql/union.rs | 24 ++++------- .../sqllogictests/test_files/explain.slt | 5 +-- .../tests/sqllogictests/test_files/window.slt | 42 +++++++++---------- .../optimizer/tests/integration-test.rs | 2 +- .../substrait/tests/roundtrip_logical_plan.rs | 13 +++--- 6 files changed, 36 insertions(+), 51 deletions(-) diff --git a/datafusion/core/src/datasource/view.rs b/datafusion/core/src/datasource/view.rs index 01f892bb59edf..dea7ecadf7f4e 100644 --- a/datafusion/core/src/datasource/view.rs +++ b/datafusion/core/src/datasource/view.rs @@ -473,7 +473,6 @@ mod tests { let formatted = arrow::util::pretty::pretty_format_batches(&plan) .unwrap() .to_string(); - println!("{}", formatted); assert!(formatted.contains("ParquetExec: limit=Some(10)")); Ok(()) } diff --git a/datafusion/core/tests/sql/union.rs b/datafusion/core/tests/sql/union.rs index c257bc304298d..4cf908aa85828 100644 --- a/datafusion/core/tests/sql/union.rs +++ b/datafusion/core/tests/sql/union.rs @@ -39,16 +39,12 @@ async fn union_with_except_input() -> Result<()> { " Union [name:UInt8;N]", " LeftAnti Join: t1.name = t2.name [name:UInt8;N]", " Aggregate: groupBy=[[t1.name]], aggr=[[]] [name:UInt8;N]", - " Projection: t1.name [name:UInt8;N]", - " TableScan: t1 projection=[name] [name:UInt8;N]", - " Projection: t2.name [name:UInt8;N]", - " TableScan: t2 projection=[name] [name:UInt8;N]", + " TableScan: t1 projection=[name] [name:UInt8;N]", + " TableScan: t2 projection=[name] [name:UInt8;N]", " LeftAnti Join: t2.name = t1.name [name:UInt8;N]", " Aggregate: groupBy=[[t2.name]], aggr=[[]] [name:UInt8;N]", - " Projection: t2.name [name:UInt8;N]", - " TableScan: t2 projection=[name] [name:UInt8;N]", - " Projection: t1.name [name:UInt8;N]", - " TableScan: t1 projection=[name] [name:UInt8;N]", + " TableScan: t2 projection=[name] [name:UInt8;N]", + " TableScan: t1 projection=[name] [name:UInt8;N]", ]; let formatted = plan.display_indent_schema().to_string(); @@ -82,17 +78,13 @@ async fn union_with_type_coercion() -> Result<()> { " Union [id:Int32;N, name:UInt8;N]", " LeftAnti Join: t1.id = CAST(t2.id AS Int32), t1.name = t2.name [id:Int32;N, name:UInt8;N]", " Aggregate: groupBy=[[t1.id, t1.name]], aggr=[[]] [id:Int32;N, name:UInt8;N]", - " Projection: t1.id, t1.name [id:Int32;N, name:UInt8;N]", - " TableScan: t1 projection=[id, name] [id:Int32;N, name:UInt8;N]", - " Projection: t2.id, t2.name [id:UInt8;N, name:UInt8;N]", - " TableScan: t2 projection=[id, name] [id:UInt8;N, name:UInt8;N]", + " TableScan: t1 projection=[id, name] [id:Int32;N, name:UInt8;N]", + " TableScan: t2 projection=[id, name] [id:UInt8;N, name:UInt8;N]", " Projection: CAST(t2.id AS Int32) AS id, t2.name [id:Int32;N, name:UInt8;N]", " LeftAnti Join: CAST(t2.id AS Int32) = t1.id, t2.name = t1.name [id:UInt8;N, name:UInt8;N]", " Aggregate: groupBy=[[t2.id, t2.name]], aggr=[[]] [id:UInt8;N, name:UInt8;N]", - " Projection: t2.id, t2.name [id:UInt8;N, name:UInt8;N]", - " TableScan: t2 projection=[id, name] [id:UInt8;N, name:UInt8;N]", - " Projection: t1.id, t1.name [id:Int32;N, name:UInt8;N]", - " TableScan: t1 projection=[id, name] [id:Int32;N, name:UInt8;N]", + " TableScan: t2 projection=[id, name] [id:UInt8;N, name:UInt8;N]", + " TableScan: t1 projection=[id, name] [id:Int32;N, name:UInt8;N]", ]; let formatted = plan.display_indent_schema().to_string(); let actual: Vec<&str> = formatted.trim().lines().collect(); diff --git a/datafusion/core/tests/sqllogictests/test_files/explain.slt b/datafusion/core/tests/sqllogictests/test_files/explain.slt index 9eca732c45f32..fe1d3ac2e4c47 100644 --- a/datafusion/core/tests/sqllogictests/test_files/explain.slt +++ b/datafusion/core/tests/sqllogictests/test_files/explain.slt @@ -59,9 +59,8 @@ query TT EXPLAIN select count(*) from (values ('a', 1, 100), ('a', 2, 150)) as t (c1,c2,c3) ---- physical_plan -ProjectionExec: expr=[COUNT(UInt8(1))@0 as COUNT(UInt8(1))] - ProjectionExec: expr=[2 as COUNT(UInt8(1))] - EmptyExec: produce_one_row=true +ProjectionExec: expr=[2 as COUNT(UInt8(1))] + EmptyExec: produce_one_row=true statement ok set datafusion.explain.physical_plan_only = false diff --git a/datafusion/core/tests/sqllogictests/test_files/window.slt b/datafusion/core/tests/sqllogictests/test_files/window.slt index 64920bb3dbb16..88be8adc71c08 100644 --- a/datafusion/core/tests/sqllogictests/test_files/window.slt +++ b/datafusion/core/tests/sqllogictests/test_files/window.slt @@ -258,18 +258,17 @@ Sort: d.b ASC NULLS LAST Aggregate: groupBy=[[d.b]], aggr=[[MAX(d.a)]] SubqueryAlias: d SubqueryAlias: _data2 - Projection: s.a, s.b - SubqueryAlias: s - SubqueryAlias: _sample_data - Union - Projection: Int64(1) AS a, Utf8("aa") AS b - EmptyRelation - Projection: Int64(3) AS a, Utf8("aa") AS b - EmptyRelation - Projection: Int64(5) AS a, Utf8("bb") AS b - EmptyRelation - Projection: Int64(7) AS a, Utf8("bb") AS b - EmptyRelation + SubqueryAlias: s + SubqueryAlias: _sample_data + Union + Projection: Int64(1) AS a, Utf8("aa") AS b + EmptyRelation + Projection: Int64(3) AS a, Utf8("aa") AS b + EmptyRelation + Projection: Int64(5) AS a, Utf8("bb") AS b + EmptyRelation + Projection: Int64(7) AS a, Utf8("bb") AS b + EmptyRelation physical_plan SortPreservingMergeExec: [b@0 ASC NULLS LAST] SortExec: expr=[b@0 ASC NULLS LAST] @@ -278,16 +277,15 @@ SortPreservingMergeExec: [b@0 ASC NULLS LAST] CoalesceBatchesExec: target_batch_size=8192 RepartitionExec: partitioning=Hash([Column { name: "b", index: 0 }], 4), input_partitions=4 AggregateExec: mode=Partial, gby=[b@1 as b], aggr=[MAX(d.a)] - ProjectionExec: expr=[a@0 as a, b@1 as b] - UnionExec - ProjectionExec: expr=[1 as a, aa as b] - EmptyExec: produce_one_row=true - ProjectionExec: expr=[3 as a, aa as b] - EmptyExec: produce_one_row=true - ProjectionExec: expr=[5 as a, bb as b] - EmptyExec: produce_one_row=true - ProjectionExec: expr=[7 as a, bb as b] - EmptyExec: produce_one_row=true + UnionExec + ProjectionExec: expr=[1 as a, aa as b] + EmptyExec: produce_one_row=true + ProjectionExec: expr=[3 as a, aa as b] + EmptyExec: produce_one_row=true + ProjectionExec: expr=[5 as a, bb as b] + EmptyExec: produce_one_row=true + ProjectionExec: expr=[7 as a, bb as b] + EmptyExec: produce_one_row=true # Check actual result: query TI diff --git a/datafusion/optimizer/tests/integration-test.rs b/datafusion/optimizer/tests/integration-test.rs index 96b418ac216e3..b84d15fae735a 100644 --- a/datafusion/optimizer/tests/integration-test.rs +++ b/datafusion/optimizer/tests/integration-test.rs @@ -319,7 +319,7 @@ fn test_same_name_but_not_ambiguous() { let sql = "SELECT t1.col_int32 AS col_int32 FROM test t1 intersect SELECT col_int32 FROM test t2"; let plan = test_sql(sql).unwrap(); let expected = "LeftSemi Join: col_int32 = t2.col_int32\ - \n Distinct:\ + \n Aggregate: groupBy=[[col_int32]], aggr=[[]]\ \n Projection: t1.col_int32 AS col_int32\ \n SubqueryAlias: t1\ \n TableScan: test projection=[col_int32]\ diff --git a/datafusion/substrait/tests/roundtrip_logical_plan.rs b/datafusion/substrait/tests/roundtrip_logical_plan.rs index a72a86846662d..47ce1bbcd9b63 100644 --- a/datafusion/substrait/tests/roundtrip_logical_plan.rs +++ b/datafusion/substrait/tests/roundtrip_logical_plan.rs @@ -226,14 +226,11 @@ mod tests { async fn simple_intersect() -> Result<()> { assert_expected_plan( "SELECT COUNT(*) FROM (SELECT data.a FROM data INTERSECT SELECT data2.a FROM data2);", - "Projection: COUNT(Int16(1))\ - \n Aggregate: groupBy=[[]], aggr=[[COUNT(Int16(1))]]\ - \n LeftSemi Join: data.a = data2.a\ - \n Aggregate: groupBy=[[data.a]], aggr=[[]]\ - \n Projection: data.a\ - \n TableScan: data projection=[a]\ - \n Projection: data2.a\ - \n TableScan: data2 projection=[a]", + "Aggregate: groupBy=[[]], aggr=[[COUNT(Int16(1))]]\ + \n LeftSemi Join: data.a = data2.a\ + \n Aggregate: groupBy=[[data.a]], aggr=[[]]\ + \n TableScan: data projection=[a]\ + \n TableScan: data2 projection=[a]", ) .await }