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

Method BuildArray

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

Source from the content-addressed store, hash-verified

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

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