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

Method StartFile

cpp/src/parquet/file_writer.cc:528–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

526 std::unique_ptr<BloomFilterBuilder> bloom_filter_builder_;
527
528 void StartFile() {
529 auto file_encryption_properties = properties_->file_encryption_properties();
530 if (file_encryption_properties == nullptr) {
531 // Unencrypted parquet files always start with PAR1
532 PARQUET_THROW_NOT_OK(sink_->Write(kParquetMagic, 4));
533 } else {
534 // Check that all columns in columnEncryptionProperties exist in the schema.
535 auto encrypted_columns = file_encryption_properties->encrypted_columns();
536 // if columnEncryptionProperties is empty, every column in file schema will be
537 // encrypted with footer key.
538 if (encrypted_columns.size() != 0) {
539 std::vector<std::string> column_path_vec;
540 std::vector<std::string> column_root_vec;
541 // First, save all column paths and root column names in schema.
542 for (int i = 0; i < num_columns(); i++) {
543 column_path_vec.push_back(schema_.Column(i)->path()->ToDotString());
544 column_root_vec.push_back(schema_.Column(i)->path()->ToDotVector().at(0));
545 }
546
547 for (const auto& elem : encrypted_columns) {
548 // Check if this column exists in schema.
549 auto it = std::find(column_path_vec.begin(), column_path_vec.end(), elem.first);
550 if (it == column_path_vec.end()) {
551 // this column does not exist in the schema, this might be a root column name
552 // like `a` while there are `a.key_value.key` and `a.key_value.value` in the
553 // schema.
554 it = std::find(column_root_vec.begin(), column_root_vec.end(), elem.first);
555 if (it == column_root_vec.end()) {
556 // no encrypted columns exist with this root column name
557 std::stringstream ss;
558 ss << "Encrypted column " + elem.first + " not in file schema: ";
559 for (auto& cp : column_path_vec) {
560 ss << cp << " ";
561 }
562 throw ParquetException(ss.str());
563 }
564 }
565 }
566 }
567
568 file_encryptor_ = std::make_unique<InternalFileEncryptor>(
569 file_encryption_properties, properties_->memory_pool());
570 if (file_encryption_properties->encrypted_footer()) {
571 PARQUET_THROW_NOT_OK(sink_->Write(kParquetEMagic, 4));
572 } else {
573 // Encrypted file with plaintext footer mode.
574 PARQUET_THROW_NOT_OK(sink_->Write(kParquetMagic, 4));
575 }
576 }
577 if (properties_->bloom_filter_enabled()) {
578 bloom_filter_builder_ = BloomFilterBuilder::Make(schema(), properties_.get());
579 }
580 if (properties_->page_index_enabled()) {
581 page_index_builder_ = PageIndexBuilder::Make(&schema_, file_encryptor_.get());
582 }
583 }
584};
585

Callers

nothing calls this directly

Calls 15

ParquetExceptionFunction · 0.85
encrypted_columnsMethod · 0.80
push_backMethod · 0.80
ToDotStringMethod · 0.80
strMethod · 0.80
num_columnsFunction · 0.70
MakeFunction · 0.70
schemaFunction · 0.50
WriteMethod · 0.45
sizeMethod · 0.45
pathMethod · 0.45
ColumnMethod · 0.45

Tested by

no test coverage detected