Skip to content

Commit c2a693c

Browse files
philo-hezhouyuan
authored andcommitted
Return 1 if empty string is given as substring (apache#69)
1 parent 28fbddf commit c2a693c

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

cpp/src/gandiva/precompiled/string_ops.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,9 +1327,9 @@ gdv_int32 locate_utf8_utf8_int32(gdv_int64 context, const char* sub_str,
13271327
gdv_fn_context_set_error_msg(context, "Start position must be greater than 0");
13281328
return 0;
13291329
}
1330-
1331-
if (str_len == 0 || sub_str_len == 0) {
1332-
return 0;
1330+
// TO align with vanilla spark.
1331+
if (sub_str_len == 0) {
1332+
return 1;
13331333
}
13341334

13351335
gdv_int32 byte_pos = utf8_byte_pos(context, str, str_len, start_pos - 1);

cpp/src/gandiva/precompiled/string_ops_test.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,11 @@ TEST(TestStringOps, TestLocate) {
921921
EXPECT_FALSE(ctx.has_error());
922922

923923
pos = locate_utf8_utf8_int32(ctx_ptr, "", 0, "str", 3, 1);
924-
EXPECT_EQ(pos, 0);
924+
EXPECT_EQ(pos, 1);
925+
EXPECT_FALSE(ctx.has_error());
926+
927+
pos = locate_utf8_utf8_int32(ctx_ptr, "", 0, "", 0, 1);
928+
EXPECT_EQ(pos, 1);
925929
EXPECT_FALSE(ctx.has_error());
926930

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

0 commit comments

Comments
 (0)