pitrou commented on code in PR #50534:
URL: https://github.com/apache/arrow/pull/50534#discussion_r3673127392


##########
cpp/src/arrow/compute/kernels/vector_run_end_encode.cc:
##########
@@ -470,6 +536,56 @@ struct RunEndDecodeExec {
     return Status::Invalid("Invalid run end type: ", 
*ree_type->run_end_type());
   }
 
+  template <typename RunEndType>
+  static Status DoExecNested(KernelContext* ctx, const ArraySpan& input_array,
+                             ExecResult* result) {
+    using RunEndCType = typename RunEndType::c_type;
+    const auto& input_values = arrow::ree_util::ValuesArray(input_array);
+
+    ARROW_ASSIGN_OR_RAISE(
+        auto output_builder,
+        MakeBuilderExactIndex(input_values.type->GetSharedPtr(), 
ctx->memory_pool()));
+    RETURN_NOT_OK(output_builder->Reserve(input_array.length));
+
+    const arrow::ree_util::RunEndEncodedArraySpan<RunEndCType> ree_array_span(
+        input_array);
+    if (input_array.length > 0) {
+      for (auto it = ree_array_span.begin(); !it.is_end(ree_array_span); ++it) 
{
+        const int64_t physical_index = it.index_into_array();
+        const int64_t run_length = it.run_length();
+        if (input_values.IsNull(physical_index)) {
+          RETURN_NOT_OK(output_builder->AppendNulls(run_length));
+          continue;
+        }
+        for (int64_t i = 0; i < run_length; ++i) {
+          RETURN_NOT_OK(
+              output_builder->AppendArraySlice(input_values, physical_index, 
1));
+        }

Review Comment:
   I wonder if it would be more performant to implement this as:
   ```suggestion
           ARROW_ASSIGN_OR_RAISE(
               auto scalar, input_values.GetScalar(physical_index));
           RETURN_NOT_OK(output_builder->AppendScalar(scalar, run_length));
   ```
   
   `GetScalar` adds its own cost, but it's amortized over the entire run.
   
   @felipecrv What do you think?



##########
python/pyarrow/tests/test_table.py:
##########
@@ -2535,6 +2535,76 @@ def test_table_from_pylist(cls):
     assert table.to_pylist() == data2
 
 
[email protected](
+    ("value_type", "values", "encoded_values"),
+    [
+        (
+            pa.struct([pa.field("age", pa.int32())]),
+            [{"age": 20}, {"age": 20}, {"age": 21}],
+            [{"age": 20}, {"age": 21}],
+        ),
+        (
+            pa.list_(pa.int32()),
+            [[20], [20], [21, 22]],
+            [[20], [21, 22]],
+        ),
+        (
+            pa.large_list(pa.int32()),
+            [[20], [20], [21, 22]],
+            [[20], [21, 22]],
+        ),
+        (
+            pa.list_view(pa.int32()),
+            [[20], [20], [21, 22]],
+            [[20], [21, 22]],
+        ),
+        (
+            pa.large_list_view(pa.int32()),
+            [[20], [20], [21, 22]],
+            [[20], [21, 22]],
+        ),
+        (
+            pa.list_(pa.int32(), 2),
+            [[20, 21], [20, 21], [22, 23]],
+            [[20, 21], [22, 23]],
+        ),
+        (
+            pa.list_(pa.list_(pa.int32())),
+            [[[20], [21]], [[20], [21]], [[22]]],
+            [[[20], [21]], [[22]]],
+        ),
+        (
+            pa.map_(pa.string(), pa.int32(), keys_sorted=True),
+            [{"a": 20}, {"a": 20}, {"b": 21}],
+            [{"a": 20}, {"b": 21}],
+        ),
+    ],
+)
+def test_table_from_pylist_run_end_encoded_nested(

Review Comment:
   Is this testing anything more than is tested on the C++ side? Otherwise this 
test may not be needed at all.



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