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

Class GetBufferLength

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

Source from the content-addressed store, hash-verified

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