edponce commented on a change in pull request #11159:
URL: https://github.com/apache/arrow/pull/11159#discussion_r709831886



##########
File path: cpp/src/arrow/compute/kernels/scalar_nested.cc
##########
@@ -62,6 +62,57 @@ const FunctionDoc list_value_length_doc{
      "Null values emit a null in the output."),
     {"lists"}};
 
+template <typename Type, typename IndexType>
+Status ListElement(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+  using ListArrayType = typename TypeTraits<Type>::ArrayType;
+  using IndexScalarType = typename TypeTraits<IndexType>::ScalarType;
+  ListArrayType list_array(batch[0].array());
+  const auto& index_scalar = batch[1].scalar_as<IndexScalarType>();
+  auto index = index_scalar.value;
+  if (ARROW_PREDICT_FALSE(index < 0)) {
+    return Status::Invalid("Index ", index,
+                           " is out of bounds: should be greater than or equal 
to 0");
+  }
+  std::unique_ptr<ArrayBuilder> builder;
+  RETURN_NOT_OK(MakeBuilder(ctx->memory_pool(), list_array.value_type(), 
&builder));

Review comment:
       You can preallocate the output buffer: 
`builder->Reserve(list_array.length());`




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


Reply via email to