edponce commented on a change in pull request #11159:
URL: https://github.com/apache/arrow/pull/11159#discussion_r709744676
##########
File path: cpp/src/arrow/compute/kernels/test_util.cc
##########
@@ -190,6 +190,13 @@ void CheckVectorUnary(std::string func_name, Datum input,
Datum expected,
AssertDatumsEqual(expected, actual, /*verbose=*/true);
}
+void CheckVectorBinary(std::string func_name, Datum v1, Datum v2, Datum
expected,
+ const FunctionOptions* options) {
Review comment:
To reduce duplicate code, I suggest to make use of
`CheckScalarNonRecursive` for the `CheckVectorXXX` functions.
```c++
void CheckVectorUnary(std::string func_name, Datum input, Datum expected,
const FunctionOptions* options) {
CheckScalarNonRecursive(func_name, {input}, expected, options);
}
void CheckVectorBinary(std::string func_name, Datum v1, Datum v2, Datum
expected,
const FunctionOptions* options) {
CheckScalarNonRecursive(func_name, {v1, v2}, expected, options);
}
```
##########
File path: cpp/src/arrow/compute/kernels/scalar_nested_test.cc
##########
@@ -39,6 +39,46 @@ TEST(TestScalarNested, ListValueLength) {
}
}
+TEST(TestScalarNested, ListElement) {
+ for (auto ty : {list(int16()), fixed_size_list(uint8(), 2)}) {
+ auto input = ArrayFromJSON(ty, "[[8, 5], [74, 92], [7, 4]]");
+ auto out_ty = ty->id() == Type::LIST ? int16() : uint8();
+ auto expected = ArrayFromJSON(out_ty, "[5, 92, 4]");
Review comment:
Add invalid tests:
* Index out-of-range
* Arrays of different lengths
##########
File path: docs/source/cpp/compute.rst
##########
@@ -1474,13 +1474,15 @@ value, but smaller than nulls.
Structural transforms
~~~~~~~~~~~~~~~~~~~~~
-+--------------------------+------------+--------------------+---------------------+---------+
-| Function name | Arity | Input types | Output type
| Notes |
-+==========================+============+====================+=====================+=========+
-| list_flatten | Unary | List-like | List value type
| \(1) |
-+--------------------------+------------+--------------------+---------------------+---------+
-| list_parent_indices | Unary | List-like | Int32 or Int64
| \(2) |
-+--------------------------+------------+--------------------+---------------------+---------+
++--------------------------+------------+--------------------------+---------------------+---------+
+| Function name | Arity | Input types | Output
type | Notes |
++==========================+============+==========================+=====================+=========+
+| list_flatten | Unary | List-like | List
value type | \(1) |
++--------------------------+------------+--------------------------+---------------------+---------+
+| list_parent_indices | Unary | List-like | Int32 or
Int64 | \(2) |
++--------------------------+------------+--------------------------+---------------------+---------+
+| list_element | Binary | List-like, Int32 or Int64| List
value type | \(3) |
Review comment:
For _Input types_ instead of using a comma, you can use this form:
`List-like (Arg 0); Integral (Arg 1)`.
Refer to _case_when_ doc.
##########
File path: cpp/src/arrow/compute/kernels/scalar_nested.cc
##########
@@ -165,6 +216,16 @@ void RegisterScalarNested(FunctionRegistry* registry) {
ListValueLength<LargeListType>));
DCHECK_OK(registry->AddFunction(std::move(list_value_length)));
+ auto list_element = std::make_shared<ScalarFunction>("list_element",
Arity::Binary(),
+ &list_element_doc);
+ AddListElement<ListType, Int32Type>(list_element.get());
+ AddListElement<ListType, Int64Type>(list_element.get());
Review comment:
Why index is not any integral type?
--
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]