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

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


The following commit(s) were added to refs/heads/master by this push:
     new 601f28dd90 [fix](regexpr)regexpr functions' contexts should be 
THREAD_LOCAL (#11595)
601f28dd90 is described below

commit 601f28dd9064554dae9cda0b134bd4be8fb57a8e
Author: starocean999 <40539150+starocean...@users.noreply.github.com>
AuthorDate: Wed Aug 10 06:58:24 2022 +0800

    [fix](regexpr)regexpr functions' contexts should be THREAD_LOCAL (#11595)
---
 be/src/vec/functions/function_regexp.cpp | 48 ++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/be/src/vec/functions/function_regexp.cpp 
b/be/src/vec/functions/function_regexp.cpp
index 570c7f3399..c99bb84d31 100644
--- a/be/src/vec/functions/function_regexp.cpp
+++ b/be/src/vec/functions/function_regexp.cpp
@@ -49,24 +49,24 @@ public:
     }
 
     Status prepare(FunctionContext* context, 
FunctionContext::FunctionStateScope scope) override {
-        if (scope != FunctionContext::FRAGMENT_LOCAL) {
-            return Status::OK();
-        }
-
-        if (context->is_col_constant(1)) {
-            const auto pattern_col = context->get_constant_col(1)->column_ptr;
-            const auto& pattern = pattern_col->get_data_at(0).to_string_val();
-            if (pattern.is_null) {
-                return Status::OK();
-            }
+        if (scope == FunctionContext::THREAD_LOCAL) {
+            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).to_string_val();
+                if (pattern.is_null) {
+                    return Status::OK();
+                }
 
-            std::string error_str;
-            re2::RE2* re = StringFunctions::compile_regex(pattern, &error_str, 
StringVal::null());
-            if (re == nullptr) {
-                context->set_error(error_str.c_str());
-                return Status::InvalidArgument(error_str);
+                std::string error_str;
+                re2::RE2* re =
+                        StringFunctions::compile_regex(pattern, &error_str, 
StringVal::null());
+                if (re == nullptr) {
+                    context->set_error(error_str.c_str());
+                    return Status::InvalidArgument(error_str);
+                }
+                context->set_function_state(scope, re);
             }
-            context->set_function_state(scope, re);
         }
         return Status::OK();
     }
@@ -101,9 +101,13 @@ public:
     }
 
     Status close(FunctionContext* context, FunctionContext::FunctionStateScope 
scope) override {
-        if (scope == FunctionContext::FRAGMENT_LOCAL) {
-            re2::RE2* re = 
reinterpret_cast<re2::RE2*>(context->get_function_state(scope));
-            delete re;
+        if (scope == FunctionContext::THREAD_LOCAL) {
+            if (context->is_col_constant(1)) {
+                re2::RE2* re = 
reinterpret_cast<re2::RE2*>(context->get_function_state(scope));
+                DCHECK(re);
+                delete re;
+                context->set_function_state(scope, nullptr);
+            }
         }
         return Status::OK();
     }
@@ -124,8 +128,9 @@ struct RegexpReplaceImpl {
                 StringOP::push_null_string(i, result_data, result_offset, 
null_map);
                 continue;
             }
+
             re2::RE2* re = reinterpret_cast<re2::RE2*>(
-                    
context->get_function_state(FunctionContext::FRAGMENT_LOCAL));
+                    
context->get_function_state(FunctionContext::THREAD_LOCAL));
             std::unique_ptr<re2::RE2> scoped_re; // destroys re if state->re 
is nullptr
             if (re == nullptr) {
                 std::string error_str;
@@ -171,8 +176,9 @@ struct RegexpExtractImpl {
                 StringOP::push_empty_string(i, result_data, result_offset);
                 continue;
             }
+
             re2::RE2* re = reinterpret_cast<re2::RE2*>(
-                    
context->get_function_state(FunctionContext::FRAGMENT_LOCAL));
+                    
context->get_function_state(FunctionContext::THREAD_LOCAL));
             std::unique_ptr<re2::RE2> scoped_re;
             if (re == nullptr) {
                 std::string error_str;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to