github-actions[bot] commented on code in PR #62205:
URL: https://github.com/apache/doris/pull/62205#discussion_r3051161196
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java:
##########
@@ -954,6 +956,15 @@ public static ImmutableMap<Slot, Expression>
extractUniformSlot(Expression expre
if (expression instanceof EqualTo) {
if (isInjective(expression.child(0)) &&
expression.child(1).isConstant()) {
builder.put((Slot) expression.child(0), expression.child(1));
+ } else {
+ // length(str_col)=0 => str_col=''
Review Comment:
This new inference is too broad. `Length` is not string-only here; it also
accepts `VARBINARY` (`Length.SIGNATURES` includes `VarBinaryType`). For a
user-written predicate like `length(bin_col) = 0`, this now records `bin_col`
as the string constant `''`, and that value flows into uniform-slot based
constant propagation. At that point downstream rewrites can substitute a string
literal for a binary slot, which is a semantic/type regression unrelated to the
pruning optimization. This needs at least a character-type guard before
inferring `slot = ''`.
##########
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/StringEmptyToLengthRuleTest.java:
##########
@@ -0,0 +1,141 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.rules.expression.rules;
+
+import org.apache.doris.nereids.rules.expression.ExpressionRewriteTestHelper;
+import org.apache.doris.nereids.rules.expression.ExpressionRuleExecutor;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Not;
+import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Length;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
+import org.apache.doris.nereids.types.IntegerType;
+import org.apache.doris.nereids.types.StringType;
+import org.apache.doris.nereids.types.VarcharType;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class StringEmptyToLengthRuleTest extends ExpressionRewriteTestHelper {
+
+ @BeforeEach
+ public void setup() {
+ executor = new ExpressionRuleExecutor(ImmutableList.of(
+ bottomUp(StringEmptyToLengthRule.INSTANCE)
+ ));
+ }
+
+ // ─── Helper: rewrite without type coercion
───────────────────────────────────
+ // We bypass ExpressionRewriteTestHelper.assertRewrite() because that
method
Review Comment:
This test is pointing at a real bug in the implementation: the production
pipeline does run type coercion before `ExpressionOptimization`, and that wraps
`''` in `Cast(...)`. `StringEmptyToLengthRule` only matches raw `Literal`s, so
the normal analyzed shape of `str_col = ''` will not be rewritten at all.
Because of that, the optimization this PR is trying to add does not fire for
the main query form unless the matcher is extended to handle the coerced
literal shape as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]