felipecrv commented on code in PR #42117:
URL: https://github.com/apache/arrow/pull/42117#discussion_r1657131888


##########
cpp/src/arrow/compute/kernels/vector_selection_internal.cc:
##########
@@ -612,6 +612,59 @@ struct ListSelectionImpl : public 
Selection<ListSelectionImpl<Type>, Type> {
   }
 };
 
+template <typename Type>
+struct ListViewSelectionImpl : public Selection<ListViewSelectionImpl<Type>, 
Type> {
+  using offset_type = typename Type::offset_type;
+
+  using Base = Selection<ListViewSelectionImpl<Type>, Type>;
+  LIFT_BASE_MEMBERS();
+
+  TypedBufferBuilder<offset_type> offsets_builder;
+  TypedBufferBuilder<offset_type> sizes_builder;
+
+  ListViewSelectionImpl(KernelContext* ctx, const ExecSpan& batch, int64_t 
output_length,
+                        ExecResult* out)
+      : Base(ctx, batch, output_length, out),
+        offsets_builder(ctx->memory_pool()),
+        sizes_builder(ctx->memory_pool()) {}
+
+  template <typename Adapter>
+  Status GenerateOutput() {
+    auto* offsets = this->values.template GetValues<offset_type>(1);
+    auto* sizes = this->values.template GetValues<offset_type>(2);
+
+    offset_type null_list_view_offset = 0;
+    Adapter adapter(this);
+    RETURN_NOT_OK(adapter.Generate(
+        [&](int64_t index) {
+          offset_type value_offset = offsets[index];
+          offset_type value_length = sizes[index];
+          offsets_builder.UnsafeAppend(value_offset);
+          sizes_builder.UnsafeAppend(value_length);
+          null_list_view_offset = value_offset + value_length;
+          return Status::OK();
+        },
+        [&]() {
+          offsets_builder.UnsafeAppend(null_list_view_offset);

Review Comment:
   To keep the offsets of list-view sorted just like they are in regular lists. 
It makes casting to regular lists much easier.
   
   Remember the invariants we discussed during the specification of list-views? 
We need `offset[i] + sizes[i]` to be `<= values.length`, so by having `sizes[i] 
== 0` I can have `offsets` that behave just like normal list offsets.



##########
cpp/src/arrow/compute/kernels/vector_selection_internal.cc:
##########
@@ -612,6 +612,59 @@ struct ListSelectionImpl : public 
Selection<ListSelectionImpl<Type>, Type> {
   }
 };
 
+template <typename Type>
+struct ListViewSelectionImpl : public Selection<ListViewSelectionImpl<Type>, 
Type> {
+  using offset_type = typename Type::offset_type;
+
+  using Base = Selection<ListViewSelectionImpl<Type>, Type>;
+  LIFT_BASE_MEMBERS();
+
+  TypedBufferBuilder<offset_type> offsets_builder;
+  TypedBufferBuilder<offset_type> sizes_builder;
+
+  ListViewSelectionImpl(KernelContext* ctx, const ExecSpan& batch, int64_t 
output_length,
+                        ExecResult* out)
+      : Base(ctx, batch, output_length, out),
+        offsets_builder(ctx->memory_pool()),
+        sizes_builder(ctx->memory_pool()) {}
+
+  template <typename Adapter>
+  Status GenerateOutput() {
+    auto* offsets = this->values.template GetValues<offset_type>(1);
+    auto* sizes = this->values.template GetValues<offset_type>(2);
+
+    offset_type null_list_view_offset = 0;
+    Adapter adapter(this);
+    RETURN_NOT_OK(adapter.Generate(
+        [&](int64_t index) {
+          offset_type value_offset = offsets[index];
+          offset_type value_length = sizes[index];
+          offsets_builder.UnsafeAppend(value_offset);
+          sizes_builder.UnsafeAppend(value_length);
+          null_list_view_offset = value_offset + value_length;
+          return Status::OK();
+        },
+        [&]() {
+          offsets_builder.UnsafeAppend(null_list_view_offset);

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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to