[Bug] Fix the core problem of function split_part and add the UT of core case (#4721)

issue:#4720
This commit is contained in:
HappenLee
2020-10-13 10:09:39 +08:00
committed by GitHub
parent f431d8d94c
commit c00a5cb543
2 changed files with 5 additions and 1 deletions

View File

@ -984,7 +984,7 @@ StringVal StringFunctions::split_part(FunctionContext* context, const StringVal&
for (int i = 1; i <= field.val; i++) { // find
int last_index = i - 1;
find[last_index] = index_of(content.ptr, 0, content.len, delimiter.ptr, 0, delimiter.len, from);
from = find[last_index] + 1;
from = find[last_index] + delimiter.len;
if (find[last_index] == -1) {
break;
}

View File

@ -178,6 +178,10 @@ TEST_F(StringFunctionsTest, split_part) {
ASSERT_EQ(AnyValUtil::from_string_temp(context, std::string("")),
StringFunctions::split_part(context, StringVal("abcdabda"), StringVal("a"), 4));
ASSERT_EQ(AnyValUtil::from_string_temp(context, std::string("#123")),
StringFunctions::split_part(context, StringVal("abc###123###234"), StringVal("##"), 2));
delete context;
}