lidavidm commented on a change in pull request #11159:
URL: https://github.com/apache/arrow/pull/11159#discussion_r709255776
##########
File path: cpp/src/arrow/compute/kernels/vector_nested.cc
##########
@@ -157,6 +157,43 @@ class ListParentIndicesFunction : public MetaFunction {
}
};
+const FunctionDoc list_element_doc(
+ "Compute elements using of nested list values using an index",
+ ("`lists` must have a list-like type.\n"
+ "For each value in each list of `lists`, the element at `index`\n"
+ "is emitted."),
+ {"lists", "index"});
+
+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;
+ ScalarVector scalars;
+ for (int i = 0; i < list_array.length(); ++i) {
+ if (list_array.IsNull(i)) {
+ scalars.push_back(MakeNullScalar(list_array.value_type()));
+ continue;
+ }
+ std::shared_ptr<arrow::Array> value_array = list_array.value_slice(i);
+ auto len = value_array->length();
+ if (ARROW_PREDICT_FALSE(index < 0 || index > len)) {
+ return Status::Invalid("Index ", index, " is out of bounds: should be in
[0, ", len,
Review comment:
As Eduardo says, we should always return the same number of elements in
the output as in the input (that keeps this as a scalar function) - but that
said, we could offer different interpretations for top-level nulls: either
return an error or return null; also here, if an index is out of bounds for a
particular list, we could also return an error or return null. That said, I
don't think any of these behaviors are useful enough to implement right this
moment.
--
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]