[enhancement](nereids)eliminate repeat node if there is only 1 grouping set and no grouping scalar function (#35872)

This commit is contained in:
starocean999
2024-06-05 18:03:20 +08:00
committed by GitHub
parent af31e96c4e
commit bcde9c6524
3 changed files with 59 additions and 1 deletions

View File

@ -82,6 +82,12 @@ public class NormalizeRepeat extends OneAnalysisRuleFactory {
public Rule build() {
return RuleType.NORMALIZE_REPEAT.build(
logicalRepeat(any()).when(LogicalRepeat::canBindVirtualSlot).then(repeat -> {
if (repeat.getGroupingSets().size() == 1
&& ExpressionUtils.collect(repeat.getOutputExpressions(),
GroupingScalarFunction.class::isInstance).isEmpty()) {
return new LogicalAggregate<>(repeat.getGroupByExpressions(),
repeat.getOutputExpressions(), repeat.child());
}
checkRepeatLegality(repeat);
repeat = removeDuplicateColumns(repeat);
// add virtual slot, LogicalAggregate and LogicalProject for normalize