Skip to content

Commit

Permalink
[Bug][Fix] regexp function core dump DCHECK failed and error result (a…
Browse files Browse the repository at this point in the history
…pache#17953)

CREATE TABLE `test` (
`name` varchar(64) NULL,
`age` int(11) NULL
) ENGINE=OLAP
DUPLICATE KEY(`name`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`name`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2",
"disable_auto_compaction" = "false"
);
insert into `test` values ("lemon",1),("tom",2);

select a.name regexp concat('^', a.name) from test a;
  • Loading branch information
HappenLee authored Mar 21, 2023
1 parent a73524a commit 7b93c17
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
23 changes: 13 additions & 10 deletions be/src/vec/functions/like.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ Status FunctionLikeBase::constant_regex_fn_scalar(LikeSearchState* state, const

Status FunctionLikeBase::regexp_fn_scalar(LikeSearchState* state, const StringRef& val,
const StringRef& pattern, unsigned char* result) {
std::string_view re_pattern(pattern.data, pattern.size);
std::string re_pattern(pattern.data, pattern.size);

hs_database_t* database = nullptr;
hs_scratch_t* scratch = nullptr;
RETURN_IF_ERROR(hs_prepare(nullptr, re_pattern.data(), &database, &scratch));
RETURN_IF_ERROR(hs_prepare(nullptr, re_pattern.c_str(), &database, &scratch));

auto ret = hs_scan(database, val.data, val.size, 0, scratch,
doris::vectorized::LikeSearchState::hs_match_handler, (void*)result);
Expand Down Expand Up @@ -246,11 +246,11 @@ Status FunctionLikeBase::constant_regex_fn(LikeSearchState* state, const ColumnS

Status FunctionLikeBase::regexp_fn(LikeSearchState* state, const ColumnString& val,
const StringRef& pattern, ColumnUInt8::Container& result) {
std::string_view re_pattern(pattern.data, pattern.size);
std::string re_pattern(pattern.data, pattern.size);

hs_database_t* database = nullptr;
hs_scratch_t* scratch = nullptr;
RETURN_IF_ERROR(hs_prepare(nullptr, re_pattern.data(), &database, &scratch));
RETURN_IF_ERROR(hs_prepare(nullptr, re_pattern.c_str(), &database, &scratch));

auto sz = val.size();
for (size_t i = 0; i < sz; i++) {
Expand Down Expand Up @@ -293,11 +293,11 @@ Status FunctionLikeBase::regexp_fn_predicate(LikeSearchState* state,
const StringRef& pattern,
ColumnUInt8::Container& result, const uint16_t* sel,
size_t sz) {
std::string_view re_pattern(pattern.data, pattern.size);
std::string re_pattern(pattern.data, pattern.size);

hs_database_t* database = nullptr;
hs_scratch_t* scratch = nullptr;
RETURN_IF_ERROR(hs_prepare(nullptr, re_pattern.data(), &database, &scratch));
RETURN_IF_ERROR(hs_prepare(nullptr, re_pattern.c_str(), &database, &scratch));

auto data_ptr = reinterpret_cast<const StringRef*>(val.get_data().data());
for (size_t i = 0; i < sz; i++) {
Expand Down Expand Up @@ -372,10 +372,13 @@ Status FunctionLikeBase::execute_impl(FunctionContext* context, Block& block,
const auto pattern_col = block.get_by_position(arguments[1]).column;

if (const auto* str_patterns = check_and_get_column<ColumnString>(pattern_col.get())) {
DCHECK_EQ(str_patterns->size(), 1);
const auto& pattern_val = str_patterns->get_data_at(0);
RETURN_IF_ERROR(vector_const(*values, &pattern_val, vec_res, state->function,
&state->search_state));
for (int i = 0; i < input_rows_count; i++) {
const auto pattern_val = str_patterns->get_data_at(i);
const auto value_val = values->get_data_at(i);
(state->scalar_function)(
const_cast<vectorized::LikeSearchState*>(&state->search_state), value_val,
pattern_val, &vec_res[i]);
}
} else if (const auto* const_patterns =
check_and_get_column<ColumnConst>(pattern_col.get())) {
const auto& pattern_val = const_patterns->get_data_at(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ billie eillish
-- !sql --
It's ok

-- !sql --
Emmy eillish
It's ok
It's true
billie eillish

-- !sql --
Emmy eillish
It's ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ suite("test_string_function_regexp") {
"""
qt_sql "SELECT k FROM ${tbName} WHERE k regexp '^billie' ORDER BY k;"
qt_sql "SELECT k FROM ${tbName} WHERE k regexp 'ok\$' ORDER BY k;"
qt_sql "SELECT k FROM ${tbName} WHERE k regexp concat('^', k) order by k;"

qt_sql "SELECT k FROM ${tbName} WHERE k not regexp '^billie' ORDER BY k;"
qt_sql "SELECT k FROM ${tbName} WHERE k not regexp 'ok\$' ORDER BY k;"
Expand Down

0 comments on commit 7b93c17

Please sign in to comment.