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


##########
be/src/exprs/function/function_regexp.cpp:
##########
@@ -361,29 +361,19 @@ class FunctionRegexpReplace : public IFunction {
             if (context->is_col_constant(1)) {
                 DCHECK(!context->get_function_state(scope));
                 const auto pattern_col = 
context->get_constant_col(1)->column_ptr;
-                const auto& pattern = pattern_col->get_data_at(0);
-                if (pattern.size == 0) {
-                    return Status::OK();
-                }
-
-                std::string error_str;
-                std::unique_ptr<re2::RE2> scoped_re;
                 StringRef options_value;
                 if constexpr (std::is_same_v<FourParamTypes, ParamTypes>) {
                     DCHECK_EQ(context->get_num_args(), 4);
-                    DCHECK(context->is_col_constant(3));
+                    // The options are a constant, but a constant expression 
such as an arithmetic
+                    // one is not evaluated in open. Then the regex is 
compiled in execute.
+                    if (!context->is_col_constant(3)) {
+                        return Status::OK();
+                    }
                     const auto options_col = 
context->get_constant_col(3)->column_ptr;
                     options_value = options_col->get_data_at(0);
                 }
-
-                bool st = StringFunctions::compile_regex(pattern, &error_str, 
StringRef(),
-                                                         options_value, 
scoped_re);
-                if (!st) {
-                    context->set_error(error_str.c_str());
-                    return Status::InvalidArgument(error_str);
-                }
-                std::shared_ptr<re2::RE2> re(scoped_re.release());
-                context->set_function_state(scope, re);
+                return compile_constant_pattern(context, 
pattern_col->get_data_at(0),

Review Comment:
   [P2] Let NULL options short-circuit before compiling the regexp. The new 
constant-argument gate accepts `CAST(NULL AS STRING)` as the fourth argument. 
In a multirow `INSERT ... VALUES`, FE leaves that cast for BE; 
`regexp_replace('abc', '[', 'x', CAST(NULL AS STRING))` now reaches this `open` 
call and fails while compiling `'['`, before the scalar NULL wrapper can return 
NULL. `regexp_replace_one` shares this path. Skip eager compilation for a NULL 
options column or defer it until after NULL propagation, and cover both 
variants in a multirow VALUES regression. This is a separate function from the 
existing date_trunc NULL-unit thread.



##########
be/src/exprs/function/function_regexp.cpp:
##########
@@ -411,14 +401,25 @@ class FunctionRegexpReplace : public IFunction {
 
         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:
   [P2] Keep a constant regexp source compact with deferred options. A 
BE-evaluated constant options expression can be a full column, such as 
`cast(uniform(1, 2, crc32('x')) as string)`, so the all-constant wrapper is 
bypassed. This newly allowed path reaches the existing 
`convert_to_full_column()` for a constant source: `regexp_replace(repeat('x', 
1048576), '^.*$', '', cast(uniform(1, 2, crc32('x')) as string))` over 1024 
rows copies about 1 GiB of input even though each result is empty. Index row 0 
of a constant source in the mixed-column path, or otherwise avoid materializing 
it. This is a separate expansion site from the existing SHA2 and array_apply 
comments.



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