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

Method WriteDictionaryPage

cpp/src/parquet/column_writer.cc:286–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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