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

Method WriteDictionaryPage

cpp/src/parquet/column_writer.cc:285–353  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

283 }
284
285 int64_t WriteDictionaryPage(const DictionaryPage& page) override {
286 int64_t uncompressed_size = page.buffer()->size();
287 if (uncompressed_size > std::numeric_limits<int32_t>::max()) {
288 throw ParquetException(
289 "Uncompressed dictionary page size overflows INT32_MAX. Size:",
290 uncompressed_size);
291 }
292 std::shared_ptr<Buffer> compressed_data;
293 if (has_compressor()) {
294 auto buffer = std::static_pointer_cast<ResizableBuffer>(
295 AllocateBuffer(pool_, uncompressed_size));
296 Compress(*(page.buffer().get()), buffer.get());
297 compressed_data = std::static_pointer_cast<Buffer>(buffer);
298 } else {
299 compressed_data = page.buffer();
300 }
301
302 format::DictionaryPageHeader dict_page_header;
303 dict_page_header.__set_num_values(page.num_values());
304 dict_page_header.__set_encoding(ToThrift(page.encoding()));
305 dict_page_header.__set_is_sorted(page.is_sorted());
306
307 const uint8_t* output_data_buffer = compressed_data->data();
308 if (compressed_data->size() > std::numeric_limits<int32_t>::max()) {
309 throw ParquetException(
310 "Compressed dictionary page size overflows INT32_MAX. Size: ",
311 uncompressed_size);
312 }
313 int32_t output_data_len = static_cast<int32_t>(compressed_data->size());
314
315 if (data_encryptor_.get()) {
316 UpdateEncryption(encryption::kDictionaryPage);
317 PARQUET_THROW_NOT_OK(encryption_buffer_->Resize(
318 data_encryptor_->CiphertextLength(output_data_len), false));
319 output_data_len =
320 data_encryptor_->Encrypt(compressed_data->span_as<uint8_t>(),
321 encryption_buffer_->mutable_span_as<uint8_t>());
322 output_data_buffer = encryption_buffer_->data();
323 }
324
325 format::PageHeader page_header;
326 page_header.__set_type(format::PageType::DICTIONARY_PAGE);
327 page_header.__set_uncompressed_page_size(static_cast<int32_t>(uncompressed_size));
328 page_header.__set_compressed_page_size(static_cast<int32_t>(output_data_len));
329 page_header.__set_dictionary_page_header(dict_page_header);
330 if (page_checksum_verification_) {
331 uint32_t crc32 =
332 ::arrow::internal::crc32(/* prev */ 0, output_data_buffer, output_data_len);
333 page_header.__set_crc(static_cast<int32_t>(crc32));
334 }
335
336 PARQUET_ASSIGN_OR_THROW(int64_t start_pos, sink_->Tell());
337 if (dictionary_page_offset_ == 0) {
338 dictionary_page_offset_ = start_pos;
339 }
340
341 if (meta_encryptor_) {
342 UpdateEncryption(encryption::kDictionaryPageHeader);

Callers

nothing calls this directly

Calls 15

ParquetExceptionFunction · 0.85
ToThriftFunction · 0.85
crc32Function · 0.85
__set_num_valuesMethod · 0.80
__set_encodingMethod · 0.80
__set_is_sortedMethod · 0.80
is_sortedMethod · 0.80
__set_typeMethod · 0.80
__set_crcMethod · 0.80

Tested by

no test coverage detected