|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | + |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +statement ok |
| 19 | +CREATE TABLE t1 (a INTEGER, b INTEGER, c INTEGER); |
| 20 | + |
| 21 | +statement ok |
| 22 | +INSERT INTO t1 VALUES |
| 23 | +(1, 2, 3), |
| 24 | +(1, 5, 6), |
| 25 | +(2, 3, 5); |
| 26 | + |
| 27 | +statement ok |
| 28 | +CREATE TABLE t2 (a INTEGER, b INTEGER, c INTEGER); |
| 29 | + |
| 30 | +query TT |
| 31 | +EXPLAIN SELECT COUNT() FROM (SELECT 1 AS a, 2 AS b) AS t; |
| 32 | +---- |
| 33 | +logical_plan |
| 34 | +01)Aggregate: groupBy=[[]], aggr=[[count(Int64(1)) AS count()]] |
| 35 | +02)--SubqueryAlias: t |
| 36 | +03)----EmptyRelation |
| 37 | +physical_plan |
| 38 | +01)ProjectionExec: expr=[1 as count()] |
| 39 | +02)--PlaceholderRowExec |
| 40 | + |
| 41 | +query TT |
| 42 | +EXPLAIN SELECT t1.a, COUNT() FROM t1 GROUP BY t1.a; |
| 43 | +---- |
| 44 | +logical_plan |
| 45 | +01)Aggregate: groupBy=[[t1.a]], aggr=[[count(Int64(1)) AS count()]] |
| 46 | +02)--TableScan: t1 projection=[a] |
| 47 | +physical_plan |
| 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] |
| 54 | + |
| 55 | +query TT |
| 56 | +EXPLAIN SELECT t1.a, COUNT() AS cnt FROM t1 GROUP BY t1.a HAVING COUNT() > 0; |
| 57 | +---- |
| 58 | +logical_plan |
| 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] |
| 63 | +physical_plan |
| 64 | +01)ProjectionExec: expr=[a@0 as a, count()@1 as cnt] |
| 65 | +02)--CoalesceBatchesExec: target_batch_size=8192 |
| 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 |
| 100 | + |
| 101 | +statement ok |
| 102 | +DROP TABLE t1; |
| 103 | + |
| 104 | +statement ok |
| 105 | +DROP TABLE t2; |
0 commit comments