Skip to content

Commit 7b7e114

Browse files
committed
[fix](Nereids) fix fold constant by be return type mismatched (apache#39723)(apache#41164) (apache#41537)
cherry-pick: apache#39723 apache#41164 because later problem is intro by prev one, so put them together when using fold constant by be, the return type of substring('123456',1, 3) would changed to be text, which we want it to be 3 remove windowframe in window expression to avoid folding constant on be
1 parent 1332f28 commit 7b7e114

File tree

4 files changed

+20
-91
lines changed

4 files changed

+20
-91
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,16 @@ private static Expression replace(
175175
if (newChild != child) {
176176
hasNewChildren = true;
177177
}
178-
newChildren.add(newChild);
178+
if (!newChild.getDataType().equals(child.getDataType())) {
179+
try {
180+
newChildren.add(newChild.castTo(child.getDataType()));
181+
} catch (Exception e) {
182+
LOG.warn("expression of type {} cast to {} failed. ", newChild.getDataType(), child.getDataType());
183+
newChildren.add(newChild);
184+
}
185+
} else {
186+
newChildren.add(newChild);
187+
}
179188
}
180189
return hasNewChildren ? root.withChildren(newChildren) : root;
181190
}

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/WindowExpression.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public WindowExpression(Expression function, List<Expression> partitionKeys, Lis
6666
.add(function)
6767
.addAll(partitionKeys)
6868
.addAll(orderKeys)
69-
.add(windowFrame)
7069
.build());
7170
this.function = function;
7271
this.partitionKeys = ImmutableList.copyOf(partitionKeys);
@@ -153,6 +152,9 @@ public WindowExpression withChildren(List<Expression> children) {
153152
if (index < children.size()) {
154153
return new WindowExpression(func, partitionKeys, orderKeys, (WindowFrame) children.get(index));
155154
}
155+
if (windowFrame.isPresent()) {
156+
return new WindowExpression(func, partitionKeys, orderKeys, windowFrame.get());
157+
}
156158
return new WindowExpression(func, partitionKeys, orderKeys);
157159
}
158160

fe/fe-core/src/test/java/org/apache/doris/nereids/preprocess/SelectHintTest.java

-88
This file was deleted.

regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_by_be.groovy

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,11 @@ suite("fold_constant_by_be") {
4848

4949
qt_sql "explain select sleep(sign(1)*100);"
5050
sql 'set query_timeout=12;'
51-
qt_sql "select sleep(sign(1)*5);"
51+
qt_sql "select sleep(sign(1)*10);"
52+
53+
explain {
54+
sql("verbose select substring('123456', 1, 3)")
55+
contains "varchar(3)"
56+
}
57+
5258
}

0 commit comments

Comments
 (0)