| 77 | } |
| 78 | |
| 79 | arrow::Status WriteEncryptedFile(const std::string& path_to_file) { |
| 80 | using arrow::internal::checked_pointer_cast; |
| 81 | |
| 82 | // Get a configured crypto factory and kms connection conf. |
| 83 | auto crypto_factory = GetCryptoFactory(); |
| 84 | auto kms_connection_config = |
| 85 | std::make_shared<parquet::encryption::KmsConnectionConfig>(); |
| 86 | |
| 87 | // Set write options with encryption configuration. |
| 88 | auto encryption_config = std::make_shared<parquet::encryption::EncryptionConfiguration>( |
| 89 | std::string("footerKeyId")); |
| 90 | encryption_config->column_keys = "columnKeyId: i, s, m, l"; |
| 91 | |
| 92 | auto parquet_encryption_config = std::make_shared<ds::ParquetEncryptionConfig>(); |
| 93 | // Directly assign shared_ptr objects to ParquetEncryptionConfig members. |
| 94 | parquet_encryption_config->crypto_factory = crypto_factory; |
| 95 | parquet_encryption_config->kms_connection_config = kms_connection_config; |
| 96 | parquet_encryption_config->encryption_config = std::move(encryption_config); |
| 97 | |
| 98 | auto file_format = std::make_shared<ds::ParquetFileFormat>(); |
| 99 | auto parquet_file_write_options = checked_pointer_cast<ds::ParquetFileWriteOptions>( |
| 100 | file_format->DefaultWriteOptions()); |
| 101 | parquet_file_write_options->parquet_encryption_config = |
| 102 | std::move(parquet_encryption_config); |
| 103 | |
| 104 | // Write dataset. |
| 105 | ARROW_ASSIGN_OR_RAISE(std::shared_ptr<arrow::Table> table, GetTable()); |
| 106 | printf("%s", table->ToString().c_str()); |
| 107 | auto dataset = std::make_shared<ds::InMemoryDataset>(table); |
| 108 | ARROW_ASSIGN_OR_RAISE(auto scanner_builder, dataset->NewScan()); |
| 109 | ARROW_ASSIGN_OR_RAISE(auto scanner, scanner_builder->Finish()); |
| 110 | |
| 111 | auto file_system = std::make_shared<fs::LocalFileSystem>(); |
| 112 | auto partitioning = std::make_shared<ds::HivePartitioning>( |
| 113 | arrow::schema({arrow::field("part", arrow::utf8())})); |
| 114 | |
| 115 | ds::FileSystemDatasetWriteOptions write_options; |
| 116 | write_options.file_write_options = parquet_file_write_options; |
| 117 | write_options.filesystem = file_system; |
| 118 | write_options.base_dir = path_to_file; |
| 119 | write_options.partitioning = partitioning; |
| 120 | write_options.basename_template = "part{i}.parquet"; |
| 121 | return ds::FileSystemDataset::Write(write_options, std::move(scanner)); |
| 122 | } |
| 123 | |
| 124 | arrow::Status ReadEncryptedFile(const std::string& path_to_file) { |
| 125 | // Get a configured crypto factory and kms connection conf |
no test coverage detected