This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch dev-1.1.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/dev-1.1.2 by this push:
new 81e714418e [fix](regexpr)regexpr functions' contexts should be
THREAD_LOCAL (#11595) (#12211)
81e714418e is described below
commit 81e714418ea86047e21bffff89a62881c56c59c9
Author: starocean999 <[email protected]>
AuthorDate: Wed Aug 31 14:33:03 2022 +0800
[fix](regexpr)regexpr functions' contexts should be THREAD_LOCAL (#11595)
(#12211)
---
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: [email protected]
For additional commands, e-mail: [email protected]