| 876 | } |
| 877 | |
| 878 | Status StructReader::BuildArray(int64_t length_upper_bound, |
| 879 | std::shared_ptr<ChunkedArray>* out) { |
| 880 | std::vector<std::shared_ptr<ArrayData>> children_array_data; |
| 881 | std::shared_ptr<ResizableBuffer> null_bitmap; |
| 882 | |
| 883 | ::parquet::internal::ValidityBitmapInputOutput validity_io; |
| 884 | validity_io.values_read_upper_bound = length_upper_bound; |
| 885 | // This simplifies accounting below. |
| 886 | validity_io.values_read = length_upper_bound; |
| 887 | |
| 888 | BEGIN_PARQUET_CATCH_EXCEPTIONS |
| 889 | const int16_t* def_levels; |
| 890 | const int16_t* rep_levels; |
| 891 | int64_t num_levels; |
| 892 | |
| 893 | if (has_repeated_child_) { |
| 894 | ARROW_ASSIGN_OR_RAISE( |
| 895 | null_bitmap, |
| 896 | AllocateResizableBuffer(bit_util::BytesForBits(length_upper_bound), ctx_->pool)); |
| 897 | validity_io.valid_bits = null_bitmap->mutable_data(); |
| 898 | RETURN_NOT_OK(GetDefLevels(&def_levels, &num_levels)); |
| 899 | RETURN_NOT_OK(GetRepLevels(&rep_levels, &num_levels)); |
| 900 | DefRepLevelsToBitmap(def_levels, rep_levels, num_levels, level_info_, &validity_io); |
| 901 | } else if (filtered_field_->nullable()) { |
| 902 | ARROW_ASSIGN_OR_RAISE( |
| 903 | null_bitmap, |
| 904 | AllocateResizableBuffer(bit_util::BytesForBits(length_upper_bound), ctx_->pool)); |
| 905 | validity_io.valid_bits = null_bitmap->mutable_data(); |
| 906 | RETURN_NOT_OK(GetDefLevels(&def_levels, &num_levels)); |
| 907 | DefLevelsToBitmap(def_levels, num_levels, level_info_, &validity_io); |
| 908 | } |
| 909 | |
| 910 | // Ensure all values are initialized. |
| 911 | if (null_bitmap) { |
| 912 | RETURN_NOT_OK(null_bitmap->Resize(bit_util::BytesForBits(validity_io.values_read))); |
| 913 | null_bitmap->ZeroPadding(); |
| 914 | } |
| 915 | |
| 916 | END_PARQUET_CATCH_EXCEPTIONS |
| 917 | // Gather children arrays and def levels |
| 918 | for (auto& child : children_) { |
| 919 | std::shared_ptr<ChunkedArray> field; |
| 920 | RETURN_NOT_OK(child->BuildArray(validity_io.values_read, &field)); |
| 921 | ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayData> array_data, ChunksToSingle(*field)); |
| 922 | children_array_data.push_back(std::move(array_data)); |
| 923 | } |
| 924 | |
| 925 | if (!filtered_field_->nullable() && !has_repeated_child_) { |
| 926 | validity_io.values_read = children_array_data.front()->length; |
| 927 | } |
| 928 | |
| 929 | std::vector<std::shared_ptr<Buffer>> buffers{validity_io.null_count > 0 ? null_bitmap |
| 930 | : nullptr}; |
| 931 | auto data = |
| 932 | std::make_shared<ArrayData>(filtered_field_->type(), |
| 933 | /*length=*/validity_io.values_read, std::move(buffers), |
| 934 | std::move(children_array_data)); |
| 935 | std::shared_ptr<Array> result = ::arrow::MakeArray(data); |
no test coverage detected