[Fix](nereids) remove duplicate expr in grouping set (#32290)
db reported a error " expression duplicate in grouping set" when there are duplicate expression in grouping set. e.g.select a from mal_test1 group by grouping sets((a,a)) This pr removes duplicate expr in grouping set : select a from mal_test1 group by grouping sets((a))
This commit is contained in:
@ -84,6 +84,7 @@ public class NormalizeRepeat extends OneAnalysisRuleFactory {
|
||||
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
|
||||
LogicalAggregate<Plan> agg = normalizeRepeat(repeat);
|
||||
return dealSlotAppearBothInAggFuncAndGroupingSets(agg);
|
||||
@ -91,6 +92,16 @@ public class NormalizeRepeat extends OneAnalysisRuleFactory {
|
||||
);
|
||||
}
|
||||
|
||||
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) {
|
||||
checkGroupingSetsSize(repeat);
|
||||
}
|
||||
|
||||
@ -175,9 +175,6 @@ public interface Repeat<CHILD_PLAN extends Plan> extends Aggregate<CHILD_PLAN> {
|
||||
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);
|
||||
|
||||
@ -158,6 +158,10 @@ public class LogicalRepeat<CHILD_TYPE extends Plan> extends LogicalUnary<CHILD_T
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user