| 819 | } |
| 820 | |
| 821 | Status StructReader::BuildArray(int64_t length_upper_bound, |
| 822 | std::shared_ptr<ChunkedArray>* out) { |
| 823 | std::vector<std::shared_ptr<ArrayData>> children_array_data; |
| 824 | std::shared_ptr<ResizableBuffer> null_bitmap; |
| 825 | |
| 826 | ::parquet::internal::ValidityBitmapInputOutput validity_io; |
| 827 | validity_io.values_read_upper_bound = length_upper_bound; |
| 828 | // This simplifies accounting below. |
| 829 | validity_io.values_read = length_upper_bound; |
| 830 | |
| 831 | BEGIN_PARQUET_CATCH_EXCEPTIONS |
| 832 | const int16_t* def_levels; |
| 833 | const int16_t* rep_levels; |
| 834 | int64_t num_levels; |
| 835 | |
| 836 | if (has_repeated_child_) { |
| 837 | ARROW_ASSIGN_OR_RAISE( |
| 838 | null_bitmap, |
| 839 | AllocateResizableBuffer(bit_util::BytesForBits(length_upper_bound), ctx_->pool)); |
| 840 | validity_io.valid_bits = null_bitmap->mutable_data(); |
| 841 | RETURN_NOT_OK(GetDefLevels(&def_levels, &num_levels)); |
| 842 | RETURN_NOT_OK(GetRepLevels(&rep_levels, &num_levels)); |
| 843 | DefRepLevelsToBitmap(def_levels, rep_levels, num_levels, level_info_, &validity_io); |
| 844 | } else if (filtered_field_->nullable()) { |
| 845 | ARROW_ASSIGN_OR_RAISE( |
| 846 | null_bitmap, |
| 847 | AllocateResizableBuffer(bit_util::BytesForBits(length_upper_bound), ctx_->pool)); |
| 848 | validity_io.valid_bits = null_bitmap->mutable_data(); |
| 849 | RETURN_NOT_OK(GetDefLevels(&def_levels, &num_levels)); |
| 850 | DefLevelsToBitmap(def_levels, num_levels, level_info_, &validity_io); |
| 851 | } |
| 852 | |
| 853 | // Ensure all values are initialized. |
| 854 | if (null_bitmap) { |
| 855 | RETURN_NOT_OK(null_bitmap->Resize(bit_util::BytesForBits(validity_io.values_read))); |
| 856 | null_bitmap->ZeroPadding(); |
| 857 | } |
| 858 | |
| 859 | END_PARQUET_CATCH_EXCEPTIONS |
| 860 | // Gather children arrays and def levels |
| 861 | for (auto& child : children_) { |
| 862 | std::shared_ptr<ChunkedArray> field; |
| 863 | RETURN_NOT_OK(child->BuildArray(validity_io.values_read, &field)); |
| 864 | ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayData> array_data, ChunksToSingle(*field)); |
| 865 | children_array_data.push_back(std::move(array_data)); |
| 866 | } |
| 867 | |
| 868 | if (!filtered_field_->nullable() && !has_repeated_child_) { |
| 869 | validity_io.values_read = children_array_data.front()->length; |
| 870 | } |
| 871 | |
| 872 | std::vector<std::shared_ptr<Buffer>> buffers{validity_io.null_count > 0 ? null_bitmap |
| 873 | : nullptr}; |
| 874 | auto data = |
| 875 | std::make_shared<ArrayData>(filtered_field_->type(), |
| 876 | /*length=*/validity_io.values_read, std::move(buffers), |
| 877 | std::move(children_array_data)); |
| 878 | std::shared_ptr<Array> result = ::arrow::MakeArray(data); |
no test coverage detected