vvellanki commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r743385126
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -19,6 +19,7 @@
#include <utf8proc.h>
+#include <list>
Review comment:
Is this include required?
##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,23 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
"gdv_fn_initcap_utf8",
NativeFunction::kNeedsContext |
NativeFunction::kCanReturnErrors),
+ NativeFunction("elt", {}, DataTypeVector{int32(), utf8(), utf8()},
utf8(),
+ kResultNullIfNull, "gdv_fn_elt_int32_utf8_utf8",
+ NativeFunction::kNeedsContext),
+
+ NativeFunction("elt", {}, DataTypeVector{int32(), utf8(), utf8(),
utf8()}, utf8(),
+ kResultNullIfNull, "gdv_fn_elt_int32_utf8_utf8_utf8",
Review comment:
I dont think this can be a NULL_IF_NULL function since the output can be
null if the position is invalid. This would have to be a NullInternal function
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +795,162 @@ 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_elt_int32_utf8_utf8(int64_t context, int32_t pos, const
char* word1,
+ int32_t word1_len, const char* word2,
+ int32_t word2_len, int32_t* out_len) {
+ const char* selected;
+ if (pos < 1 || pos > 2) {
+ *out_len = 0;
+ return "";
+ }
+
+ if (pos == 1) {
+ *out_len = word1_len;
+ selected = word1;
+ }
+
+ if (pos == 2) {
+ *out_len = word2_len;
+ selected = word2;
+ }
+
+ 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 "";
+ }
+ memcpy(out, selected, *out_len);
+ return out;
+}
+
+GANDIVA_EXPORT
+const char* gdv_fn_elt_int32_utf8_utf8_utf8(int64_t context, int32_t pos,
+ const char* word1, int32_t
word1_len,
+ const char* word2, int32_t
word2_len,
+ const char* word3, int32_t
word3_len,
+ int32_t* out_len) {
+ const char* selected;
+ if (pos < 1 || pos > 3) {
+ *out_len = 0;
+ return "";
+ }
+
+ if (pos == 1) {
Review comment:
Same comment - lets use switch case and reduce the number of
if-statements in the code
##########
File path: cpp/src/gandiva/tests/projector_test.cc
##########
@@ -1606,4 +1606,46 @@ TEST_F(TestProjector, TestCastNullableIntYearInterval) {
EXPECT_ARROW_ARRAY_EQUALS(out_int64, outputs.at(1));
}
+TEST_F(TestProjector, TestEltFunction) {
Review comment:
You should add a test here to verify that the validity bit is false when
the pos is out of range.
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +795,162 @@ 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_elt_int32_utf8_utf8(int64_t context, int32_t pos, const
char* word1,
+ int32_t word1_len, const char* word2,
+ int32_t word2_len, int32_t* out_len) {
+ const char* selected;
+ if (pos < 1 || pos > 2) {
+ *out_len = 0;
+ return "";
+ }
+
+ if (pos == 1) {
Review comment:
Please change this to a switch case statement:
switch (pos) {
case 1:
case 2:
default: // handle the case where pos is invalid
}
##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +795,162 @@ 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_elt_int32_utf8_utf8(int64_t context, int32_t pos, const
char* word1,
+ int32_t word1_len, const char* word2,
+ int32_t word2_len, int32_t* out_len) {
+ const char* selected;
+ if (pos < 1 || pos > 2) {
+ *out_len = 0;
+ return "";
Review comment:
This should return null. With this implementation, it will return a
string of length 0. Please check NullInternal functions
--
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]