Skip to content

Commit

Permalink
tests: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tshauck committed Jul 7, 2024
1 parent fde85e5 commit 10f32a4
Showing 1 changed file with 55 additions and 29 deletions.
84 changes: 55 additions & 29 deletions datafusion/sqllogictest/test_files/count_empty_rule.slt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
statement ok
CREATE TABLE t1 (a INTEGER, b INTEGER, c INTEGER);

statement ok
INSERT INTO t1 VALUES
(1, 2, 3),
(1, 5, 6),
(2, 3, 5);

statement ok
CREATE TABLE t2 (a INTEGER, b INTEGER, c INTEGER);

Expand All @@ -32,45 +38,65 @@ physical_plan
01)ProjectionExec: expr=[1 as count()]
02)--PlaceholderRowExec


query TT
EXPLAIN SELECT t1.a, t1.b, t1.c
FROM t1
WHERE t1.a IN (
SELECT COUNT()
FROM t2
);
EXPLAIN SELECT t1.a, COUNT() FROM t1 GROUP BY t1.a;
----
logical_plan
01)LeftSemi Join: CAST(t1.a AS Int64) = __correlated_sq_1.count()
02)--TableScan: t1 projection=[a, b, c]
03)--SubqueryAlias: __correlated_sq_1
04)----Aggregate: groupBy=[[]], aggr=[[count(Int64(1)) AS count()]]
05)------TableScan: t2 projection=[]
01)Aggregate: groupBy=[[t1.a]], aggr=[[count(Int64(1)) AS count()]]
02)--TableScan: t1 projection=[a]
physical_plan
01)CoalesceBatchesExec: target_batch_size=8192
02)--HashJoinExec: mode=Partitioned, join_type=LeftSemi, on=[(CAST(t1.a AS Int64)@3, count()@0)], projection=[a@0, b@1, c@2]
03)----CoalesceBatchesExec: target_batch_size=8192
04)------RepartitionExec: partitioning=Hash([CAST(t1.a AS Int64)@3], 4), input_partitions=1
05)--------ProjectionExec: expr=[a@0 as a, b@1 as b, c@2 as c, CAST(a@0 AS Int64) as CAST(t1.a AS Int64)]
06)----------MemoryExec: partitions=1, partition_sizes=[0]
07)----CoalesceBatchesExec: target_batch_size=8192
08)------RepartitionExec: partitioning=Hash([count()@0], 4), input_partitions=1
09)--------ProjectionExec: expr=[0 as count()]
10)----------PlaceholderRowExec
01)AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[count()]
02)--CoalesceBatchesExec: target_batch_size=8192
03)----RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=4
04)------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
05)--------AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[count()]
06)----------MemoryExec: partitions=1, partition_sizes=[1]

query TT
EXPLAIN SELECT t1.a, COUNT() FROM t1 GROUP BY t1.a;
EXPLAIN SELECT t1.a, COUNT() AS cnt FROM t1 GROUP BY t1.a HAVING COUNT() > 0;
----
logical_plan
01)Aggregate: groupBy=[[t1.a]], aggr=[[count(Int64(1)) AS count()]]
02)--TableScan: t1 projection=[a]
01)Projection: t1.a, count() AS cnt
02)--Filter: count() > Int64(0)
03)----Aggregate: groupBy=[[t1.a]], aggr=[[count(Int64(1)) AS count()]]
04)------TableScan: t1 projection=[a]
physical_plan
01)AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[count()]
01)ProjectionExec: expr=[a@0 as a, count()@1 as cnt]
02)--CoalesceBatchesExec: target_batch_size=8192
03)----RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=1
04)------AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[count()]
05)--------MemoryExec: partitions=1, partition_sizes=[0]
03)----FilterExec: count()@1 > 0
04)------AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[count()]
05)--------CoalesceBatchesExec: target_batch_size=8192
06)----------RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=4
07)------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
08)--------------AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[count()]
09)----------------MemoryExec: partitions=1, partition_sizes=[1]

query II
SELECT t1.a, COUNT() AS cnt FROM t1 GROUP BY t1.a HAVING COUNT() > 1;
----
1 2

query TT
EXPLAIN SELECT a, COUNT() OVER (PARTITION BY a) AS count_a FROM t1;
----
logical_plan
01)Projection: t1.a, count() PARTITION BY [t1.a] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING AS count_a
02)--WindowAggr: windowExpr=[[count(Int64(1)) PARTITION BY [t1.a] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING AS count() PARTITION BY [t1.a] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING]]
03)----TableScan: t1 projection=[a]
physical_plan
01)ProjectionExec: expr=[a@0 as a, count() PARTITION BY [t1.a] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING@1 as count_a]
02)--WindowAggExec: wdw=[count() PARTITION BY [t1.a] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING: Ok(Field { name: "count() PARTITION BY [t1.a] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Rows, start_bound: Preceding(UInt64(NULL)), end_bound: Following(UInt64(NULL)), is_causal: false }]
03)----SortExec: expr=[a@0 ASC NULLS LAST], preserve_partitioning=[true]
04)------CoalesceBatchesExec: target_batch_size=8192
05)--------RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=1
06)----------MemoryExec: partitions=1, partition_sizes=[1]

query II
SELECT a, COUNT() OVER (PARTITION BY a) AS count_a FROM t1 ORDER BY a;
----
1 2
1 2
2 1

statement ok
DROP TABLE t1;
Expand Down

0 comments on commit 10f32a4

Please sign in to comment.