Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,14 @@ public PlanFragment visitPhysicalHashAggregate(
.collect(Collectors.toCollection(ArrayList::new));

PlanFragment currentFragment;
if (inputPlanFragment.getPlanRoot() instanceof ExchangeNode) {
Preconditions.checkState(aggregate.child() instanceof PhysicalDistribute,
"When the ExchangeNode is child of PhysicalHashAggregate, "
+ "it should be created by PhysicalDistribute, but meet " + aggregate.child());
if (inputPlanFragment.getPlanRoot() instanceof ExchangeNode
&& aggregate.child() instanceof PhysicalDistribute) {
//the exchange node is generated in two cases:
// 1. some nodes (e.g. sort node) need to gather data from multiple instances, and hence their gather phase
// need an exchange node. For this type of exchange, their data partition is un_partitioned, do not
// create a new plan fragment.
// 2. PhysicalDistribute node is translated to exchange node. PhysicalDistribute node means we need to
// shuffle data, and we have to create a new plan fragment.
ExchangeNode exchangeNode = (ExchangeNode) inputPlanFragment.getPlanRoot();
Optional<List<Expression>> partitionExpressions = aggregate.getPartitionExpressions();
PhysicalDistribute physicalDistribute = (PhysicalDistribute) aggregate.child();
Expand Down
4 changes: 4 additions & 0 deletions regression-test/data/nereids_syntax_p0/agg_with_sort.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --
0

38 changes: 38 additions & 0 deletions regression-test/suites/nereids_syntax_p0/agg_with_sort.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.

suite("agg_with_sort") {
sql "SET enable_nereids_planner=true"
sql "set enable_fallback_to_original_planner=false"
sql """
DROP TABLE IF EXISTS tbl
"""

sql """CREATE TABLE IF NOT EXISTS tbl (a int not null, b int not null)
DISTRIBUTED BY HASH(a)
BUCKETS 1
PROPERTIES(
"replication_num"="1"
)
"""
//make sure we can handle this sql pattern:
// agg -> exchange -> sort

qt_select """
select count(1) from (select a from tbl order by a desc) t;
"""
}