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

Function main

cpp/examples/parquet/low_level_api/encryption_reader_writer.cc:47–449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45const arrow::util::SecureString kColumnEncryptionKey2("1234567890123451");
46
47int main(int argc, char** argv) {
48 /**********************************************************************************
49 PARQUET ENCRYPTION WRITER EXAMPLE
50 **********************************************************************************/
51
52 try {
53 // Create a local file output stream instance.
54 using FileClass = ::arrow::io::FileOutputStream;
55 std::shared_ptr<FileClass> out_file;
56 PARQUET_ASSIGN_OR_THROW(out_file, FileClass::Open(PARQUET_FILENAME));
57
58 // Setup the parquet schema
59 std::shared_ptr<GroupNode> schema = SetupSchema();
60
61 // Add encryption properties
62 // Encryption configuration: Encrypt two columns and the footer.
63 std::map<std::string, std::shared_ptr<parquet::ColumnEncryptionProperties>>
64 encryption_cols;
65
66 parquet::SchemaDescriptor schema_desc;
67 schema_desc.Init(schema);
68 auto column_path1 = schema_desc.Column(5)->path()->ToDotString();
69 auto column_path2 = schema_desc.Column(4)->path()->ToDotString();
70
71 encryption_cols[column_path1] =
72 parquet::ColumnEncryptionProperties::WithColumnKey(kColumnEncryptionKey1, "kc1");
73 encryption_cols[column_path2] =
74 parquet::ColumnEncryptionProperties::WithColumnKey(kColumnEncryptionKey2, "kc2");
75
76 parquet::FileEncryptionProperties::Builder file_encryption_builder(
77 kFooterEncryptionKey);
78
79 parquet::WriterProperties::Builder builder;
80 // Add the current encryption configuration to WriterProperties.
81 builder.encryption(file_encryption_builder.footer_key_metadata("kf")
82 ->encrypted_columns(std::move(encryption_cols))
83 ->build());
84
85 // Add other writer properties
86 builder.compression(parquet::Compression::SNAPPY);
87
88 std::shared_ptr<parquet::WriterProperties> props = builder.build();
89
90 // Create a ParquetFileWriter instance
91 std::shared_ptr<parquet::ParquetFileWriter> file_writer =
92 parquet::ParquetFileWriter::Open(out_file, schema, props);
93
94 // Append a RowGroup with a specific number of rows.
95 parquet::RowGroupWriter* rg_writer = file_writer->AppendRowGroup();
96
97 // Write the Bool column
98 parquet::BoolWriter* bool_writer =
99 static_cast<parquet::BoolWriter*>(rg_writer->NextColumn());
100 for (int i = 0; i < NUM_ROWS_PER_ROW_GROUP; i++) {
101 bool value = ((i % 2) == 0) ? true : false;
102 bool_writer->WriteBatch(1, nullptr, nullptr, &value);
103 }
104

Callers

nothing calls this directly

Calls 15

OpenFileFunction · 0.85
ToDotStringMethod · 0.80
encrypted_columnsMethod · 0.80
footer_key_metadataMethod · 0.80
whatMethod · 0.80
PutKeyMethod · 0.80
key_retrieverMethod · 0.80
SetupSchemaFunction · 0.70
InitMethod · 0.45
pathMethod · 0.45
ColumnMethod · 0.45

Tested by

no test coverage detected