[fix](nereids)remove literal partition by and order by expression in window function (#26899)
This commit is contained in:
@ -39,6 +39,7 @@ import com.google.common.collect.Sets;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@ -52,14 +53,24 @@ public class ExtractAndNormalizeWindowExpression extends OneRewriteRuleFactory i
|
||||
List<NamedExpression> outputs =
|
||||
ExpressionUtils.rewriteDownShortCircuit(project.getProjects(), output -> {
|
||||
if (output instanceof WindowExpression) {
|
||||
WindowExpression windowExpression = (WindowExpression) output;
|
||||
Expression expression = ((WindowExpression) output).getFunction();
|
||||
if (expression instanceof Sum || expression instanceof Max
|
||||
|| expression instanceof Min || expression instanceof Avg) {
|
||||
// sum, max, min and avg in window function should be always nullable
|
||||
return ((WindowExpression) output)
|
||||
windowExpression = ((WindowExpression) output)
|
||||
.withFunction(((NullableAggregateFunction) expression)
|
||||
.withAlwaysNullable(true));
|
||||
}
|
||||
// remove literal partition by and order by keys
|
||||
return windowExpression.withPartitionKeysOrderKeys(
|
||||
windowExpression.getPartitionKeys().stream()
|
||||
.filter(partitionExpr -> !partitionExpr.isConstant())
|
||||
.collect(Collectors.toList()),
|
||||
windowExpression.getOrderKeys().stream()
|
||||
.filter(orderExpression -> !orderExpression
|
||||
.getOrderKey().getExpr().isConstant())
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
return output;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user