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

Method EncryptFile

cpp/src/parquet/encryption/test_encryption_util.cc:210–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208}
209
210void FileEncryptor::EncryptFile(
211 std::string file,
212 std::shared_ptr<parquet::FileEncryptionProperties> encryption_configurations) {
213 WriterProperties::Builder prop_builder;
214 prop_builder.compression(parquet::Compression::UNCOMPRESSED);
215 prop_builder.encryption(encryption_configurations);
216 prop_builder.enable_write_page_index();
217 std::shared_ptr<WriterProperties> writer_properties = prop_builder.build();
218
219 PARQUET_ASSIGN_OR_THROW(auto out_file, FileOutputStream::Open(file));
220 // Create a ParquetFileWriter instance
221 std::shared_ptr<parquet::ParquetFileWriter> file_writer =
222 parquet::ParquetFileWriter::Open(out_file, schema_, writer_properties);
223
224 for (int r = 0; r < num_rowgroups_; r++) {
225 bool buffered_mode = r % 2 == 0;
226 auto row_group_writer = buffered_mode ? file_writer->AppendBufferedRowGroup()
227 : file_writer->AppendRowGroup();
228
229 int column_index = 0;
230 // Captures i by reference; increments it by one
231 auto get_next_column = [&]() {
232 return buffered_mode ? row_group_writer->column(column_index++)
233 : row_group_writer->NextColumn();
234 };
235
236 // Write the Bool column
237 parquet::BoolWriter* bool_writer =
238 static_cast<parquet::BoolWriter*>(get_next_column());
239 for (int i = 0; i < rows_per_rowgroup_; i++) {
240 bool value = ((i % 2) == 0) ? true : false;
241 bool_writer->WriteBatch(1, nullptr, nullptr, &value);
242 }
243
244 // Write the Int32 column
245 WriteBatch<Int32Type>(rows_per_rowgroup_, get_next_column);
246
247 // Write the Int64 column.
248 WriteBatch<Int64Type>(rows_per_rowgroup_, get_next_column);
249
250 // Write the INT96 column.
251 WriteBatch<Int96Type>(rows_per_rowgroup_, get_next_column);
252
253 // Write the Float column
254 WriteBatch<FloatType>(rows_per_rowgroup_, get_next_column);
255
256 // Write the Double column
257 WriteBatch<DoubleType>(rows_per_rowgroup_, get_next_column);
258
259 // Write the ByteArray column. Make every alternate values NULL
260 // Write the ByteArray column. Make every alternate values NULL
261 parquet::ByteArrayWriter* ba_writer =
262 static_cast<parquet::ByteArrayWriter*>(get_next_column());
263 for (int i = 0; i < rows_per_rowgroup_; i++) {
264 parquet::ByteArray value;
265 char hello[kFixedLength] = "parquet";
266 hello[7] = static_cast<char>(static_cast<int>('0') + i / 100);
267 hello[8] = static_cast<char>(static_cast<int>('0') + (i / 10) % 10);

Callers 2

TEST_FFunction · 0.45

Calls 8

compressionMethod · 0.45
buildMethod · 0.45
AppendRowGroupMethod · 0.45
columnMethod · 0.45
NextColumnMethod · 0.45
WriteBatchMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected