[fix](Nereids) simplify window expression should inherit data type (#37061) (#37283)

pick from master #37061

after window expression rewritten by literal.
literal's data type should same with original window expression.
This commit is contained in:
morrySnow
2024-07-04 19:19:05 +08:00
committed by GitHub
parent e4fb506c20
commit c7ad1f3d21
3 changed files with 17 additions and 1 deletions

View File

@ -22,6 +22,7 @@ import org.apache.doris.nereids.pattern.MatchingContext;
import org.apache.doris.nereids.rules.Rule;
import org.apache.doris.nereids.rules.RuleType;
import org.apache.doris.nereids.trees.expressions.Alias;
import org.apache.doris.nereids.trees.expressions.Cast;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.NamedExpression;
import org.apache.doris.nereids.trees.expressions.Slot;
@ -91,7 +92,8 @@ public class SimplifyWindowExpression extends OneRewriteRuleFactory {
String name = ((BoundFunction) function).getName();
if ((name.equals(COUNT) && checkCount((Count) boundFunction))
|| REWRRITE_TO_CONST_WINDOW_FUNCTIONS.contains(name)) {
projectionsBuilder.add(new Alias(alias.getExprId(), new TinyIntLiteral((byte) 1), alias.getName()));
projectionsBuilder.add(new Alias(alias.getExprId(),
new Cast(new TinyIntLiteral((byte) 1), function.getDataType()), alias.getName()));
} else if (REWRRITE_TO_SLOT_WINDOW_FUNCTIONS.contains(name)) {
projectionsBuilder.add(new Alias(alias.getExprId(),
TypeCoercionUtils.castIfNotSameType(boundFunction.child(0), boundFunction.getDataType()),