This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.2 by this push:
     new fa4316beaef [branch-4.2] : [fix](function) Validate regexp replacement 
strings before replacing (#71309) (#71360)
fa4316beaef is described below

commit fa4316beaef320fc65eb2c801e115bebd8646e9f
Author: TengJianPing <[email protected]>
AuthorDate: Fri Dec 4 09:01:37 2026 +0800

    [branch-4.2] : [fix](function) Validate regexp replacement strings before 
replacing (#71309) (#71360)
    
    Backport of #71309 to `branch-4.2`.
    
    Original merged commit: `89529eac8c31ef6cbe361148f6c10756ee6a99dd`.
    
    ### Backport adjustments
    
    - Port strict replacement validation to both separate 4.2
    implementations (`RegexpReplaceImpl` and `RegexpReplaceOneImpl`). Keep
    validation local to each block for constant pattern/replacement pairs.
    - Preserve NULL maps in the shared replacement-function wrapper before
    validation. The 4.2 generic NULL wrapper otherwise evaluates masked
    payloads and would incorrectly reject NULL rows containing malformed
    rewrites.
    - Retain the upstream regression suite and generated expected results
    unchanged. Add a BE unit test for the release-specific NULL adaptation,
    including three/four arguments and a NULL first row followed by an
    invalid constant rewrite.
    
    ### Backport validation
    
    - Scoped repository clang-format 16.0.6/check-format and `git diff
    --cached --check`: passed.
    - Both changed C++ translation units were parsed using the branch-4.2
    ASAN UT compilation database and clang-tidy 20
    (`clang-analyzer-core.*`). No compiler errors or diagnostics on changed
    lines. Full-file analysis returned exit 1 because four existing
    uninitialized-condition diagnostics in the unchanged regexp extraction
    implementation were promoted by WarningsAsErrors; these are outside this
    backport.
    - Both SQL regression files are byte-identical to the upstream PR,
    including its generated expected output.
    - Started `./run-be-ut.sh --run
    --filter='FunctionConstantArgumentTest.regexp*:FunctionLikeTest.regexp*'
    -j24`, then stopped during the full rebuild on a heavily loaded host. No
    unit tests executed; no passing UT result is claimed.
    - The branch-4.2 cluster regression suite was not run locally. CI
    validation will be requested with `run buildall`.
    - The release branch has no `build-support/run-clang-tidy.sh` or
    `build-support/check-build-hygiene.sh`; the direct clang-tidy check
    above was used as a limited fallback.
    
    Pre-submission status: Partially verified: local BE UT and target-branch
    SQL regression have not run; CI validation pending.
    
    The original description below is retained for context. Its build,
    unit-test and regression results were obtained on master; they are not
    evidence of a branch-4.2 run.
    
    <details>
    <summary>Original PR description (master)</summary>
    
    ### Background
    
    REGEXP_REPLACE and REGEXP_REPLACE_ONE use RE2 to replace all matches or
    the first match. Both accept capture references in the replacement and
    an explicit IGNORE_INVALID_ESCAPE option.
    
    ### What problem does this PR solve?
    
    Issue Number: None
    Related PR: #8307 (introduced global replacement), #13766 (introduced
    first-match replacement)
    PR Type: Bugfix
    
    Problem Summary:
    
    With one match and replacement `X\xY`, default-mode global replacement
    can keep only the prefix while first-match replacement leaves the input
    unchanged. Both silently accept an invalid rewrite. Validate strict
    rewrites before either operation so both report a meaningful argument
    error; legal backreferences, explicit IGNORE_INVALID_ESCAPE and NULL
    propagation remain unchanged.
    
    ### Details
    
    - **Frequency:** Always for the tested malformed escapes, trailing
    backslash and missing capture group in strict mode; real BE baseline
    tests returned OK for all 48 calls.
    - **Root cause:** RegexpReplaceImpl ignores RE2's replacement failure
    semantics and does not validate rewrite syntax. Replace and
    GlobalReplace handle a failed rewrite differently.
    - **Why existing tests missed it:** FunctionLikeTest covers successful
    replacement/backreferences/NULLs; FunctionConstantArgumentTest covers
    constant options and block changes. Native test_regexp_replace and
    test_regexp_invalid_pattern exercise permissive replacement and pattern
    failures, without asserting rejection of invalid strict rewrites.
    - **Fix:** Reuse CheckRewriteString in the common replacement path after
    NULL skipping and before modifying the source. Skip strict validation
    for the existing permissive option. Constant pattern/replacement pairs
    validate once per block, preserving lazy-join block boundaries.
    - **Other paths and branches:** Three- and four-argument, constant and
    column paths for both functions are covered. Extract/match functions
    have no replacement argument. Cached branch-3.1/4.0/4.1/4.2 have the
    same omission; only master was built and run. External
    dialect-conversion services were not exercised.
    - **Behavior change:** Invalid strict replacement arguments now fail,
    including when the source has no match, instead of silently returning
    partial or unchanged text.
    
    ### Testing
    
    - Local ASAN baseline:
    `FunctionConstantArgumentTest.regexp_replace_invalid_rewrite` fails
    because all 48 executions incorrectly return OK.
    - Local ASAN candidate: `./run-be-ut.sh --run
    --filter='FunctionConstantArgumentTest.regexp*:FunctionLikeTest.regexp*'
    -j48` passes all 27 tests.
    - `./build.sh --be --fe -j48 --output <isolated-output>` passes. The
    first attempt found an obsolete generated FE annotation after switching
    branches; moving stale generated annotations and rerunning the standard
    build resolved it.
    - Generated and independently checked test_regexp_invalid_rewrite.out:
    legal captures yield aXbYc, explicit permissive replacements yield
    aXxYc, NULL rows remain NULL. BE constant folding is tested both enabled
    and disabled.
    - `./run-regression-test.sh --run -d
    query_p0/sql_functions/string_functions,nereids_syntax_p0 -s
    test_regexp_invalid_rewrite,test_regexp_invalid_pattern,test_regexp_replace`
    passes all 3 suites with no skips.
    - Scoped repository clang-format 16/check-format and clang-tidy pass on
    both changed C++ files. `git diff --check` passes.
    
    ### Release note
    
    REGEXP_REPLACE and REGEXP_REPLACE_ONE now consistently reject invalid
    replacement strings in default mode. IGNORE_INVALID_ESCAPE retains its
    existing permissive behavior.
    
    ### Check List (For Author)
    
    - Behavior changed: Yes (see Details)
    - Does this need documentation: Yes; clarify strict rewrite errors and
    unchanged IGNORE_INVALID_ESCAPE behavior in the corresponding
    apache/doris-website SQL function pages.
    - Pre-submission status: Ready
    
    ### AI Disclosure
    
    - Tool: Codex (GPT-6)
    - Generated: Implementation, unit/regression tests and this description.
    - Human review: Pending author review.
    
    </details>
---
 be/src/exprs/function/function_regexp.cpp          | 85 +++++++++++++++++++---
 .../function/function_constant_argument_test.cpp   | 76 +++++++++++++++++++
 .../test_regexp_invalid_rewrite.out                | 19 +++++
 .../test_regexp_invalid_rewrite.groovy             | 76 +++++++++++++++++++
 4 files changed, 247 insertions(+), 9 deletions(-)

diff --git a/be/src/exprs/function/function_regexp.cpp 
b/be/src/exprs/function/function_regexp.cpp
index f5b5f04fabf..7fba735dfb7 100644
--- a/be/src/exprs/function/function_regexp.cpp
+++ b/be/src/exprs/function/function_regexp.cpp
@@ -45,6 +45,7 @@
 #include "core/string_ref.h"
 #include "core/types.h"
 #include "exec/common/stringop_substring.h"
+#include "exec/common/util.hpp"
 #include "exprs/aggregate/aggregate_function.h"
 #include "exprs/function/function.h"
 #include "exprs/function/simple_function_factory.h"
@@ -327,6 +328,10 @@ public:
 
     bool is_variadic() const override { return true; }
 
+    // The generic NULL wrapper evaluates nested payloads before restoring the 
null map.
+    // Preserve NULL rows here so an invalid replacement on such a row is not 
validated.
+    bool use_default_implementation_for_nulls() const override { return false; 
}
+
     DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
         return make_nullable(std::make_shared<DataTypeString>());
     }
@@ -337,6 +342,13 @@ public:
 
     Status open(FunctionContext* context, FunctionContext::FunctionStateScope 
scope) override {
         if (scope == FunctionContext::THREAD_LOCAL) {
+            // A constant NULL argument makes the result NULL before pattern 
compilation.
+            for (int i = 0; i < context->get_num_args(); ++i) {
+                if (context->is_col_constant(i) &&
+                    context->get_constant_col(i)->column_ptr()->only_null()) {
+                    return Status::OK();
+                }
+            }
             if (context->is_col_constant(1)) {
                 DCHECK(!context->get_function_state(scope));
                 const auto pattern_col = 
context->get_constant_col(1)->column_ptr();
@@ -367,6 +379,31 @@ public:
         size_t argument_size = arguments.size();
 
         auto result_null_map = ColumnUInt8::create(input_rows_count, 0);
+        Block args_block;
+        ColumnNumbers args;
+        for (const auto arg : arguments) {
+            auto argument = block.get_by_position(arg);
+            if (argument.type->is_nullable()) {
+                const auto info = argument.get_nullable_column_info();
+                // A NULL argument must not expose its nested payload to 
rewrite validation.
+                if (info.only_null) {
+                    block.get_by_position(result).column =
+                            
block.get_by_position(result).type->create_column_const(
+                                    input_rows_count, Field());
+                    return Status::OK();
+                }
+                if (info.has_null) {
+                    // A constant with a NULL bit was handled by the only_null 
branch above.
+                    DCHECK(!info.is_const);
+                    VectorizedUtils::update_null_map(
+                            result_null_map->get_data(),
+                            
argument.get_nullable_null_map_column()->get_data());
+                }
+                argument = argument.unnest_nullable(info, false);
+            }
+            args.push_back(args_block.columns());
+            args_block.insert(std::move(argument));
+        }
         auto result_data_column = ColumnString::create();
         auto& result_data = result_data_column->get_chars();
         auto& result_offset = result_data_column->get_offsets();
@@ -375,18 +412,18 @@ public:
         bool col_const[3];
         ColumnPtr argument_columns[3];
         for (int i = 0; i < 3; ++i) {
-            col_const[i] = 
is_column_const(*block.get_by_position(arguments[i]).column);
+            col_const[i] = 
is_column_const(*args_block.get_by_position(args[i]).column);
         }
         argument_columns[0] = col_const[0] ? static_cast<const ColumnConst&>(
-                                                     
*block.get_by_position(arguments[0]).column)
+                                                     
*args_block.get_by_position(args[0]).column)
                                                      .convert_to_full_column()
-                                           : 
block.get_by_position(arguments[0]).column;
+                                           : 
args_block.get_by_position(args[0]).column;
 
-        default_preprocess_parameter_columns(argument_columns, col_const, {1, 
2}, block, arguments);
+        default_preprocess_parameter_columns(argument_columns, col_const, {1, 
2}, args_block, args);
 
         StringRef options_value;
         if (argument_size == 4) {
-            options_value = 
block.get_by_position(arguments[3]).column->get_data_at(0);
+            options_value = 
args_block.get_by_position(args[3]).column->get_data_at(0);
         }
         if (col_const[1] && col_const[2]) {
             if constexpr (std::is_same_v<FourParamTypes, ParamTypes>) {
@@ -461,13 +498,17 @@ struct RegexpReplaceImpl {
         const auto* pattern_col = 
check_and_get_column<ColumnString>(argument_columns[1].get());
         const auto* replace_col = 
check_and_get_column<ColumnString>(argument_columns[2].get());
 
+        // Pattern and replacement are constant within this block. Skip NULL 
rows before
+        // validating, and do not retain validation state across blocks of a 
lazy join.
+        bool validate_rewrite = true;
         for (size_t i = 0; i < input_rows_count; ++i) {
             if (null_map[i]) {
                 StringOP::push_null_string(i, result_data, result_offset, 
null_map);
                 continue;
             }
             _execute_inner_loop<true>(context, str_col, pattern_col, 
replace_col, options_value,
-                                      result_data, result_offset, null_map, i);
+                                      result_data, result_offset, null_map, i, 
validate_rewrite);
+            validate_rewrite = false;
         }
     }
     template <bool Const>
@@ -476,7 +517,7 @@ struct RegexpReplaceImpl {
                                     const ColumnString* replace_col, const 
StringRef& options_value,
                                     ColumnString::Chars& result_data,
                                     ColumnString::Offsets& result_offset, 
NullMap& null_map,
-                                    const size_t index_now) {
+                                    const size_t index_now, bool 
validate_rewrite = true) {
         re2::RE2* re = reinterpret_cast<re2::RE2*>(
                 context->get_function_state(FunctionContext::THREAD_LOCAL));
         std::unique_ptr<re2::RE2> scoped_re; // destroys re if state->re is 
nullptr
@@ -496,6 +537,17 @@ struct RegexpReplaceImpl {
         re2::StringPiece replace_str = re2::StringPiece(
                 replace_col->get_data_at(index_check_const(index_now, 
Const)).to_string_view());
 
+        if (validate_rewrite && !re->options().ignore_replace_escape()) {
+            std::string error;
+            // For invalid rewrites such as X\\xY, GlobalReplace can consume a 
partial
+            // replacement while Replace keeps the original string. Reject 
both before
+            // modifying the source, unless the explicit permissive option is 
enabled.
+            if (!re->CheckRewriteString(replace_str, &error)) {
+                throw Exception(
+                        Status::InvalidArgument("Invalid regexp replacement 
string: {}", error));
+            }
+        }
+
         std::string result_str(str_col->get_data_at(index_now).to_string());
         re2::RE2::GlobalReplace(&result_str, *re, replace_str);
         StringOP::push_value_string(result_str, index_now, result_data, 
result_offset);
@@ -531,13 +583,17 @@ struct RegexpReplaceOneImpl {
         const auto* pattern_col = 
check_and_get_column<ColumnString>(argument_columns[1].get());
         const auto* replace_col = 
check_and_get_column<ColumnString>(argument_columns[2].get());
         // 3 args
+        // Pattern and replacement are constant within this block. Skip NULL 
rows before
+        // validating, and do not retain validation state across blocks of a 
lazy join.
+        bool validate_rewrite = true;
         for (size_t i = 0; i < input_rows_count; ++i) {
             if (null_map[i]) {
                 StringOP::push_null_string(i, result_data, result_offset, 
null_map);
                 continue;
             }
             _execute_inner_loop<true>(context, str_col, pattern_col, 
replace_col, options_value,
-                                      result_data, result_offset, null_map, i);
+                                      result_data, result_offset, null_map, i, 
validate_rewrite);
+            validate_rewrite = false;
         }
     }
     template <bool Const>
@@ -546,7 +602,7 @@ struct RegexpReplaceOneImpl {
                                     const ColumnString* replace_col, const 
StringRef& options_value,
                                     ColumnString::Chars& result_data,
                                     ColumnString::Offsets& result_offset, 
NullMap& null_map,
-                                    const size_t index_now) {
+                                    const size_t index_now, bool 
validate_rewrite = true) {
         re2::RE2* re = reinterpret_cast<re2::RE2*>(
                 context->get_function_state(FunctionContext::THREAD_LOCAL));
         std::unique_ptr<re2::RE2> scoped_re; // destroys re if state->re is 
nullptr
@@ -566,6 +622,17 @@ struct RegexpReplaceOneImpl {
         re2::StringPiece replace_str = re2::StringPiece(
                 replace_col->get_data_at(index_check_const(index_now, 
Const)).to_string_view());
 
+        if (validate_rewrite && !re->options().ignore_replace_escape()) {
+            std::string error;
+            // For invalid rewrites such as X\\xY, GlobalReplace can consume a 
partial
+            // replacement while Replace keeps the original string. Reject 
both before
+            // modifying the source, unless the explicit permissive option is 
enabled.
+            if (!re->CheckRewriteString(replace_str, &error)) {
+                throw Exception(
+                        Status::InvalidArgument("Invalid regexp replacement 
string: {}", error));
+            }
+        }
+
         std::string result_str(str_col->get_data_at(index_now).to_string());
         re2::RE2::Replace(&result_str, *re, replace_str);
         StringOP::push_value_string(result_str, index_now, result_data, 
result_offset);
diff --git a/be/test/exprs/function/function_constant_argument_test.cpp 
b/be/test/exprs/function/function_constant_argument_test.cpp
index 7346780084f..c4e935d59f4 100644
--- a/be/test/exprs/function/function_constant_argument_test.cpp
+++ b/be/test/exprs/function/function_constant_argument_test.cpp
@@ -174,6 +174,82 @@ TEST_F(FunctionConstantArgumentTest, 
regexp_replace_options) {
     EXPECT_EQ(empty_block.get_by_position(4).column->size(), 0);
 }
 
+TEST_F(FunctionConstantArgumentTest, regexp_replace_invalid_rewrite) {
+    auto string_type = std::make_shared<DataTypeString>();
+    auto return_type = make_nullable(string_type);
+    for (const std::string name : {"regexp_replace", "regexp_replace_one"}) {
+        // Invalid escapes, a trailing backslash and a missing capture group 
must
+        // fail before RE2 can discard the replacement suffix or keep the 
source.
+        for (const std::string rewrite : {"X\\xY", "X\\", "X\\2Y"}) {
+            for (int shape = 0; shape < 8; ++shape) {
+                SCOPED_TRACE(name + ": " + rewrite + ", shape=" + 
std::to_string(shape));
+                const std::vector<std::string> values = {"abc", "(b)", 
rewrite};
+                Block block;
+                std::vector<std::shared_ptr<ConstantExprResult>> constants(3);
+                for (size_t arg = 0; arg < values.size(); ++arg) {
+                    ColumnPtr column = strings({values[arg]});
+                    if (shape & (1 << arg)) {
+                        column = ColumnConst::create(column, 1);
+                        constants[arg] = constant(column);
+                    }
+                    block.insert({column, string_type, std::to_string(arg)});
+                }
+                Status status = execute(name, block, return_type, constants);
+                EXPECT_TRUE(status.is<ErrorCode::INVALID_ARGUMENT>()) << 
status;
+                EXPECT_NE(status.to_string().find("Invalid regexp replacement 
string"),
+                          std::string::npos)
+                        << status;
+            }
+        }
+    }
+}
+
+TEST_F(FunctionConstantArgumentTest, 
regexp_replace_invalid_rewrite_on_null_rows) {
+    auto string_type = std::make_shared<DataTypeString>();
+    auto nullable_string_type = make_nullable(string_type);
+    for (const std::string name : {"regexp_replace", "regexp_replace_one"}) {
+        for (const bool with_options : {false, true}) {
+            Block block;
+            const std::vector<std::vector<std::string>> values = {
+                    {"abc", "abc", "abc", "abc"},
+                    {"(b)", "(b)", "(b)", "(b)"},
+                    {"X\\1Y", "X\\xY", "X\\xY", "X\\xY"}};
+            for (size_t arg = 0; arg < values.size(); ++arg) {
+                auto null_map = ColumnUInt8::create(4, 0);
+                null_map->get_data()[arg + 1] = 1;
+                block.insert({ColumnNullable::create(strings(values[arg]), 
std::move(null_map)),
+                              nullable_string_type, std::to_string(arg)});
+            }
+            if (with_options) {
+                block.insert({ColumnConst::create(strings({"none"}), 4), 
string_type, "options"});
+            }
+            const auto result_index = block.columns();
+            Status status = execute(name, block, nullable_string_type,
+                                    
std::vector<std::shared_ptr<ConstantExprResult>>(result_index));
+            ASSERT_TRUE(status.ok()) << status;
+            const auto& result = *block.get_by_position(result_index).column;
+            EXPECT_EQ(result.get_data_at(0).to_string(), "aXbYc");
+            for (size_t row = 1; row < 4; ++row) {
+                EXPECT_TRUE(result.is_null_at(row));
+            }
+        }
+
+        // Skipping the first NULL row must not mark a constant rewrite as 
already validated.
+        Block block;
+        auto null_map = ColumnUInt8::create(2, 0);
+        null_map->get_data()[0] = 1;
+        block.insert({ColumnNullable::create(strings({"abc", "abc"}), 
std::move(null_map)),
+                      nullable_string_type, "s"});
+        ColumnPtr pattern = ColumnConst::create(strings({"(b)"}), 2);
+        ColumnPtr replacement = ColumnConst::create(strings({"X\\xY"}), 2);
+        block.insert({pattern, string_type, "pattern"});
+        block.insert({replacement, string_type, "replacement"});
+        Status status = execute(name, block, nullable_string_type,
+                                {nullptr, constant(pattern), 
constant(replacement)});
+        EXPECT_TRUE(status.is<ErrorCode::INVALID_ARGUMENT>()) << status;
+    }
+}
+
 TEST_F(FunctionConstantArgumentTest, 
regexp_replace_pattern_changes_across_blocks) {
     // A lazy join can pass a probe-side pattern as a physical ColumnConst for 
one block while the
     // pattern is not a query-level constant, so FE's constant_cols entry for 
it is nullptr here
diff --git 
a/regression-test/data/query_p0/sql_functions/string_functions/test_regexp_invalid_rewrite.out
 
b/regression-test/data/query_p0/sql_functions/string_functions/test_regexp_invalid_rewrite.out
new file mode 100644
index 00000000000..4015c57ef80
--- /dev/null
+++ 
b/regression-test/data/query_p0/sql_functions/string_functions/test_regexp_invalid_rewrite.out
@@ -0,0 +1,19 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !constants_false --
+aXbYc  aXbYc   aXxYc   aXxYc
+
+-- !constants_true --
+aXbYc  aXbYc   aXxYc   aXxYc
+
+-- !nullable --
+1      aXbYc   aXbYc
+3      \N      \N
+4      \N      \N
+5      \N      \N
+
+-- !ignore_invalid_escape --
+1      aXbYc   aXbYc
+2      aXxYc   aXxYc
+3      \N      \N
+4      \N      \N
+5      \N      \N
diff --git 
a/regression-test/suites/query_p0/sql_functions/string_functions/test_regexp_invalid_rewrite.groovy
 
b/regression-test/suites/query_p0/sql_functions/string_functions/test_regexp_invalid_rewrite.groovy
new file mode 100644
index 00000000000..e6af13b40e6
--- /dev/null
+++ 
b/regression-test/suites/query_p0/sql_functions/string_functions/test_regexp_invalid_rewrite.groovy
@@ -0,0 +1,76 @@
+// 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.
+
+// Both replacement functions reject invalid rewrites in strict mode, whether
+// the arguments are constants or columns.
+suite("test_regexp_invalid_rewrite", "p0") {
+    def functions = ["regexp_replace", "regexp_replace_one"]
+    def originalFold = sql("select @@enable_fold_constant_by_be")[0][0]
+    try {
+        [false, true].each { fold ->
+            sql "set enable_fold_constant_by_be = ${fold}"
+            functions.each { function ->
+                test {
+                    sql "SELECT ${function}('abc', '(b)', CONCAT('X', 
CHAR(92), 'xY'))"
+                    exception "Invalid regexp replacement string"
+                }
+                test {
+                    sql "SELECT ${function}('abc', '(b)', CONCAT('X', 
CHAR(92), 'xY'), 'none')"
+                    exception "Invalid regexp replacement string"
+                }
+                // Invalid rewrite arguments must not depend on whether the 
source matches.
+                test {
+                    sql "SELECT ${function}('zzz', '(b)', CONCAT('X', 
CHAR(92), 'xY'))"
+                    exception "Invalid regexp replacement string"
+                }
+            }
+            "order_qt_constants_${fold}" """SELECT
+                regexp_replace('abc', '(b)', CONCAT('X', CHAR(92), '1Y')),
+                regexp_replace_one('abc', '(b)', CONCAT('X', CHAR(92), '1Y')),
+                regexp_replace('abc', '(b)', CONCAT('X', CHAR(92), 'xY'), 
'IGNORE_INVALID_ESCAPE'),
+                regexp_replace_one('abc', '(b)', CONCAT('X', CHAR(92), 'xY'), 
'IGNORE_INVALID_ESCAPE')"""
+        }
+    } finally {
+        sql "set enable_fold_constant_by_be = ${originalFold}"
+    }
+
+    sql "DROP TABLE IF EXISTS test_regexp_invalid_rewrite"
+    sql """CREATE TABLE test_regexp_invalid_rewrite (
+        id INT, s STRING, p STRING, r STRING
+    ) DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1
+    PROPERTIES("replication_num" = "1")"""
+    sql """INSERT INTO test_regexp_invalid_rewrite VALUES
+        (1, 'abc', '(b)', CONCAT('X', CHAR(92), '1Y')),
+        (2, 'abc', '(b)', CONCAT('X', CHAR(92), 'xY')),
+        (3, NULL, '(b)', CONCAT('X', CHAR(92), 'xY')),
+        (4, 'abc', '(b)', NULL),
+        (5, 'abc', NULL, CONCAT('X', CHAR(92), 'xY'))"""
+    functions.each { function ->
+        ["s, p, r", "s, '(b)', r", "'abc', p, r", "'abc', '(b)', r"].each { 
arguments ->
+            test {
+                sql "SELECT ${function}(${arguments}) FROM 
test_regexp_invalid_rewrite WHERE id = 2"
+                exception "Invalid regexp replacement string"
+            }
+        }
+    }
+    // NULL rows skip rewrite validation, even when a non-NULL replacement is 
invalid.
+    order_qt_nullable """SELECT id, regexp_replace(s, p, r), 
regexp_replace_one(s, p, r)
+        FROM test_regexp_invalid_rewrite WHERE id <> 2"""
+    order_qt_ignore_invalid_escape """SELECT id,
+        regexp_replace(s, p, r, 'IGNORE_INVALID_ESCAPE'),
+        regexp_replace_one(s, p, r, 'IGNORE_INVALID_ESCAPE') FROM 
test_regexp_invalid_rewrite"""
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to