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

Class GetBufferLength

cpp/src/arrow/array/util.cc:338–449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

336class NullArrayFactory {
337 public:
338 struct GetBufferLength {
339 GetBufferLength(const std::shared_ptr<DataType>& type, int64_t length)
340 : type_(*type), length_(length), buffer_length_(bit_util::BytesForBits(length)) {}
341
342 Result<int64_t> Finish() && {
343 RETURN_NOT_OK(VisitTypeInline(type_, this));
344 return buffer_length_;
345 }
346
347 template <typename T, typename = decltype(TypeTraits<T>::bytes_required(0))>
348 Status Visit(const T&) {
349 return MaxOf(TypeTraits<T>::bytes_required(length_));
350 }
351
352 template <typename T>
353 enable_if_var_size_list<T, Status> Visit(const T& type) {
354 // values array may be empty, but there must be at least one offset of 0
355 RETURN_NOT_OK(MaxOf(sizeof(typename T::offset_type) * (length_ + 1)));
356 RETURN_NOT_OK(MaxOf(GetBufferLength(type.value_type(), /*length=*/0)));
357 return Status::OK();
358 }
359
360 template <typename T>
361 enable_if_list_view<T, Status> Visit(const T& type) {
362 RETURN_NOT_OK(MaxOf(sizeof(typename T::offset_type) * length_));
363 RETURN_NOT_OK(MaxOf(GetBufferLength(type.value_type(), /*length=*/0)));
364 return Status::OK();
365 }
366
367 template <typename T>
368 enable_if_base_binary<T, Status> Visit(const T&) {
369 // values buffer may be empty, but there must be at least one offset of 0
370 return MaxOf(sizeof(typename T::offset_type) * (length_ + 1));
371 }
372
373 Status Visit(const BinaryViewType& type) {
374 return MaxOf(sizeof(BinaryViewType::c_type) * length_);
375 }
376
377 Status Visit(const FixedSizeListType& type) {
378 return MaxOf(GetBufferLength(type.value_type(), type.list_size() * length_));
379 }
380
381 Status Visit(const FixedSizeBinaryType& type) {
382 return MaxOf(type.byte_width() * length_);
383 }
384
385 Status Visit(const StructType& type) {
386 for (const auto& child : type.fields()) {
387 RETURN_NOT_OK(MaxOf(GetBufferLength(child->type(), length_)));
388 }
389 return Status::OK();
390 }
391
392 Status Visit(const SparseUnionType& type) {
393 // type codes
394 RETURN_NOT_OK(MaxOf(length_));
395 // will create children of the same length as the union

Callers 1

VisitMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected