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

Method BuildArray

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

Source from the content-addressed store, hash-verified

786}
787
788Status StructReader::BuildArray(int64_t length_upper_bound,
789 std::shared_ptr<ChunkedArray>* out) {
790 std::vector<std::shared_ptr<ArrayData>> children_array_data;
791 std::shared_ptr<ResizableBuffer> null_bitmap;
792
793 ::parquet::internal::ValidityBitmapInputOutput validity_io;
794 validity_io.values_read_upper_bound = length_upper_bound;
795 // This simplifies accounting below.
796 validity_io.values_read = length_upper_bound;
797
798 BEGIN_PARQUET_CATCH_EXCEPTIONS
799 const int16_t* def_levels;
800 const int16_t* rep_levels;
801 int64_t num_levels;
802
803 if (has_repeated_child_) {
804 ARROW_ASSIGN_OR_RAISE(
805 null_bitmap,
806 AllocateResizableBuffer(bit_util::BytesForBits(length_upper_bound), ctx_->pool));
807 validity_io.valid_bits = null_bitmap->mutable_data();
808 RETURN_NOT_OK(GetDefLevels(&def_levels, &num_levels));
809 RETURN_NOT_OK(GetRepLevels(&rep_levels, &num_levels));
810 DefRepLevelsToBitmap(def_levels, rep_levels, num_levels, level_info_, &validity_io);
811 } else if (filtered_field_->nullable()) {
812 ARROW_ASSIGN_OR_RAISE(
813 null_bitmap,
814 AllocateResizableBuffer(bit_util::BytesForBits(length_upper_bound), ctx_->pool));
815 validity_io.valid_bits = null_bitmap->mutable_data();
816 RETURN_NOT_OK(GetDefLevels(&def_levels, &num_levels));
817 DefLevelsToBitmap(def_levels, num_levels, level_info_, &validity_io);
818 }
819
820 // Ensure all values are initialized.
821 if (null_bitmap) {
822 RETURN_NOT_OK(null_bitmap->Resize(bit_util::BytesForBits(validity_io.values_read)));
823 null_bitmap->ZeroPadding();
824 }
825
826 END_PARQUET_CATCH_EXCEPTIONS
827 // Gather children arrays and def levels
828 for (auto& child : children_) {
829 std::shared_ptr<ChunkedArray> field;
830 RETURN_NOT_OK(child->BuildArray(validity_io.values_read, &field));
831 ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayData> array_data, ChunksToSingle(*field));
832 children_array_data.push_back(std::move(array_data));
833 }
834
835 if (!filtered_field_->nullable() && !has_repeated_child_) {
836 validity_io.values_read = children_array_data.front()->length;
837 }
838
839 std::vector<std::shared_ptr<Buffer>> buffers{validity_io.null_count > 0 ? null_bitmap
840 : nullptr};
841 auto data =
842 std::make_shared<ArrayData>(filtered_field_->type(),
843 /*length=*/validity_io.values_read, std::move(buffers),
844 std::move(children_array_data));
845 std::shared_ptr<Array> result = ::arrow::MakeArray(data);

Callers 3

BuildArrayMethod · 0.45
BuildArrayMethod · 0.45
forFunction · 0.45

Calls 11

AllocateResizableBufferFunction · 0.85
BytesForBitsFunction · 0.85
DefRepLevelsToBitmapFunction · 0.85
DefLevelsToBitmapFunction · 0.85
nullableMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.70
MakeArrayFunction · 0.50
OKFunction · 0.50
mutable_dataMethod · 0.45
ResizeMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected