Repository navigation
build: enable Parquet modular encryption and zstd in vendored Arrow #989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cb4513d
build: enable Parquet modular encryption and zstd in vendored Arrow
shangxinli db6f9d3
build: add the OpenSSL include directory to all vendored Parquet targets
shangxinli 59b678a
build: address review feedback on OpenSSL wiring and encryption default
shangxinli 13b772a
Merge remote-tracking branch 'apache/main' into pr/01-build
wgtmac 6a43797
ci: build and test Parquet encryption in the Windows job
wgtmac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include <arrow/io/memory.h> | ||
| #include <arrow/json/from_string.h> | ||
| #include <arrow/table.h> | ||
| #include <arrow/util/secure_string.h> | ||
| #include <gtest/gtest.h> | ||
| #include <parquet/arrow/reader.h> | ||
| #include <parquet/arrow/writer.h> | ||
| #include <parquet/encryption/encryption.h> | ||
| #include <parquet/exception.h> | ||
| #include <parquet/file_reader.h> | ||
| #include <parquet/properties.h> | ||
|
|
||
| namespace iceberg::parquet { | ||
|
|
||
| namespace { | ||
|
|
||
| const std::string kKey = "0123456789012345"; | ||
| const std::string kAadPrefix = "file-aad-prefix-"; | ||
|
|
||
| std::shared_ptr<::arrow::Table> MakeTable() { | ||
| auto schema = ::arrow::schema({::arrow::field("id", ::arrow::int64())}); | ||
| auto ids = | ||
| ::arrow::json::ArrayFromJSONString(::arrow::int64(), "[1, 2, 3]").ValueOrDie(); | ||
| return ::arrow::Table::Make(schema, {ids}); | ||
| } | ||
|
|
||
| std::shared_ptr<::arrow::Buffer> WriteEncrypted(::parquet::Compression::type codec) { | ||
| // Same settings as Iceberg: footer key only (encrypted footer), AAD prefix supplied | ||
| // by the reader from the manifest instead of stored in the file. | ||
| ::parquet::FileEncryptionProperties::Builder encryption{ | ||
| ::arrow::util::SecureString(std::string(kKey))}; | ||
| encryption.aad_prefix(kAadPrefix); | ||
| encryption.disable_aad_prefix_storage(); | ||
| auto properties = ::parquet::WriterProperties::Builder() | ||
| .compression(codec) | ||
| ->encryption(encryption.build()) | ||
| ->build(); | ||
|
|
||
| auto sink = ::arrow::io::BufferOutputStream::Create().ValueOrDie(); | ||
| PARQUET_THROW_NOT_OK(::parquet::arrow::WriteTable( | ||
| *MakeTable(), ::arrow::default_memory_pool(), sink, 1024, properties)); | ||
| return sink->Finish().ValueOrDie(); | ||
| } | ||
|
|
||
| std::shared_ptr<::arrow::Table> Read(const std::shared_ptr<::arrow::Buffer>& buffer, | ||
| const std::string& aad_prefix) { | ||
| ::parquet::FileDecryptionProperties::Builder decryption; | ||
| decryption.footer_key(::arrow::util::SecureString(std::string(kKey))); | ||
| decryption.aad_prefix(aad_prefix); | ||
| ::parquet::ReaderProperties properties; | ||
| properties.file_decryption_properties(decryption.build()); | ||
|
|
||
| auto reader = ::parquet::ParquetFileReader::Open( | ||
| std::make_shared<::arrow::io::BufferReader>(buffer), properties); | ||
| auto arrow_reader = ::parquet::arrow::FileReader::Make(::arrow::default_memory_pool(), | ||
| std::move(reader)) | ||
| .ValueOrDie(); | ||
| return arrow_reader->ReadTable().ValueOrDie(); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| TEST(ParquetEncryptionTest, ModularEncryptionIsAvailable) { | ||
| for (auto codec : | ||
| {::parquet::Compression::UNCOMPRESSED, ::parquet::Compression::ZSTD}) { | ||
| auto buffer = WriteEncrypted(codec); | ||
| // Encrypted footer mode | ||
| ASSERT_EQ(std::string(reinterpret_cast<const char*>(buffer->data()), 4), "PARE"); | ||
| EXPECT_TRUE(Read(buffer, kAadPrefix)->Equals(*MakeTable())); | ||
| // The AAD prefix binds the file to its manifest entry | ||
| EXPECT_THROW(Read(buffer, "another-prefix--"), ::parquet::ParquetException); | ||
| } | ||
| } | ||
|
|
||
| } // namespace iceberg::parquet |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.