MCPcopy Create free account
hub / github.com/apache/arrow / ListViewArrayFromArrays

Function ListViewArrayFromArrays

cpp/src/arrow/array/array_nested.cc:147–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145
146template <typename TYPE>
147Result<std::shared_ptr<typename TypeTraits<TYPE>::ArrayType>> ListViewArrayFromArrays(
148 std::shared_ptr<DataType> type, const Array& offsets, const Array& sizes,
149 const Array& values, MemoryPool* pool, std::shared_ptr<Buffer> null_bitmap = NULLPTR,
150 int64_t null_count = kUnknownNullCount) {
151 using offset_type = typename TYPE::offset_type;
152 using ArrayType = typename TypeTraits<TYPE>::ArrayType;
153 using OffsetArrowType = typename CTypeTraits<offset_type>::ArrowType;
154
155 if (offsets.type_id() != OffsetArrowType::type_id) {
156 return Status::TypeError("List offsets must be ", OffsetArrowType::type_name());
157 }
158
159 if (sizes.length() != offsets.length() && sizes.length() != offsets.length() - 1) {
160 return Status::Invalid(
161 "List sizes must have the same length as offsets or one less than offsets");
162 }
163 if (sizes.type_id() != OffsetArrowType::type_id) {
164 return Status::TypeError("List sizes must be ", OffsetArrowType::type_name());
165 }
166
167 if (offsets.offset() != sizes.offset()) {
168 return Status::Invalid("List offsets and sizes must have the same offset");
169 }
170 const int64_t array_offset = sizes.offset();
171
172 if (null_bitmap) {
173 if (offsets.null_count() > 0 || sizes.null_count() > 0) {
174 return Status::Invalid(
175 "Ambiguous to specify both validity map and offsets or sizes with nulls");
176 }
177 if (array_offset != 0) {
178 return Status::Invalid(
179 "List offsets and sizes must not be slices if a validity map is specified");
180 }
181 } else {
182 if (offsets.null_count() > 0 && sizes.null_count() > 0) {
183 return Status::Invalid("Ambiguous to specify both offsets and sizes with nulls");
184 }
185 }
186
187 DCHECK(offsets.length() == sizes.length() || offsets.length() - 1 == sizes.length());
188
189 using OffsetArrayType = typename TypeTraits<OffsetArrowType>::ArrayType;
190 const auto& typed_offsets = checked_cast<const OffsetArrayType&>(offsets);
191 const auto& typed_sizes = checked_cast<const OffsetArrayType&>(sizes);
192
193 auto derived_validity_buffer = std::move(null_bitmap);
194 if (offsets.null_count() > 0) {
195 derived_validity_buffer = offsets.null_bitmap();
196 null_count = offsets.null_count();
197 // We allow construction from an offsets array containing one extra value.
198 // If that is the case, we might need to discount one null from out_null_count.
199 if (offsets.length() - 1 == sizes.length() && !offsets.IsValid(sizes.length())) {
200 null_count -= 1;
201 }
202 } else if (sizes.null_count() > 0) {
203 derived_validity_buffer = sizes.null_bitmap();
204 null_count = sizes.null_count();

Callers

nothing calls this directly

Calls 11

MakeFunction · 0.70
TypeErrorFunction · 0.50
type_nameFunction · 0.50
InvalidFunction · 0.50
type_idMethod · 0.45
lengthMethod · 0.45
offsetMethod · 0.45
null_countMethod · 0.45
IsValidMethod · 0.45
valuesMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected