forked from apache/datafusion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: issue apache#9213 substitute ArrayAgg to NthValue to optimize qu…
…ery plan
- Loading branch information
Showing
2 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
datafusion/sqllogictest/test_files/agg_func_substitute.slt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
####### | ||
# Setup test data table | ||
####### | ||
statement ok | ||
CREATE EXTERNAL TABLE multiple_ordered_table ( | ||
a0 INTEGER, | ||
a INTEGER, | ||
b INTEGER, | ||
c INTEGER, | ||
d INTEGER | ||
) | ||
STORED AS CSV | ||
WITH HEADER ROW | ||
WITH ORDER (a ASC, b ASC) | ||
WITH ORDER (c ASC) | ||
LOCATION '../../datafusion/core/tests/data/window_2.csv'; | ||
|
||
|
||
query TT | ||
EXPLAIN SELECT a, ARRAY_AGG(c ORDER BY c)[1] as result | ||
FROM multiple_ordered_table | ||
GROUP BY a; | ||
---- | ||
logical_plan | ||
Projection: multiple_ordered_table.a, NTH_VALUE(multiple_ordered_table.c,Int64(1)) ORDER BY [multiple_ordered_table.c ASC NULLS LAST] AS result | ||
--Aggregate: groupBy=[[multiple_ordered_table.a]], aggr=[[NTH_VALUE(multiple_ordered_table.c, Int64(1)) ORDER BY [multiple_ordered_table.c ASC NULLS LAST]]] | ||
----TableScan: multiple_ordered_table projection=[a, c] | ||
physical_plan | ||
ProjectionExec: expr=[a@0 as a, NTH_VALUE(multiple_ordered_table.c,Int64(1)) ORDER BY [multiple_ordered_table.c ASC NULLS LAST]@1 as result] | ||
--AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[NTH_VALUE(multiple_ordered_table.c,Int64(1))], ordering_mode=Sorted | ||
----SortExec: expr=[a@0 ASC NULLS LAST] | ||
------CoalesceBatchesExec: target_batch_size=8192 | ||
--------RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=4 | ||
----------AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[NTH_VALUE(multiple_ordered_table.c,Int64(1))], ordering_mode=Sorted | ||
------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1 | ||
--------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a, c], output_orderings=[[a@0 ASC NULLS LAST], [c@1 ASC NULLS LAST]], has_header=true | ||
|
||
|
||
query TT | ||
EXPLAIN SELECT a, NTH_VALUE(c, 1 ORDER BY c) as result | ||
FROM multiple_ordered_table | ||
GROUP BY a; | ||
---- | ||
logical_plan | ||
Projection: multiple_ordered_table.a, NTH_VALUE(multiple_ordered_table.c,Int64(1)) ORDER BY [multiple_ordered_table.c ASC NULLS LAST] AS result | ||
--Aggregate: groupBy=[[multiple_ordered_table.a]], aggr=[[NTH_VALUE(multiple_ordered_table.c, Int64(1)) ORDER BY [multiple_ordered_table.c ASC NULLS LAST]]] | ||
----TableScan: multiple_ordered_table projection=[a, c] | ||
physical_plan | ||
ProjectionExec: expr=[a@0 as a, NTH_VALUE(multiple_ordered_table.c,Int64(1)) ORDER BY [multiple_ordered_table.c ASC NULLS LAST]@1 as result] | ||
--AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[NTH_VALUE(multiple_ordered_table.c,Int64(1))], ordering_mode=Sorted | ||
----SortExec: expr=[a@0 ASC NULLS LAST] | ||
------CoalesceBatchesExec: target_batch_size=8192 | ||
--------RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=4 | ||
----------AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[NTH_VALUE(multiple_ordered_table.c,Int64(1))], ordering_mode=Sorted | ||
------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1 | ||
--------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a, c], output_orderings=[[a@0 ASC NULLS LAST], [c@1 ASC NULLS LAST]], has_header=true | ||
|
||
query TT | ||
EXPLAIN SELECT a, ARRAY_AGG(c ORDER BY c)[1 + 100] as result | ||
FROM multiple_ordered_table | ||
GROUP BY a; | ||
---- | ||
logical_plan | ||
Projection: multiple_ordered_table.a, NTH_VALUE(multiple_ordered_table.c,Int64(1) + Int64(100)) ORDER BY [multiple_ordered_table.c ASC NULLS LAST] AS result | ||
--Aggregate: groupBy=[[multiple_ordered_table.a]], aggr=[[NTH_VALUE(multiple_ordered_table.c, Int64(101)) ORDER BY [multiple_ordered_table.c ASC NULLS LAST] AS NTH_VALUE(multiple_ordered_table.c,Int64(1) + Int64(100)) ORDER BY [multiple_ordered_table.c ASC NULLS LAST]]] | ||
----TableScan: multiple_ordered_table projection=[a, c] | ||
physical_plan | ||
ProjectionExec: expr=[a@0 as a, NTH_VALUE(multiple_ordered_table.c,Int64(1) + Int64(100)) ORDER BY [multiple_ordered_table.c ASC NULLS LAST]@1 as result] | ||
--AggregateExec: mode=FinalPartitioned, gby=[a@0 as a], aggr=[NTH_VALUE(multiple_ordered_table.c,Int64(1) + Int64(100)) ORDER BY [multiple_ordered_table.c ASC NULLS LAST]], ordering_mode=Sorted | ||
----SortExec: expr=[a@0 ASC NULLS LAST] | ||
------CoalesceBatchesExec: target_batch_size=8192 | ||
--------RepartitionExec: partitioning=Hash([a@0], 4), input_partitions=4 | ||
----------AggregateExec: mode=Partial, gby=[a@0 as a], aggr=[NTH_VALUE(multiple_ordered_table.c,Int64(1) + Int64(100)) ORDER BY [multiple_ordered_table.c ASC NULLS LAST]], ordering_mode=Sorted | ||
------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1 | ||
--------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a, c], output_orderings=[[a@0 ASC NULLS LAST], [c@1 ASC NULLS LAST]], has_header=true |