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 2021/09/15 23:37:41 UTC

[GitHub] [arrow] augustoasilva opened a new pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

augustoasilva opened a new pull request #11166:
URL: https://github.com/apache/arrow/pull/11166


   Return string at index number. For example elt(2,'hello','world') returns 'world'. Returns NULL if N is less than 1 or greater than the number of arguments.


-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r742404778



##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
                      "gdv_fn_initcap_utf8",
                      NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
 
+      NativeFunction("elt", {}, DataTypeVector{int32(), utf8()}, utf8(),
+                     kResultNullIfNull, "gdv_fn_elt_utf8",
+                     NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

Review comment:
       It can return an error if it could not alocate the memory for the output and need the context to tag the error with it




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r743569956



##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -19,6 +19,7 @@
 
 #include <utf8proc.h>
 
+#include <list>

Review comment:
       Not anymore, removed it

##########
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:
       Ok, I've looked to see an example of NullInternal, and it makes sense now.

##########
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:
       Sure, fixed.

##########
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:
       Ok, I've changed to switch statement

##########
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:
       Done

##########
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:
       Done




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r743570664



##########
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:
       Ok, I've changed to switch statement




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r742405646



##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +795,54 @@ 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_utf8(int64_t context, int32_t pos, const char* data,

Review comment:
       It was the only way that I've found to simulate a variadic function in Gandiva, but I changed for your approach.




-- 
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



[GitHub] [arrow] ursabot edited a comment on pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#issuecomment-976279589


   Benchmark runs are scheduled for baseline = e417fbf2ec54a13dc3dcc259d2ed9df90f6095d0 and contender = 5f6c92a8f40fb3c26ed35e0e4cb6433e1237ff57. 5f6c92a8f40fb3c26ed35e0e4cb6433e1237ff57 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/bdcae6f53e2044e48637b9583813910c...7d242016d6e7463aa5fbeb456df71437/)
   [Failed :arrow_down:0.0% :arrow_up:0.0%] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/efbc435a1a994446b37c049ec3ee5e7f...e642955f794042de938648feb9403b51/)
   [Finished :arrow_down:0.57% :arrow_up:0.09%] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/cc5e5554def34fd4b7c9117777b7b8cf...a9a260f7059a4e04a7a992e62e068036/)
   Supported benchmarks:
   ursa-i9-9960x: langs = Python, R, JavaScript
   ursa-thinkcentre-m75q: langs = C++, Java
   ec2-t3-xlarge-us-east-2: cloud = True
   


-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r743600815



##########
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:
       Done




-- 
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



[GitHub] [arrow] ursabot commented on pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
ursabot commented on pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#issuecomment-976279589


   Benchmark runs are scheduled for baseline = e417fbf2ec54a13dc3dcc259d2ed9df90f6095d0 and contender = 5f6c92a8f40fb3c26ed35e0e4cb6433e1237ff57. 5f6c92a8f40fb3c26ed35e0e4cb6433e1237ff57 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Scheduled] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/bdcae6f53e2044e48637b9583813910c...7d242016d6e7463aa5fbeb456df71437/)
   [Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/efbc435a1a994446b37c049ec3ee5e7f...e642955f794042de938648feb9403b51/)
   [Scheduled] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/cc5e5554def34fd4b7c9117777b7b8cf...a9a260f7059a4e04a7a992e62e068036/)
   Supported benchmarks:
   ursa-i9-9960x: langs = Python, R, JavaScript
   ursa-thinkcentre-m75q: langs = C++, Java
   ec2-t3-xlarge-us-east-2: cloud = True
   


-- 
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



[GitHub] [arrow] pravindra closed pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
pravindra closed pull request #11166:
URL: https://github.com/apache/arrow/pull/11166


   


-- 
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



[GitHub] [arrow] vvellanki commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

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

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



[GitHub] [arrow] vvellanki commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

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

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



[GitHub] [arrow] vvellanki commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
vvellanki commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r741663325



##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
                      "gdv_fn_initcap_utf8",
                      NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
 
+      NativeFunction("elt", {}, DataTypeVector{int32(), utf8()}, utf8(),
+                     kResultNullIfNull, "gdv_fn_elt_utf8",
+                     NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

Review comment:
       Why does this need the flags kNeedsContext and kCanReturnErrors?

##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +795,54 @@ 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_utf8(int64_t context, int32_t pos, const char* data,

Review comment:
       elt is a function with variable number of arguments - there is no expectation for the arguments to be concatenated using a ',' separator. This code assumes that
   
   Please implement elt(int, string1, string2) - elt that works on 2 string arguments and
   elt(int, string1, string2, string3) and elt(int, string1, string2, string3, string4) and elt(int, string1, string2, string3, string4, string5)
   
   If the query has more arguments, the query needs to be modified




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r742404778



##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
                      "gdv_fn_initcap_utf8",
                      NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
 
+      NativeFunction("elt", {}, DataTypeVector{int32(), utf8()}, utf8(),
+                     kResultNullIfNull, "gdv_fn_elt_utf8",
+                     NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

Review comment:
       It can return an error if it could not alocate the memory for the output

##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
                      "gdv_fn_initcap_utf8",
                      NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
 
+      NativeFunction("elt", {}, DataTypeVector{int32(), utf8()}, utf8(),
+                     kResultNullIfNull, "gdv_fn_elt_utf8",
+                     NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

Review comment:
       It can return an error if it could not alocate the memory for the output and need the context to tag the error with it

##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +795,54 @@ 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_utf8(int64_t context, int32_t pos, const char* data,

Review comment:
       It was the only way that I've found to simulate a variadic function in Gandiva, but I changed for your approach.

##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
                      "gdv_fn_initcap_utf8",
                      NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
 
+      NativeFunction("elt", {}, DataTypeVector{int32(), utf8()}, utf8(),
+                     kResultNullIfNull, "gdv_fn_elt_utf8",
+                     NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

Review comment:
       It can return an error if it could not alocate the memory for the output

##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
                      "gdv_fn_initcap_utf8",
                      NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
 
+      NativeFunction("elt", {}, DataTypeVector{int32(), utf8()}, utf8(),
+                     kResultNullIfNull, "gdv_fn_elt_utf8",
+                     NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

Review comment:
       It can return an error if it could not alocate the memory for the output and need the context to tag the error with it

##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +795,54 @@ 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_utf8(int64_t context, int32_t pos, const char* data,

Review comment:
       It was the only way that I've found to simulate a variadic function in Gandiva, but I changed for your approach.




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r745151213



##########
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) {
+  auto field0 = field("f0", arrow::int32());
+  auto field1 = field("f1", arrow::utf8());
+  auto field2 = field("f2", arrow::utf8());
+
+  auto schema0 = arrow::schema({field0, field1, field2});
+
+  // output fields
+  auto out_field0 = field("out_field0", arrow::utf8());
+
+  // Build expression
+  auto elt_expr0 =
+      TreeExprBuilder::MakeExpression("elt", {field0, field1, field2}, out_field0);
+
+  std::shared_ptr<Projector> projector1;
+
+  auto status = Projector::Make(schema0, {elt_expr0}, TestConfiguration(), &projector1);
+  EXPECT_TRUE(status.ok());
+
+  // Create a row-batch with some sample data
+  int num_records = 5;
+
+  auto array0 = MakeArrowArrayInt32({1, 2, 4, 0, -2}, {true, true, true, true, true});

Review comment:
       yeah, I wrote the first test case. Now I added cases for the fixed pos where the first one grabs the pos 1 with first vector containing the bigger words, and seconde case where pos is 2 and the second vector has the smaller words. Is that what you meant?




-- 
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



[GitHub] [arrow] augustoasilva commented on pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#issuecomment-965005737


   @pravindra I fixed them


-- 
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



[GitHub] [arrow] ursabot edited a comment on pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#issuecomment-976279589


   Benchmark runs are scheduled for baseline = e417fbf2ec54a13dc3dcc259d2ed9df90f6095d0 and contender = 5f6c92a8f40fb3c26ed35e0e4cb6433e1237ff57. 5f6c92a8f40fb3c26ed35e0e4cb6433e1237ff57 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/bdcae6f53e2044e48637b9583813910c...7d242016d6e7463aa5fbeb456df71437/)
   [Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/efbc435a1a994446b37c049ec3ee5e7f...e642955f794042de938648feb9403b51/)
   [Finished :arrow_down:0.57% :arrow_up:0.09%] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/cc5e5554def34fd4b7c9117777b7b8cf...a9a260f7059a4e04a7a992e62e068036/)
   Supported benchmarks:
   ursa-i9-9960x: langs = Python, R, JavaScript
   ursa-thinkcentre-m75q: langs = C++, Java
   ec2-t3-xlarge-us-east-2: cloud = True
   


-- 
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



[GitHub] [arrow] vvellanki commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
vvellanki commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r741663325



##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
                      "gdv_fn_initcap_utf8",
                      NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
 
+      NativeFunction("elt", {}, DataTypeVector{int32(), utf8()}, utf8(),
+                     kResultNullIfNull, "gdv_fn_elt_utf8",
+                     NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

Review comment:
       Why does this need the flags kNeedsContext and kCanReturnErrors?

##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +795,54 @@ 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_utf8(int64_t context, int32_t pos, const char* data,

Review comment:
       elt is a function with variable number of arguments - there is no expectation for the arguments to be concatenated using a ',' separator. This code assumes that
   
   Please implement elt(int, string1, string2) - elt that works on 2 string arguments and
   elt(int, string1, string2, string3) and elt(int, string1, string2, string3, string4) and elt(int, string1, string2, string3, string4, string5)
   
   If the query has more arguments, the query needs to be modified




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r742404778



##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
                      "gdv_fn_initcap_utf8",
                      NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
 
+      NativeFunction("elt", {}, DataTypeVector{int32(), utf8()}, utf8(),
+                     kResultNullIfNull, "gdv_fn_elt_utf8",
+                     NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

Review comment:
       It can return an error if it could not alocate the memory for the output

##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
                      "gdv_fn_initcap_utf8",
                      NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
 
+      NativeFunction("elt", {}, DataTypeVector{int32(), utf8()}, utf8(),
+                     kResultNullIfNull, "gdv_fn_elt_utf8",
+                     NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

Review comment:
       It can return an error if it could not alocate the memory for the output and need the context to tag the error with it

##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +795,54 @@ 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_utf8(int64_t context, int32_t pos, const char* data,

Review comment:
       It was the only way that I've found to simulate a variadic function in Gandiva, but I changed for your approach.




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r743570328



##########
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:
       Ok, I've looked to see an example of NullInternal, and it makes sense now.




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r743570500



##########
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:
       Sure, fixed.




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r743569956



##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -19,6 +19,7 @@
 
 #include <utf8proc.h>
 
+#include <list>

Review comment:
       Not anymore, removed it

##########
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:
       Ok, I've looked to see an example of NullInternal, and it makes sense now.

##########
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:
       Sure, fixed.

##########
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:
       Ok, I've changed to switch statement

##########
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:
       Done

##########
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:
       Done




-- 
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



[GitHub] [arrow] vvellanki commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
vvellanki commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r744618852



##########
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) {
+  auto field0 = field("f0", arrow::int32());
+  auto field1 = field("f1", arrow::utf8());
+  auto field2 = field("f2", arrow::utf8());
+
+  auto schema0 = arrow::schema({field0, field1, field2});
+
+  // output fields
+  auto out_field0 = field("out_field0", arrow::utf8());
+
+  // Build expression
+  auto elt_expr0 =
+      TreeExprBuilder::MakeExpression("elt", {field0, field1, field2}, out_field0);
+
+  std::shared_ptr<Projector> projector1;
+
+  auto status = Projector::Make(schema0, {elt_expr0}, TestConfiguration(), &projector1);
+  EXPECT_TRUE(status.ok());
+
+  // Create a row-batch with some sample data
+  int num_records = 5;
+
+  auto array0 = MakeArrowArrayInt32({1, 2, 4, 0, -2}, {true, true, true, true, true});

Review comment:
       Can you add a test case for the following:
   1) Return the 1 element always
   2) Make the first element have size larger than the 2nd element
   3) Make the first element smaller in size compared to the 2nd element
   
   Add a test where the pos keeps changing such that:
   1) elt returns the input with smallest length in the input strings
   2) elt returns the input with largest length in the input strings
   3) elt returns a random input




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r744759654



##########
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) {
+  auto field0 = field("f0", arrow::int32());
+  auto field1 = field("f1", arrow::utf8());
+  auto field2 = field("f2", arrow::utf8());
+
+  auto schema0 = arrow::schema({field0, field1, field2});
+
+  // output fields
+  auto out_field0 = field("out_field0", arrow::utf8());
+
+  // Build expression
+  auto elt_expr0 =
+      TreeExprBuilder::MakeExpression("elt", {field0, field1, field2}, out_field0);
+
+  std::shared_ptr<Projector> projector1;
+
+  auto status = Projector::Make(schema0, {elt_expr0}, TestConfiguration(), &projector1);
+  EXPECT_TRUE(status.ok());
+
+  // Create a row-batch with some sample data
+  int num_records = 5;
+
+  auto array0 = MakeArrowArrayInt32({1, 2, 4, 0, -2}, {true, true, true, true, true});

Review comment:
       I did not get the cases where the pos keep changing. Changing where? Do you mean a random generated pos value at execution time?




-- 
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



[GitHub] [arrow] vvellanki commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
vvellanki commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r744835348



##########
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) {
+  auto field0 = field("f0", arrow::int32());
+  auto field1 = field("f1", arrow::utf8());
+  auto field2 = field("f2", arrow::utf8());
+
+  auto schema0 = arrow::schema({field0, field1, field2});
+
+  // output fields
+  auto out_field0 = field("out_field0", arrow::utf8());
+
+  // Build expression
+  auto elt_expr0 =
+      TreeExprBuilder::MakeExpression("elt", {field0, field1, field2}, out_field0);
+
+  std::shared_ptr<Projector> projector1;
+
+  auto status = Projector::Make(schema0, {elt_expr0}, TestConfiguration(), &projector1);
+  EXPECT_TRUE(status.ok());
+
+  // Create a row-batch with some sample data
+  int num_records = 5;
+
+  auto array0 = MakeArrowArrayInt32({1, 2, 4, 0, -2}, {true, true, true, true, true});

Review comment:
       You wrote this test - I meant changing the value of pos such that it returns the input of smallest length; input of largest length and a random input string... I believe you wrote this test.
   
   The other test was where pos is a constant (1 for e.g.) and the first vector had the larger inputs than the 2nd vector; and another test where pos is a constant (2 for e.g.) and the 2nd vector had the smaller input




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r742404778



##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
                      "gdv_fn_initcap_utf8",
                      NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
 
+      NativeFunction("elt", {}, DataTypeVector{int32(), utf8()}, utf8(),
+                     kResultNullIfNull, "gdv_fn_elt_utf8",
+                     NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

Review comment:
       It can return an error if it could not alocate the memory for the output




-- 
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



[GitHub] [arrow] vvellanki commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
vvellanki commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r741663325



##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
                      "gdv_fn_initcap_utf8",
                      NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
 
+      NativeFunction("elt", {}, DataTypeVector{int32(), utf8()}, utf8(),
+                     kResultNullIfNull, "gdv_fn_elt_utf8",
+                     NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

Review comment:
       Why does this need the flags kNeedsContext and kCanReturnErrors?

##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +795,54 @@ 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_utf8(int64_t context, int32_t pos, const char* data,

Review comment:
       elt is a function with variable number of arguments - there is no expectation for the arguments to be concatenated using a ',' separator. This code assumes that
   
   Please implement elt(int, string1, string2) - elt that works on 2 string arguments and
   elt(int, string1, string2, string3) and elt(int, string1, string2, string3, string4) and elt(int, string1, string2, string3, string4, string5)
   
   If the query has more arguments, the query needs to be modified




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r744613753



##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +794,169 @@ 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, bool pos_validity,
+                                       const char* word1, int32_t word1_len,
+                                       bool word1_validity, const char* word2,
+                                       int32_t word2_len, bool word2_validity,
+                                       bool* out_valid, int32_t* out_len) {
+  const char* selected;
+  *out_valid = true;
+
+  switch (pos) {
+    case 1:
+      *out_len = word1_len;
+      selected = word1;
+      break;
+    case 2:
+      *out_len = word2_len;
+      selected = word2;
+      break;
+    default:
+      *out_len = 0;
+      *out_valid = false;
+      return nullptr;
+  }
+
+  char* out = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context, *out_len));

Review comment:
       Ok,  changed to remove this mem allocation

##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +794,169 @@ 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, bool pos_validity,
+                                       const char* word1, int32_t word1_len,
+                                       bool word1_validity, const char* word2,
+                                       int32_t word2_len, bool word2_validity,
+                                       bool* out_valid, int32_t* out_len) {
+  const char* selected;
+  *out_valid = true;
+
+  switch (pos) {
+    case 1:
+      *out_len = word1_len;
+      selected = word1;
+      break;
+    case 2:
+      *out_len = word2_len;

Review comment:
       done




-- 
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



[GitHub] [arrow] pravindra commented on pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
pravindra commented on pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#issuecomment-964944321


   @augustoasilva There were some clang-format issues https://github.com/apache/arrow/runs/4162313247?check_suite_focus=true


-- 
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



[GitHub] [arrow] ursabot edited a comment on pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#issuecomment-976279589


   Benchmark runs are scheduled for baseline = e417fbf2ec54a13dc3dcc259d2ed9df90f6095d0 and contender = 5f6c92a8f40fb3c26ed35e0e4cb6433e1237ff57. 5f6c92a8f40fb3c26ed35e0e4cb6433e1237ff57 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/bdcae6f53e2044e48637b9583813910c...7d242016d6e7463aa5fbeb456df71437/)
   [Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/efbc435a1a994446b37c049ec3ee5e7f...e642955f794042de938648feb9403b51/)
   [Scheduled] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/cc5e5554def34fd4b7c9117777b7b8cf...a9a260f7059a4e04a7a992e62e068036/)
   Supported benchmarks:
   ursa-i9-9960x: langs = Python, R, JavaScript
   ursa-thinkcentre-m75q: langs = C++, Java
   ec2-t3-xlarge-us-east-2: cloud = True
   


-- 
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



[GitHub] [arrow] vvellanki commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
vvellanki commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r741663325



##########
File path: cpp/src/gandiva/function_registry_string.cc
##########
@@ -88,6 +88,10 @@ std::vector<NativeFunction> GetStringFunctionRegistry() {
                      "gdv_fn_initcap_utf8",
                      NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),
 
+      NativeFunction("elt", {}, DataTypeVector{int32(), utf8()}, utf8(),
+                     kResultNullIfNull, "gdv_fn_elt_utf8",
+                     NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors),

Review comment:
       Why does this need the flags kNeedsContext and kCanReturnErrors?

##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +795,54 @@ 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_utf8(int64_t context, int32_t pos, const char* data,

Review comment:
       elt is a function with variable number of arguments - there is no expectation for the arguments to be concatenated using a ',' separator. This code assumes that
   
   Please implement elt(int, string1, string2) - elt that works on 2 string arguments and
   elt(int, string1, string2, string3) and elt(int, string1, string2, string3, string4) and elt(int, string1, string2, string3, string4, string5)
   
   If the query has more arguments, the query needs to be modified




-- 
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



[GitHub] [arrow] vvellanki commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
vvellanki commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r744573250



##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +794,169 @@ 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, bool pos_validity,
+                                       const char* word1, int32_t word1_len,
+                                       bool word1_validity, const char* word2,
+                                       int32_t word2_len, bool word2_validity,
+                                       bool* out_valid, int32_t* out_len) {
+  const char* selected;
+  *out_valid = true;
+
+  switch (pos) {
+    case 1:
+      *out_len = word1_len;
+      selected = word1;
+      break;
+    case 2:
+      *out_len = word2_len;

Review comment:
       *out_len = word2_len;
   return word2;

##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +794,169 @@ 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, bool pos_validity,
+                                       const char* word1, int32_t word1_len,
+                                       bool word1_validity, const char* word2,
+                                       int32_t word2_len, bool word2_validity,
+                                       bool* out_valid, int32_t* out_len) {
+  const char* selected;
+  *out_valid = true;
+
+  switch (pos) {
+    case 1:
+      *out_len = word1_len;
+      selected = word1;
+      break;
+    case 2:
+      *out_len = word2_len;
+      selected = word2;
+      break;
+    default:
+      *out_len = 0;
+      *out_valid = false;
+      return nullptr;
+  }
+
+  char* out = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context, *out_len));

Review comment:
       You do not have to allocate memory here

##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -794,6 +794,169 @@ 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, bool pos_validity,
+                                       const char* word1, int32_t word1_len,
+                                       bool word1_validity, const char* word2,
+                                       int32_t word2_len, bool word2_validity,
+                                       bool* out_valid, int32_t* out_len) {
+  const char* selected;
+  *out_valid = true;
+
+  switch (pos) {
+    case 1:
+      *out_len = word1_len;

Review comment:
       *out_len = word1_len;
   return word1;




-- 
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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r743570760



##########
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:
       Done




-- 
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



[GitHub] [arrow] vvellanki commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

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

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



[GitHub] [arrow] augustoasilva commented on a change in pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
augustoasilva commented on a change in pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#discussion_r743569956



##########
File path: cpp/src/gandiva/gdv_function_stubs.cc
##########
@@ -19,6 +19,7 @@
 
 #include <utf8proc.h>
 
+#include <list>

Review comment:
       Not anymore, removed it




-- 
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



[GitHub] [arrow] github-actions[bot] commented on pull request #11166: ARROW-14011: [C++][Gandiva] Add elt hive function to gandiva

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #11166:
URL: https://github.com/apache/arrow/pull/11166#issuecomment-920462894






-- 
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