Skip to content

Commit cba60ac

Browse files
committed
tests: more tests
1 parent da5da12 commit cba60ac

File tree

1 file changed

+55
-29
lines changed

1 file changed

+55
-29
lines changed

datafusion/sqllogictest/test_files/count_empty_rule.slt

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
statement ok
1919
CREATE TABLE t1 (a INTEGER, b INTEGER, c INTEGER);
2020

21+
statement ok
22+
INSERT INTO t1 VALUES
23+
(1, 2, 3),
24+
(1, 5, 6),
25+
(2, 3, 5);
26+
2127
statement ok
2228
CREATE TABLE t2 (a INTEGER, b INTEGER, c INTEGER);
2329

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

35-
3641
query TT
37-
EXPLAIN SELECT t1.a, t1.b, t1.c
38-
FROM t1
39-
WHERE t1.a IN (
40-
SELECT COUNT()
41-
FROM t2
42-
);
42+
EXPLAIN SELECT t1.a, COUNT() FROM t1 GROUP BY t1.a;
4343
----
4444
logical_plan
45-
01)LeftSemi Join: CAST(t1.a AS Int64) = __correlated_sq_1.count()
46-
02)--TableScan: t1 projection=[a, b, c]
47-
03)--SubqueryAlias: __correlated_sq_1
48-
04)----Aggregate: groupBy=[[]], aggr=[[count(Int64(1)) AS count()]]
49-
05)------TableScan: t2 projection=[]
45+
01)Aggregate: groupBy=[[t1.a]], aggr=[[count(Int64(1)) AS count()]]
46+
02)--TableScan: t1 projection=[a]
5047
physical_plan
51-
01)CoalesceBatchesExec: target_batch_size=8192
52-
02)--HashJoinExec: mode=Partitioned, join_type=LeftSemi, on=[(CAST(t1.a AS Int64)@3, count()@0)], projection=[a@0, b@1, c@2]
53-
03)----CoalesceBatchesExec: target_batch_size=8192
54-
04)------RepartitionExec: partitioning=Hash([CAST(t1.a AS Int64)@3], 4), input_partitions=1
55-
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)]
56-
06)----------MemoryExec: partitions=1, partition_sizes=[0]
57-
07)----CoalesceBatchesExec: target_batch_size=8192
58-
08)------RepartitionExec: partitioning=Hash([count()@0], 4), input_partitions=1
59-
09)--------ProjectionExec: expr=[0 as count()]
60-
10)----------PlaceholderRowExec
48+
01)AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[count()]
49+
02)--CoalesceBatchesExec: target_batch_size=8192
50+
03)----RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=4
51+
04)------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
52+
05)--------AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[count()]
53+
06)----------MemoryExec: partitions=1, partition_sizes=[1]
6154

6255
query TT
63-
EXPLAIN SELECT t1.a, COUNT() FROM t1 GROUP BY t1.a;
56+
EXPLAIN SELECT t1.a, COUNT() AS cnt FROM t1 GROUP BY t1.a HAVING COUNT() > 0;
6457
----
6558
logical_plan
66-
01)Aggregate: groupBy=[[t1.a]], aggr=[[count(Int64(1)) AS count()]]
67-
02)--TableScan: t1 projection=[a]
59+
01)Projection: t1.a, count() AS cnt
60+
02)--Filter: count() > Int64(0)
61+
03)----Aggregate: groupBy=[[t1.a]], aggr=[[count(Int64(1)) AS count()]]
62+
04)------TableScan: t1 projection=[a]
6863
physical_plan
69-
01)AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[count()]
64+
01)ProjectionExec: expr=[a@0 as a, count()@1 as cnt]
7065
02)--CoalesceBatchesExec: target_batch_size=8192
71-
03)----RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=1
72-
04)------AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[count()]
73-
05)--------MemoryExec: partitions=1, partition_sizes=[0]
66+
03)----FilterExec: count()@1 > 0
67+
04)------AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[count()]
68+
05)--------CoalesceBatchesExec: target_batch_size=8192
69+
06)----------RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=4
70+
07)------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
71+
08)--------------AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[count()]
72+
09)----------------MemoryExec: partitions=1, partition_sizes=[1]
73+
74+
query II
75+
SELECT t1.a, COUNT() AS cnt FROM t1 GROUP BY t1.a HAVING COUNT() > 1;
76+
----
77+
1 2
78+
79+
query TT
80+
EXPLAIN SELECT a, COUNT() OVER (PARTITION BY a) AS count_a FROM t1;
81+
----
82+
logical_plan
83+
01)Projection: t1.a, count() PARTITION BY [t1.a] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING AS count_a
84+
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]]
85+
03)----TableScan: t1 projection=[a]
86+
physical_plan
87+
01)ProjectionExec: expr=[a@0 as a, count() PARTITION BY [t1.a] ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING@1 as count_a]
88+
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 }]
89+
03)----SortExec: expr=[a@0 ASC NULLS LAST], preserve_partitioning=[true]
90+
04)------CoalesceBatchesExec: target_batch_size=8192
91+
05)--------RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=1
92+
06)----------MemoryExec: partitions=1, partition_sizes=[1]
93+
94+
query II
95+
SELECT a, COUNT() OVER (PARTITION BY a) AS count_a FROM t1 ORDER BY a;
96+
----
97+
1 2
98+
1 2
99+
2 1
74100

75101
statement ok
76102
DROP TABLE t1;

0 commit comments

Comments
 (0)