You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/05 14:10:52 UTC

[GitHub] [arrow] ViniciusSouzaRoque commented on a diff in pull request #12391: ARROW-15644: [C++][Gandiva] Implement Find_In_Set Function

ViniciusSouzaRoque commented on code in PR #12391:
URL: https://github.com/apache/arrow/pull/12391#discussion_r913845578


##########
cpp/src/gandiva/precompiled/string_ops.cc:
##########
@@ -3034,4 +3034,53 @@ int32_t instr_utf8(const char* string, int32_t string_len, const char* substring
   }
   return 0;
 }
+
+FORCE_INLINE
+int32_t find_in_set_utf8_utf8(int64_t context, const char* to_find, int32_t to_find_len,
+                              const char* string_list, int32_t string_list_len) {
+  // Return 0 if entry len <= 0
+  if (to_find_len <= 0 || string_list_len <= 0) {
+    gdv_fn_context_set_error_msg(context, "Invalid input values.");
+    return 0;
+  }
+
+  // Return 0 if to search entry have commas
+  if (is_substr_utf8_utf8(to_find, to_find_len, reinterpret_cast<const char*>(","), 1)) {
+    return 0;
+  }
+
+  int32_t cur_pos_in_array = 0;
+  int32_t cur_length = 0;
+  bool matching = true;
+
+  int char_length = 0;
+  for (int i = 0; i < string_list_len; i += char_length) {
+    char_length = utf8_char_length(string_list[i]);

Review Comment:
   @projjal I don't know if this is possible in this case, because using **strtok** it ends up **ignoring the commas**, and we need to count them for the correct result
   e.g.: in this case: **"A,B,,,,,,,C,,,,,"** finding **"C"** the function need **return 9**, but **using split we have 3 as result**.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org