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

Method BuildArray

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

Source from the content-addressed store, hash-verified

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

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