[fix](Nereids) should not fold constant when do ordinal group by (#29976)

This commit is contained in:
morrySnow
2024-01-16 14:31:04 +08:00
committed by yiguolei
parent 2297a5b6fc
commit 07de535c4c
3 changed files with 8 additions and 9 deletions

View File

@ -20,8 +20,6 @@ package org.apache.doris.nereids.rules.analysis;
import org.apache.doris.nereids.properties.OrderKey;
import org.apache.doris.nereids.rules.Rule;
import org.apache.doris.nereids.rules.RuleType;
import org.apache.doris.nereids.rules.expression.ExpressionRewriteContext;
import org.apache.doris.nereids.rules.expression.rules.FoldConstantRule;
import org.apache.doris.nereids.trees.expressions.Alias;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.NamedExpression;
@ -51,10 +49,8 @@ public class ResolveOrdinalInOrderByAndGroupBy implements AnalysisRuleFactory {
List<Slot> childOutput = sort.child().getOutput();
List<OrderKey> orderKeys = sort.getOrderKeys();
List<OrderKey> orderKeysWithoutOrd = new ArrayList<>();
ExpressionRewriteContext context = new ExpressionRewriteContext(ctx.cascadesContext);
for (OrderKey k : orderKeys) {
Expression expression = k.getExpr();
expression = FoldConstantRule.INSTANCE.rewrite(expression, context);
if (expression instanceof IntegerLikeLiteral) {
IntegerLikeLiteral i = (IntegerLikeLiteral) expression;
int ord = i.getIntValue();
@ -69,14 +65,12 @@ public class ResolveOrdinalInOrderByAndGroupBy implements AnalysisRuleFactory {
})
))
.add(RuleType.RESOLVE_ORDINAL_IN_GROUP_BY.build(
logicalAggregate().whenNot(agg -> agg.isOrdinalIsResolved()).thenApply(ctx -> {
logicalAggregate().whenNot(LogicalAggregate::isOrdinalIsResolved).thenApply(ctx -> {
LogicalAggregate<Plan> agg = ctx.root;
List<NamedExpression> aggOutput = agg.getOutputExpressions();
List<Expression> groupByWithoutOrd = new ArrayList<>();
ExpressionRewriteContext context = new ExpressionRewriteContext(ctx.cascadesContext);
boolean ordExists = false;
for (Expression groupByExpr : agg.getGroupByExpressions()) {
groupByExpr = FoldConstantRule.INSTANCE.rewrite(groupByExpr, context);
if (groupByExpr instanceof IntegerLikeLiteral) {
IntegerLikeLiteral i = (IntegerLikeLiteral) groupByExpr;
int ord = i.getIntValue();
@ -92,8 +86,8 @@ public class ResolveOrdinalInOrderByAndGroupBy implements AnalysisRuleFactory {
}
}
if (ordExists) {
return new LogicalAggregate(groupByWithoutOrd, agg.getOutputExpressions(), true,
agg.child());
return new LogicalAggregate<>(groupByWithoutOrd, agg.getOutputExpressions(),
true, agg.child());
} else {
return agg;
}