vvellanki commented on a change in pull request #11180:
URL: https://github.com/apache/arrow/pull/11180#discussion_r743387907
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +794,56 @@ const char* gdv_fn_initcap_utf8(int64_t context, const
char* data, int32_t data_
*out_len = out_idx;
return out;
}
+
+GANDIVA_EXPORT
+const char* gdv_fn_concat_ws_utf8(int64_t context, const char* separator,
Review comment:
yes, that's what you should do
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +794,132 @@ const char* gdv_fn_initcap_utf8(int64_t context, const
char* data, int32_t data_
*out_len = out_idx;
return out;
}
+
+GANDIVA_EXPORT
+const char* gdv_fn_concat_ws_utf8_utf8(int64_t context, const char* separator,
+ int32_t separator_len, const char*
word1,
+ int32_t word1_len, const char* word2,
+ int32_t word2_len, int32_t* out_len) {
+ if (word1_len <= 0 && word2_len <= 0) {
+ gdv_fn_context_set_error_msg(context, "All words can not be null.");
+ *out_len = 0;
+ return "";
+ }
+
+ *out_len = word1_len + separator_len + word2_len;
+ char* out = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context,
*out_len));
+ if (out == nullptr) {
+ gdv_fn_context_set_error_msg(context, "Could not allocate memory for
output string");
+ *out_len = 0;
+ return "";
+ }
+
+ strncpy(out, word1, word1_len);
Review comment:
The input can include \0. You cannot use strncpy. Please use memcpy
instead
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +794,132 @@ const char* gdv_fn_initcap_utf8(int64_t context, const
char* data, int32_t data_
*out_len = out_idx;
return out;
}
+
+GANDIVA_EXPORT
+const char* gdv_fn_concat_ws_utf8_utf8(int64_t context, const char* separator,
+ int32_t separator_len, const char*
word1,
+ int32_t word1_len, const char* word2,
+ int32_t word2_len, int32_t* out_len) {
+ if (word1_len <= 0 && word2_len <= 0) {
Review comment:
Arrow has validity bits and data values - if a value is null, the
validity bit will be false
0 length strings are valid inputs... none of the inputs can have negative
lengths. You should check for that
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +794,132 @@ const char* gdv_fn_initcap_utf8(int64_t context, const
char* data, int32_t data_
*out_len = out_idx;
return out;
}
+
+GANDIVA_EXPORT
+const char* gdv_fn_concat_ws_utf8_utf8(int64_t context, const char* separator,
+ int32_t separator_len, const char*
word1,
+ int32_t word1_len, const char* word2,
+ int32_t word2_len, int32_t* out_len) {
+ if (word1_len <= 0 && word2_len <= 0) {
+ gdv_fn_context_set_error_msg(context, "All words can not be null.");
+ *out_len = 0;
+ return "";
+ }
+
+ *out_len = word1_len + separator_len + word2_len;
+ char* out = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context,
*out_len));
+ if (out == nullptr) {
+ gdv_fn_context_set_error_msg(context, "Could not allocate memory for
output string");
+ *out_len = 0;
+ return "";
+ }
+
+ strncpy(out, word1, word1_len);
+ out[word1_len] = '\0';
+ strncat(out, separator, separator_len);
+ strncat(out, word2, word2_len);
Review comment:
Same here
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +794,132 @@ const char* gdv_fn_initcap_utf8(int64_t context, const
char* data, int32_t data_
*out_len = out_idx;
return out;
}
+
+GANDIVA_EXPORT
+const char* gdv_fn_concat_ws_utf8_utf8(int64_t context, const char* separator,
+ int32_t separator_len, const char*
word1,
+ int32_t word1_len, const char* word2,
+ int32_t word2_len, int32_t* out_len) {
+ if (word1_len <= 0 && word2_len <= 0) {
+ gdv_fn_context_set_error_msg(context, "All words can not be null.");
+ *out_len = 0;
+ return "";
+ }
+
+ *out_len = word1_len + separator_len + word2_len;
+ char* out = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context,
*out_len));
+ if (out == nullptr) {
+ gdv_fn_context_set_error_msg(context, "Could not allocate memory for
output string");
+ *out_len = 0;
+ return "";
+ }
+
+ strncpy(out, word1, word1_len);
+ out[word1_len] = '\0';
Review comment:
This is not required. There is no need to add a '\0'
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +794,132 @@ const char* gdv_fn_initcap_utf8(int64_t context, const
char* data, int32_t data_
*out_len = out_idx;
return out;
}
+
+GANDIVA_EXPORT
+const char* gdv_fn_concat_ws_utf8_utf8(int64_t context, const char* separator,
+ int32_t separator_len, const char*
word1,
+ int32_t word1_len, const char* word2,
+ int32_t word2_len, int32_t* out_len) {
+ if (word1_len <= 0 && word2_len <= 0) {
+ gdv_fn_context_set_error_msg(context, "All words can not be null.");
+ *out_len = 0;
+ return "";
+ }
+
+ *out_len = word1_len + separator_len + word2_len;
+ char* out = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context,
*out_len));
+ if (out == nullptr) {
+ gdv_fn_context_set_error_msg(context, "Could not allocate memory for
output string");
+ *out_len = 0;
+ return "";
+ }
+
+ strncpy(out, word1, word1_len);
+ out[word1_len] = '\0';
+ strncat(out, separator, separator_len);
Review comment:
This will not work. It has to be memcpy(out + word1_len, separator,
separator_len);
--
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]