| 1048 | } |
| 1049 | |
| 1050 | void ColumnWriterImpl::BuildDataPageV2(int64_t definition_levels_rle_size, |
| 1051 | int64_t repetition_levels_rle_size, |
| 1052 | int64_t uncompressed_size, |
| 1053 | const std::shared_ptr<Buffer>& values) { |
| 1054 | // Compress the values if needed. Repetition and definition levels are uncompressed in |
| 1055 | // V2. |
| 1056 | bool page_is_compressed = false; |
| 1057 | if (pager_->has_compressor() && values->size() > 0) { |
| 1058 | pager_->Compress(*values, compressor_temp_buffer_.get()); |
| 1059 | if (compressor_temp_buffer_->size() < values->size()) { |
| 1060 | page_is_compressed = true; |
| 1061 | } |
| 1062 | } |
| 1063 | std::shared_ptr<Buffer> compressed_values = |
| 1064 | (page_is_compressed ? compressor_temp_buffer_ : values); |
| 1065 | |
| 1066 | // Concatenate uncompressed levels and the possibly compressed values |
| 1067 | int64_t combined_size = |
| 1068 | definition_levels_rle_size + repetition_levels_rle_size + compressed_values->size(); |
| 1069 | std::shared_ptr<ResizableBuffer> combined = AllocateBuffer(allocator_, combined_size); |
| 1070 | |
| 1071 | ConcatenateBuffers(definition_levels_rle_size, repetition_levels_rle_size, |
| 1072 | compressed_values, combined->mutable_data()); |
| 1073 | |
| 1074 | auto [page_stats, page_size_stats] = GetPageStatistics(); |
| 1075 | page_stats.ApplyStatSizeLimits(properties_->max_statistics_size(descr_->path())); |
| 1076 | page_stats.set_is_signed(SortOrder::SIGNED == descr_->sort_order()); |
| 1077 | ResetPageStatistics(); |
| 1078 | |
| 1079 | int32_t num_values = static_cast<int32_t>(num_buffered_values_); |
| 1080 | int32_t null_count = static_cast<int32_t>(num_buffered_nulls_); |
| 1081 | int32_t num_rows = static_cast<int32_t>(num_buffered_rows_); |
| 1082 | int32_t def_levels_byte_length = static_cast<int32_t>(definition_levels_rle_size); |
| 1083 | int32_t rep_levels_byte_length = static_cast<int32_t>(repetition_levels_rle_size); |
| 1084 | int64_t first_row_index = rows_written_ - num_buffered_rows_; |
| 1085 | |
| 1086 | // page_stats.null_count is not set when page_statistics_ is nullptr. It is only used |
| 1087 | // here for safety check. |
| 1088 | DCHECK(!page_stats.has_null_count || page_stats.null_count == null_count); |
| 1089 | |
| 1090 | // Write the page to OutputStream eagerly if there is no dictionary or |
| 1091 | // if dictionary encoding has fallen back to PLAIN |
| 1092 | if (has_dictionary_ && !fallback_) { // Save pages until end of dictionary encoding |
| 1093 | PARQUET_ASSIGN_OR_THROW(auto data_copy, |
| 1094 | combined->CopySlice(0, combined->size(), allocator_)); |
| 1095 | std::unique_ptr<DataPage> page_ptr = std::make_unique<DataPageV2>( |
| 1096 | combined, num_values, null_count, num_rows, encoding_, def_levels_byte_length, |
| 1097 | rep_levels_byte_length, uncompressed_size, page_is_compressed, |
| 1098 | std::move(page_stats), first_row_index, std::move(page_size_stats)); |
| 1099 | total_compressed_bytes_ += page_ptr->size() + sizeof(format::PageHeader); |
| 1100 | data_pages_.push_back(std::move(page_ptr)); |
| 1101 | } else { |
| 1102 | DataPageV2 page(combined, num_values, null_count, num_rows, encoding_, |
| 1103 | def_levels_byte_length, rep_levels_byte_length, uncompressed_size, |
| 1104 | page_is_compressed, std::move(page_stats), first_row_index, |
| 1105 | std::move(page_size_stats)); |
| 1106 | WriteDataPage(page); |
| 1107 | } |
nothing calls this directly
no test coverage detected