HappenLee commented on code in PR #51392: URL: https://github.com/apache/doris/pull/51392#discussion_r2117964079
########## be/src/vec/functions/function_regexp.cpp: ########## @@ -501,6 +502,84 @@ struct RegexpExtractAllImpl { } }; +struct RegexpCountImpl { + static constexpr auto name = "regexp_count"; + + static void execute_impl(FunctionContext* context, ColumnPtr argument_columns[], + size_t input_rows_count, ColumnInt64::Container& result_data, + NullMap& null_map) { + const auto* str_col = check_and_get_column<ColumnString>(argument_columns[0].get()); + const auto* pattern_col = check_and_get_column<ColumnString>(argument_columns[1].get()); + for (int i = 0; i < input_rows_count; ++i) { + if (null_map[i]) { + result_data[i] = 0; + continue; + } + result_data[i] = _execute_inner_loop<false>(context, str_col, pattern_col, null_map, i); + } + } + + static void execute_impl_const_args(FunctionContext* context, ColumnPtr argument_columns[], + size_t input_rows_count, + ColumnInt64::Container& result_data, NullMap& null_map) { + const auto* str_col = check_and_get_column<ColumnString>(argument_columns[0].get()); + const auto* pattern_col = check_and_get_column<ColumnString>(argument_columns[1].get()); + for (int i = 0; i < input_rows_count; ++i) { + if (null_map[i]) { + result_data[i] = 0; + continue; + } + result_data[i] = _execute_inner_loop<true>(context, str_col, pattern_col, null_map, i); + } + } + + template <bool Const> + static int64_t _execute_inner_loop(FunctionContext* context, const ColumnString* str_col, + const ColumnString* pattern_col, NullMap& null_map, + const size_t index_now) { + re2::RE2* re = reinterpret_cast<re2::RE2*>( + context->get_function_state(FunctionContext::THREAD_LOCAL)); + std::unique_ptr<re2::RE2> scoped_re; + if (re == nullptr) { + std::string error_str; + const auto& pattern = pattern_col->get_data_at(index_check_const(index_now, Const)); + bool st = StringFunctions::compile_regex(pattern, &error_str, StringRef(), StringRef(), Review Comment: if the second args is const. better compile one time just in open? -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org