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

Method BuildArray

cpp/src/parquet/arrow/reader.cc:621–673  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

619 }
620
621 Status BuildArray(int64_t length_upper_bound,
622 std::shared_ptr<ChunkedArray>* out) override {
623 const int16_t* def_levels;
624 const int16_t* rep_levels;
625 int64_t num_levels;
626 RETURN_NOT_OK(item_reader_->GetDefLevels(&def_levels, &num_levels));
627 RETURN_NOT_OK(item_reader_->GetRepLevels(&rep_levels, &num_levels));
628
629 std::shared_ptr<ResizableBuffer> validity_buffer;
630 ::parquet::internal::ValidityBitmapInputOutput validity_io;
631 validity_io.values_read_upper_bound = length_upper_bound;
632 if (field_->nullable()) {
633 ARROW_ASSIGN_OR_RAISE(validity_buffer,
634 AllocateResizableBuffer(
635 bit_util::BytesForBits(length_upper_bound), ctx_->pool));
636 validity_io.valid_bits = validity_buffer->mutable_data();
637 }
638 ARROW_ASSIGN_OR_RAISE(
639 std::shared_ptr<ResizableBuffer> offsets_buffer,
640 AllocateResizableBuffer(
641 sizeof(IndexType) * std::max(int64_t{1}, length_upper_bound + 1),
642 ctx_->pool));
643 // Ensure zero initialization in case we have reached a zero length list (and
644 // because first entry is always zero).
645 IndexType* offset_data = reinterpret_cast<IndexType*>(offsets_buffer->mutable_data());
646 offset_data[0] = 0;
647 BEGIN_PARQUET_CATCH_EXCEPTIONS
648 ::parquet::internal::DefRepLevelsToList(def_levels, rep_levels, num_levels,
649 level_info_, &validity_io, offset_data);
650 END_PARQUET_CATCH_EXCEPTIONS
651
652 RETURN_NOT_OK(item_reader_->BuildArray(offset_data[validity_io.values_read], out));
653
654 // Resize to actual number of elements returned.
655 RETURN_NOT_OK(
656 offsets_buffer->Resize((validity_io.values_read + 1) * sizeof(IndexType)));
657 if (validity_buffer != nullptr) {
658 RETURN_NOT_OK(
659 validity_buffer->Resize(bit_util::BytesForBits(validity_io.values_read)));
660 validity_buffer->ZeroPadding();
661 }
662 ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayData> item_chunk, ChunksToSingle(**out));
663
664 std::vector<std::shared_ptr<Buffer>> buffers{
665 validity_io.null_count > 0 ? validity_buffer : nullptr, offsets_buffer};
666 auto data = std::make_shared<ArrayData>(
667 field_->type(),
668 /*length=*/validity_io.values_read, std::move(buffers),
669 std::vector<std::shared_ptr<ArrayData>>{item_chunk}, validity_io.null_count);
670
671 ARROW_ASSIGN_OR_RAISE(*out, AssembleArray(std::move(data)));
672 return Status::OK();
673 }
674
675 const std::shared_ptr<Field> field() override { return field_; }
676

Callers

nothing calls this directly

Calls 13

AllocateResizableBufferFunction · 0.85
BytesForBitsFunction · 0.85
DefRepLevelsToListFunction · 0.85
ChunksToSingleFunction · 0.85
nullableMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.70
OKFunction · 0.50
GetDefLevelsMethod · 0.45
GetRepLevelsMethod · 0.45
mutable_dataMethod · 0.45
BuildArrayMethod · 0.45
ResizeMethod · 0.45

Tested by

no test coverage detected