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 @@ -78,12 +78,23 @@ public Rule build() {
return RuleType.NORMALIZE_REPEAT.build(
logicalRepeat(any()).when(LogicalRepeat::canBindVirtualSlot).then(repeat -> {
checkRepeatLegality(repeat);
repeat = removeDuplicateColumns(repeat);
// add virtual slot, LogicalAggregate and LogicalProject for normalize
return normalizeRepeat(repeat);
})
);
}

private LogicalRepeat<Plan> removeDuplicateColumns(LogicalRepeat<Plan> repeat) {
List<List<Expression>> groupingSets = repeat.getGroupingSets();
ImmutableList.Builder<List<Expression>> builder = ImmutableList.builder();
for (List<Expression> sets : groupingSets) {
List<Expression> newList = ImmutableList.copyOf(ImmutableSet.copyOf(sets));
builder.add(newList);
}
return repeat.withGroupSets(builder.build());
}

private void checkRepeatLegality(LogicalRepeat<Plan> repeat) {
checkIfAggFuncSlotInGroupingSets(repeat);
checkGroupingSetsSize(repeat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ default List<Set<Integer>> getGroupingSetsIndexesInOutput() {
if (index == null) {
throw new AnalysisException("Can not find grouping set expression in output: " + expression);
}
if (groupingSetIndex.contains(index)) {
throw new AnalysisException("expression duplicate in grouping set: " + expression);
}
groupingSetIndex.add(index);
}
groupingSetsIndex.add(groupingSetIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public Plan withGroupExprLogicalPropChildren(Optional<GroupExpression> groupExpr
children.get(0));
}

public LogicalRepeat<CHILD_TYPE> withGroupSets(List<List<Expression>> groupingSets) {
return new LogicalRepeat<>(groupingSets, outputExpressions, child());
}

public LogicalRepeat<CHILD_TYPE> withGroupSetsAndOutput(List<List<Expression>> groupingSets,
List<NamedExpression> outputExpressionList) {
return new LogicalRepeat<>(groupingSets, outputExpressionList, child());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !test_col --
\N 6
1 20
2 8
3 20
4 2
5 26
7 1

-- !test_expr --
\N 6
2 20
3 8
4 20
5 2
6 26
8 1

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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("remove_duplicate_expr_in_grouping_set") {
sql "SET enable_nereids_planner=true"
sql "SET enable_fallback_to_original_planner=false"
sql """
DROP TABLE IF EXISTS mal_test1
"""

sql """
create table mal_test1(pk int, a int, b int) distributed by hash(pk) buckets 10
properties('replication_num' = '1');
"""

sql """
insert into mal_test1 values(2,1,3),(1,1,2),(3,5,6),(6,null,6),(4,5,6),(2,1,4),(2,3,5),(1,1,4)
,(3,5,6),(3,5,null),(6,7,1),(2,1,7),(2,4,2),(2,3,9),(1,3,6),(3,5,8),(3,2,8);
"""
sql "sync"
qt_test_col "select a, sum(b) from mal_test1 group by grouping sets((a,a)) order by 1,2"
qt_test_expr "select a+1,sum(b) from mal_test1 group by grouping sets((a+1,a+1)) order by 1,2"

}