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

Method WriteDataPage

cpp/src/parquet/column_writer.cc:392–477  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390 }
391
392 int64_t WriteDataPage(const DataPage& page) override {
393 const int64_t uncompressed_size = page.uncompressed_size();
394 if (uncompressed_size > std::numeric_limits<int32_t>::max()) {
395 throw ParquetException("Uncompressed data page size overflows INT32_MAX. Size:",
396 uncompressed_size);
397 }
398
399 std::shared_ptr<Buffer> compressed_data = page.buffer();
400 const uint8_t* output_data_buffer = compressed_data->data();
401 int64_t output_data_len = compressed_data->size();
402
403 if (output_data_len > std::numeric_limits<int32_t>::max()) {
404 throw ParquetException("Compressed data page size overflows INT32_MAX. Size:",
405 output_data_len);
406 }
407
408 if (data_encryptor_.get()) {
409 PARQUET_THROW_NOT_OK(encryption_buffer_->Resize(
410 data_encryptor_->CiphertextLength(output_data_len), false));
411 UpdateEncryption(encryption::kDataPage);
412 output_data_len =
413 data_encryptor_->Encrypt(compressed_data->span_as<uint8_t>(),
414 encryption_buffer_->mutable_span_as<uint8_t>());
415 output_data_buffer = encryption_buffer_->data();
416 }
417
418 format::PageHeader page_header;
419 page_header.__set_uncompressed_page_size(static_cast<int32_t>(uncompressed_size));
420 page_header.__set_compressed_page_size(static_cast<int32_t>(output_data_len));
421
422 if (page_checksum_verification_) {
423 uint32_t crc32 =
424 ::arrow::internal::crc32(/* prev */ 0, output_data_buffer, output_data_len);
425 page_header.__set_crc(static_cast<int32_t>(crc32));
426 }
427
428 if (page.type() == PageType::DATA_PAGE) {
429 const DataPageV1& v1_page = checked_cast<const DataPageV1&>(page);
430 SetDataPageHeader(page_header, v1_page);
431 } else if (page.type() == PageType::DATA_PAGE_V2) {
432 const DataPageV2& v2_page = checked_cast<const DataPageV2&>(page);
433 SetDataPageV2Header(page_header, v2_page);
434 } else {
435 throw ParquetException("Unexpected page type");
436 }
437
438 PARQUET_ASSIGN_OR_THROW(int64_t start_pos, sink_->Tell());
439 if (page_ordinal_ == 0) {
440 data_page_offset_ = start_pos;
441 }
442
443 if (meta_encryptor_) {
444 UpdateEncryption(encryption::kDataPageHeader);
445 }
446 const int64_t header_size =
447 thrift_serializer_->Serialize(&page_header, sink_.get(), meta_encryptor_.get());
448 PARQUET_THROW_NOT_OK(sink_->Write(output_data_buffer, output_data_len));
449

Callers

nothing calls this directly

Calls 15

ParquetExceptionFunction · 0.85
crc32Function · 0.85
uncompressed_sizeMethod · 0.80
__set_crcMethod · 0.80
first_row_indexMethod · 0.80
bufferMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
ResizeMethod · 0.45

Tested by

no test coverage detected