felipecrv commented on code in PR #35345:
URL: https://github.com/apache/arrow/pull/35345#discussion_r1356844873
##########
cpp/src/arrow/array/array_nested.h:
##########
@@ -216,6 +231,172 @@ class ARROW_EXPORT LargeListArray : public
BaseListArray<LargeListType> {
void SetData(const std::shared_ptr<ArrayData>& data);
};
+// ----------------------------------------------------------------------
+// ListViewArray / LargeListViewArray
+
+template <typename TYPE>
+class BaseListViewArray : public VarLengthListLikeArray<TYPE> {
+ public:
+ using TypeClass = TYPE;
+ using offset_type = typename TYPE::offset_type;
+
+ const TypeClass* list_view_type() const { return
this->var_length_list_like_type(); }
+
+ /// Note that this buffer does not account for any slice offset or length.
+ const std::shared_ptr<Buffer>& value_sizes() const { return
this->data_->buffers[2]; }
+
+ /// Return pointer to raw value offsets accounting for any slice offset
+ const offset_type* raw_value_sizes() const {
+ return raw_value_sizes_ + this->data_->offset;
+ }
+
+ offset_type value_length(int64_t i) const final {
+ return this->raw_value_sizes_[i + this->data_->offset];
+ }
+
+ protected:
+ const offset_type* raw_value_sizes_ = NULLPTR;
+};
+
+/// \brief Concrete Array class for list-view data
+class ARROW_EXPORT ListViewArray : public BaseListViewArray<ListViewType> {
+ public:
+ explicit ListViewArray(std::shared_ptr<ArrayData> data);
+
+ ListViewArray(std::shared_ptr<DataType> type, int64_t length,
+ std::shared_ptr<Buffer> value_offsets,
+ std::shared_ptr<Buffer> value_sizes, std::shared_ptr<Array>
values,
+ std::shared_ptr<Buffer> null_bitmap = NULLPTR,
+ int64_t null_count = kUnknownNullCount, int64_t offset = 0);
+
+ /// \brief Construct ListViewArray from array of offsets, sizes, and child
+ /// value array
+ ///
+ /// Construct a ListViewArray using buffers from offsets and sizes arrays
+ /// that project views into the child values array.
+ ///
+ /// This function does the bare minimum of validation of the offsets/sizes
and
+ /// input types.
+ ///
+ /// Offsets of an Array's null bitmap can be present or an explicit
+ /// null_bitmap, but not both.
+ ///
+ /// \param[in] offsets An array of int32 offsets into the values array. NULL
values are
+ /// supported if the corresponding values in sizes is NULL or 0.
+ /// \param[in] sizes An array containing the int32 sizes of every view. NULL
values are
+ /// taken to represent a NULL list-view in the array being created.
+ /// \param[in] values Array containing list values
+ /// \param[in] pool MemoryPool
+ /// \param[in] null_bitmap Optional validity bitmap
+ /// \param[in] null_count Optional null count in null_bitmap
+ static Result<std::shared_ptr<ListViewArray>> FromArrays(
+ const Array& offsets, const Array& sizes, const Array& values,
+ MemoryPool* pool = default_memory_pool(),
+ std::shared_ptr<Buffer> null_bitmap = NULLPTR,
+ int64_t null_count = kUnknownNullCount);
+
+ static Result<std::shared_ptr<ListViewArray>> FromArrays(
+ std::shared_ptr<DataType> type, const Array& offsets, const Array& sizes,
+ const Array& values, MemoryPool* pool = default_memory_pool(),
+ std::shared_ptr<Buffer> null_bitmap = NULLPTR,
+ int64_t null_count = kUnknownNullCount);
+
+ /// \brief Return an Array that is a concatenation of the list-views in this
array.
+ ///
+ /// Note that it's different from `values()` in that it takes into
+ /// consideration this array's offsets (which can be in any order)
+ /// and sizes. Nulls are skipped.
+ Result<std::shared_ptr<Array>> Flatten(
+ MemoryPool* memory_pool = default_memory_pool()) const;
+
+ /// \brief Return list-view offsets as an Int32Array
+ ///
+ /// The returned array will not have a validity bitmap, so you cannot expect
+ /// to pass it to ListArray::FromArrays() and get back the same list array
+ /// if the original one has nulls.
+ std::shared_ptr<Array> offsets() const;
+
+ /// \brief Return list-view sizes as an Int32Array
+ ///
+ /// The returned array will not have a validity bitmap, so you cannot expect
+ /// to pass it to ListArray::FromArrays() and get back the same list array
+ /// if the original one has nulls.
+ std::shared_ptr<Array> sizes() const;
+
+ protected:
+ // This constructor defers SetData to a derived array class
+ ListViewArray() = default;
+
+ void SetData(const std::shared_ptr<ArrayData>& data);
+};
+
+/// \brief Concrete Array class for large list-view data (with 64-bit offsets
+/// and sizes)
+class ARROW_EXPORT LargeListViewArray : public
BaseListViewArray<LargeListViewType> {
+ public:
+ explicit LargeListViewArray(std::shared_ptr<ArrayData> data);
+
+ LargeListViewArray(std::shared_ptr<DataType> type, int64_t length,
+ std::shared_ptr<Buffer> value_offsets,
+ std::shared_ptr<Buffer> value_sizes,
std::shared_ptr<Array> values,
+ std::shared_ptr<Buffer> null_bitmap = NULLPTR,
+ int64_t null_count = kUnknownNullCount, int64_t offset =
0);
+
+ /// \brief Construct LargeListViewArray from array of offsets, sizes, and
child
+ /// value array
+ ///
+ /// Construct an LargeListViewArray using buffers from offsets and sizes
arrays
+ /// that project views into the values array.
+ ///
+ /// This function does the bare minimum of validation of the offsets/sizes
and
+ /// input types. TODO: describe the minimum validation
Review Comment:
I could swear I had removed this.
--
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]