From bda1355c0a113294b10017e736185738799db23a Mon Sep 17 00:00:00 2001 From: LiBinfeng <1204975323@qq.com> Date: Wed, 21 Aug 2024 18:07:45 +0800 Subject: [PATCH 1/3] [fix](Nereids) fix fold constant by be return type mismatched --- .../rules/expression/rules/FoldConstantRuleOnBE.java | 6 +++++- .../expression/fold_constant/fold_constant_by_be.groovy | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java index d133eac32baddb..637c52e7c2ce2c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java @@ -176,7 +176,11 @@ private static Expression replace( if (newChild != child) { hasNewChildren = true; } - newChildren.add(newChild); + if (newChild.getDataType() != child.getDataType()) { + newChildren.add(newChild.castTo(child.getDataType())); + } else { + newChildren.add(newChild); + } } return hasNewChildren ? root.withChildren(newChildren) : root; } diff --git a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_by_be.groovy b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_by_be.groovy index 809b8e8b291d23..668e88c6f04944 100644 --- a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_by_be.groovy +++ b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_by_be.groovy @@ -53,4 +53,9 @@ suite("fold_constant_by_be") { sql 'set query_timeout=12;' qt_sql "select sleep(sign(1)*5);" + + explain { + sql("verbose select substring('123456', 1, 3)") + contains "varchar(3)" + } } From 5b9da22ed9a44c545d656551ffe5009cfb3ebc10 Mon Sep 17 00:00:00 2001 From: LiBinfeng <1204975323@qq.com> Date: Thu, 12 Sep 2024 17:20:56 +0800 Subject: [PATCH 2/3] fix comment --- .../nereids/rules/expression/rules/FoldConstantRuleOnBE.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java index 637c52e7c2ce2c..b237a3d6c5eed6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java @@ -176,7 +176,7 @@ private static Expression replace( if (newChild != child) { hasNewChildren = true; } - if (newChild.getDataType() != child.getDataType()) { + if (!newChild.getDataType().equals(child.getDataType())) { newChildren.add(newChild.castTo(child.getDataType())); } else { newChildren.add(newChild); From 951da11c2b7b7710e63f2b8a6a88f7318948ebed Mon Sep 17 00:00:00 2001 From: LiBinfeng <1204975323@qq.com> Date: Thu, 19 Sep 2024 11:09:06 +0800 Subject: [PATCH 3/3] fix p0 problem --- .../rules/expression/rules/FoldConstantRuleOnBE.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java index b237a3d6c5eed6..810d281ac579ac 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java @@ -177,7 +177,12 @@ private static Expression replace( hasNewChildren = true; } if (!newChild.getDataType().equals(child.getDataType())) { - newChildren.add(newChild.castTo(child.getDataType())); + try { + newChildren.add(newChild.castTo(child.getDataType())); + } catch (Exception e) { + LOG.warn("expression of type {} cast to {} failed. ", newChild.getDataType(), child.getDataType()); + newChildren.add(newChild); + } } else { newChildren.add(newChild); }