github-actions[bot] commented on code in PR #68579:
URL: https://github.com/apache/doris/pull/68579#discussion_r4219163461


##########
be/src/exprs/function/function_regexp.cpp:
##########
@@ -404,69 +398,103 @@ class FunctionRegexpReplace : public IFunction {
         for (int i = 0; i < 3; ++i) {
             col_const[i] = 
is_column_const(*block.get_by_position(arguments[i]).column);
         }
-        argument_columns[0] = col_const[0] ? static_cast<const ColumnConst&>(
-                                                     
*block.get_by_position(arguments[0]).column)
-                                                     .convert_to_full_column()
-                                           : 
block.get_by_position(arguments[0]).column;
+        const auto& [source_column, source_const] =
+                unpack_if_const(block.get_by_position(arguments[0]).column);
+        argument_columns[0] = source_column;
 
         default_preprocess_parameter_columns(argument_columns, col_const, {1, 
2}, block, arguments);
 
+        if constexpr (std::is_same_v<FourParamTypes, ParamTypes>) {
+            // The regex of a constant pattern was not compiled in open 
because the options were
+            // not evaluated there. Compile it once with the options of the 
first row.
+            if (col_const[1] && !context->is_col_constant(3) && 
input_rows_count > 0 &&

Review Comment:
   [P1] Cache this pattern only when the expression is query constant. A lazy 
nested-loop join can pass `probe.pat` as a physical `ColumnConst` for each 
probe row while `VSlotRef::is_constant()` remains false. With a BE-evaluated 
constant options expression, this branch compiles the first probe's pattern 
into THREAD_LOCAL state and `_execute_inner_loop` reuses it for later probes. 
For `build.s = 'a'` and probe patterns `a`, then `b`, `regexp_replace(build.s, 
probe.pat, 'x', if(crc32('') = 0, 'none', 'ignore_invalid_escape')) = 'x'` 
incorrectly matches both probes instead of only the first. Both replacement 
variants share this path. Gate caching on `context->is_col_constant(1)` (or 
invalidate by pattern and options), and test two executions with different 
Const patterns on one function context.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DateTrunc.java:
##########
@@ -62,13 +63,53 @@ private DateTrunc(ScalarFunctionParams functionParams) {
         super(functionParams);
     }
 
+    @Override
+    public Expression prepareBeforeTypeCoercion() {
+        // When an argument is a date, the other one is the time unit, and the 
signature does not need its value.
+        if (getArgument(0).getDataType().isDateLikeType() || 
getArgument(1).getDataType().isDateLikeType()) {
+            return this;
+        }
+        // Otherwise customSignature tells the time unit from the date value 
by the literal time unit, so fold a
+        // constant string that evaluates to a time unit, unless the other 
argument already is one. A string date
+        // value is kept unfolded, because folding it would change the derived 
return type.
+        return withChildren((argument, index) -> {
+            if (!argument.getDataType().isStringLikeType() || 
isTimeUnit(getArgument(1 - index))) {
+                return argument;
+            }
+            Expression folded = ExpressionUtils.foldConstantArgument(argument);
+            return isTimeUnit(folded) ? folded : argument;
+        });
+    }
+
+    private static boolean isTimeUnit(Expression expression) {
+        return expression instanceof StringLikeLiteral
+                && LEGAL_TIME_UNIT.contains(((StringLikeLiteral) 
expression).getStringValue().toLowerCase());
+    }
+
+    private static boolean isConstantString(Expression expression) {
+        return expression.isConstant() && 
expression.getDataType().isStringLikeType();
+    }
+
     @Override
     public void checkLegalityBeforeTypeCoercion() {
         boolean firstArgIsStringLiteral =
                 getArgument(0).isConstant() && getArgument(0) instanceof 
StringLikeLiteral;
         boolean secondArgIsStringLiteral =
                 getArgument(1).isConstant() && getArgument(1) instanceof 
StringLikeLiteral;
         if (!firstArgIsStringLiteral && !secondArgIsStringLiteral) {
+            for (int i = 0; i < 2; i++) {

Review Comment:
   [P2] Accept a BE-only constant unit beside a VARCHAR date expression. In 
`Project(date_trunc(s:VARCHAR, lpad('nth',5,'mo'))) -> Scan(s)`, `lpad` 
evaluates to `month` but stays nonliteral on FE. This branch then sees neither 
a literal unit nor a date-typed argument and rejects the call; `date_trunc(s, 
'month')` succeeds, and reversing the arguments has the same gap. The 
nonconstant `s` and constant unit identify their roles, so select the 
corresponding signature and let BE validate the evaluated unit. Please cover 
both orders with a VARCHAR column.



-- 
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]

Reply via email to