Skip to content

Commit

Permalink
[Fix](sql function)Fix split_part function behavior apache#36231
Browse files Browse the repository at this point in the history
  • Loading branch information
morningman committed Jun 13, 2024
1 parent e392cae commit 7de0107
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions be/src/vec/functions/function_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,11 @@ class FunctionSplitPart : public IFunction {
reinterpret_cast<const char*>(str.data + pre_offset + 1),
(size_t)offset - pre_offset - 1},
i, res_chars, res_offsets);
} else if (num == 0) {
StringOP::push_value_string(
std::string_view {reinterpret_cast<const char*>(str.data),
str.size},
i, res_chars, res_offsets);
} else {
StringOP::push_null_string(i, res_chars, res_offsets, null_map_data);
}
Expand Down Expand Up @@ -1881,6 +1886,11 @@ class FunctionSplitPart : public IFunction {
str.data + pre_offset + delimiter.size),
(size_t)offset - pre_offset - delimiter.size},
i, res_chars, res_offsets);
} else if (num == 0) {
StringOP::push_value_string(
std::string_view {reinterpret_cast<const char*>(str.data),
str.size},
i, res_chars, res_offsets);
} else {
StringOP::push_null_string(i, res_chars, res_offsets, null_map_data);
}
Expand Down Expand Up @@ -1920,6 +1930,10 @@ class FunctionSplitPart : public IFunction {
(size_t)pre_offset - offset - delimiter.size)},
i, res_chars, res_offsets);
}
} else if (num == 0) {
StringOP::push_value_string(
std::string_view {reinterpret_cast<const char*>(str.data), str.size}, i,
res_chars, res_offsets);
} else {
StringOP::push_null_string(i, res_chars, res_offsets, null_map_data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ suite("test_string_function", "arrow_flight_sql") {
qt_sql "select split_part('abc##123###xyz', '##', -1)"
qt_sql "select split_part('abc##123###xyz', '##', -2)"
qt_sql "select split_part('abc##123###xyz', '##', -4)"
qt_sql "select split_part('abc', '|', 1)"
qt_sql "select split_part('abc', '||', 1)"
qt_sql "select split_part('abc', '|', -1)"
qt_sql "select split_part('abc', '||', -1)"

qt_sql "select starts_with(\"hello world\",\"hello\");"
qt_sql "select starts_with(\"hello world\",\"world\");"
Expand Down

0 comments on commit 7de0107

Please sign in to comment.