vvellanki commented on a change in pull request #11287:
URL: https://github.com/apache/arrow/pull/11287#discussion_r747198908
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +795,25 @@ const char* gdv_fn_initcap_utf8(int64_t context, const
char* data, int32_t data_
*out_len = out_idx;
return out;
}
+
+GANDIVA_EXPORT
+int32_t gdv_fn_instr_utf8(const char* string, int32_t string_len, const char*
substring,
+ int32_t substring_len) {
+ if (substring_len == 0) {
+ return 1;
+ }
+
+ if (string_len < substring_len) {
Review comment:
What happens if string_len == substring_len? Looks like we return 0
always - the for loop goes from 0 to 0
Can you fix this case?
Also, can this function be moved to precompiled and use FORCE_INLINE?
##########
File path: cpp/src/gandiva/gdv_function_stubs_test.cc
##########
@@ -766,4 +766,62 @@ TEST(TestGdvFnStubs, TestCastVarbinaryFloat8) {
ctx.Reset();
}
+TEST(TestGdvFnStubs, TestInstr) {
+ std::string s1 = "hello world!";
+ auto s1_len = static_cast<int32_t>(s1.size());
+ std::string s2 = "world";
+ auto s2_len = static_cast<int32_t>(s2.size());
+
+ auto result = gdv_fn_instr_utf8(s1.c_str(), s1_len, s2.c_str(), s2_len);
+ EXPECT_EQ(result, 7);
+
+ s1 = "apple banana mango";
Review comment:
Please add a test where string = "Hello" and substring = "Hello".
Another where string = "Hello", substring = "Hell"
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]