Skip to content

Commit

Permalink
Return 1 if empty string is given as substring (apache#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE authored and zhztheplayer committed Feb 8, 2022
1 parent 7f40757 commit ca2d251
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cpp/src/gandiva/precompiled/string_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1807,9 +1807,9 @@ gdv_int32 locate_utf8_utf8_int32(gdv_int64 context, const char* sub_str,
gdv_fn_context_set_error_msg(context, "Start position must be greater than 0");
return 0;
}

if (str_len == 0 || sub_str_len == 0) {
return 0;
// TO align with vanilla spark.
if (sub_str_len == 0) {
return 1;
}

gdv_int32 byte_pos = utf8_byte_pos(context, str, str_len, start_pos - 1);
Expand Down
6 changes: 5 additions & 1 deletion cpp/src/gandiva/precompiled/string_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,11 @@ TEST(TestStringOps, TestLocate) {
EXPECT_FALSE(ctx.has_error());

pos = locate_utf8_utf8_int32(ctx_ptr, "", 0, "str", 3, 1);
EXPECT_EQ(pos, 0);
EXPECT_EQ(pos, 1);
EXPECT_FALSE(ctx.has_error());

pos = locate_utf8_utf8_int32(ctx_ptr, "", 0, "", 0, 1);
EXPECT_EQ(pos, 1);
EXPECT_FALSE(ctx.has_error());

pos = locate_utf8_utf8_int32(ctx_ptr, "bar", 3, "barbar", 6, 0);
Expand Down

0 comments on commit ca2d251

Please sign in to comment.