felipecrv commented on code in PR #35345:
URL: https://github.com/apache/arrow/pull/35345#discussion_r1317962587
##########
cpp/src/arrow/array/array_nested.cc:
##########
@@ -137,6 +137,78 @@ Result<std::shared_ptr<typename
TypeTraits<TYPE>::ArrayType>> ListArrayFromArray
return std::make_shared<ArrayType>(std::move(data));
}
+template <typename TYPE>
+Result<std::shared_ptr<typename TypeTraits<TYPE>::ArrayType>>
ListViewArrayFromArrays(
+ std::shared_ptr<DataType> type, const Array& offsets, const Array& sizes,
+ const Array& values, MemoryPool* pool, std::shared_ptr<Buffer> null_bitmap
= NULLPTR,
+ int64_t null_count = kUnknownNullCount) {
+ using offset_type = typename TYPE::offset_type;
+ using ArrayType = typename TypeTraits<TYPE>::ArrayType;
+ using OffsetArrowType = typename CTypeTraits<offset_type>::ArrowType;
+
+ if (offsets.type_id() != OffsetArrowType::type_id) {
+ return Status::TypeError("List offsets must be ",
OffsetArrowType::type_name());
+ }
+
+ if (sizes.length() != offsets.length() && sizes.length() != offsets.length()
- 1) {
+ return Status::Invalid(
+ "List sizes must have the same length as offsets or one less than
offsets");
+ }
+ if (sizes.type_id() != OffsetArrowType::type_id) {
+ return Status::TypeError("List sizes must be ",
OffsetArrowType::type_name());
+ }
+
+ if (offsets.offset() != sizes.offset()) {
+ return Status::Invalid("List offsets and sizes must have the same offset");
+ }
+ const int64_t offset = sizes.offset();
+
+ if (null_bitmap) {
+ if (offsets.null_count() > 0 || sizes.null_count() > 0) {
+ return Status::Invalid(
+ "Ambiguous to specify both validity map and offsets or sizes with
nulls");
+ }
+ if (offset != 0) {
+ return Status::Invalid(
+ "List offsets and sizes must not be slices if a validity map is
specified");
+ }
+ } else {
+ if (offsets.null_count() > 0 && sizes.null_count() > 0) {
+ return Status::Invalid("Ambiguous to specify both offsets and sizes with
nulls");
+ }
+ }
+
+ DCHECK(offsets.length() == sizes.length() || offsets.length() - 1 ==
sizes.length());
+
+ using OffsetArrayType = typename TypeTraits<OffsetArrowType>::ArrayType;
+ const auto& typed_offsets = checked_cast<const OffsetArrayType&>(offsets);
+ const auto& typed_sizes = checked_cast<const OffsetArrayType&>(sizes);
+
+ auto derived_validity_buffer = std::move(null_bitmap);
+ int64_t null_count_ = null_count;
+ if (offsets.null_count() > 0) {
+ derived_validity_buffer = offsets.null_bitmap();
+ null_count_ = offsets.null_count();
+ // We allow construction from an offsets array containing one extra value.
+ // If that is the case, we might need to discount one null from
out_null_count.
+ if (offsets.length() - 1 == sizes.length() &&
!offsets.IsValid(sizes.length())) {
+ null_count_ -= 1;
Review Comment:
An initial version of this code compared against `null_count` in the end. I
will remove the extra variable now.
--
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]