Skip to content

Commit 44357ac

Browse files
committed
- Added support for Parquet utils to read/decode num_elements from headers+level bytes without actually reading the value bytes.
- num_elements for DICTIONARY_PAGE and DATA_PAGE_V2 pages read from the headers values directly (easy) - num_elements for DATA_PAGE_V1 pages read from the level bytes and RLE bit decoding (hard!) - Added unittests for RLE bit decoding and count present values from definition levels for DATA_PAGE_V1 pages. - Updated all scripts and unittests for new Parquet parsing requirements.
1 parent 6d8944d commit 44357ac

9 files changed

Lines changed: 628 additions & 108 deletions

src/common/dbpa_local_test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ TEST_F(LocalDataBatchProtectionAgentTest, SuccessfulEncryption) {
5050
Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, std::nullopt));
5151

5252
std::vector<uint8_t> test_data = BuildByteArrayValueBytesForTesting("test_ABC");
53-
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}};
53+
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}, {"dict_page_num_values", "1"}};
5454
auto result = agent.Encrypt(test_data, encoding_attributes);
5555

5656
ASSERT_NE(result, nullptr);
@@ -74,7 +74,7 @@ TEST_F(LocalDataBatchProtectionAgentTest, SuccessfulEncryptionCompressedDictiona
7474
0x03, 0x32, 0x92, 0x12, 0xF3, 0x80, 0x10, 0x00, 0xC7, 0xB8,
7575
0x50, 0xFC, 0x13, 0x00, 0x00, 0x00
7676
};
77-
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}};
77+
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}, {"dict_page_num_values", "1"}};
7878
auto result = agent.Encrypt(test_data_gzip, encoding_attributes);
7979

8080
ASSERT_NE(result, nullptr);
@@ -93,7 +93,7 @@ TEST_F(LocalDataBatchProtectionAgentTest, SuccessfulDecryption) {
9393
Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, DBPS_ENCRYPTION_METADATA));
9494

9595
std::vector<uint8_t> test_data = BuildByteArrayValueBytesForTesting("test_EFG");
96-
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}};
96+
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}, {"dict_page_num_values", "1"}};
9797
auto result = agent.Decrypt(test_data, encoding_attributes);
9898

9999
ASSERT_NE(result, nullptr);
@@ -113,7 +113,7 @@ TEST_F(LocalDataBatchProtectionAgentTest, RoundTripEncryptDecrypt) {
113113

114114
// Original data to encrypt
115115
std::vector<uint8_t> original_data = BuildByteArrayValueBytesForTesting("roundtrip_XYZ");
116-
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}};
116+
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}, {"dict_page_num_values", "1"}};
117117

118118
// Encrypt the data
119119
auto encrypt_result = encrypt_agent.Encrypt(original_data, encoding_attributes);
@@ -156,7 +156,7 @@ TEST_F(LocalDataBatchProtectionAgentTest, EncryptWithoutInit) {
156156
LocalDataBatchProtectionAgent agent;
157157

158158
std::vector<uint8_t> test_data = {1, 2, 3, 4};
159-
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}};
159+
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}, {"dict_page_num_values", "1"}};
160160
auto result = agent.Encrypt(test_data, encoding_attributes);
161161

162162
ASSERT_NE(result, nullptr);
@@ -171,7 +171,7 @@ TEST_F(LocalDataBatchProtectionAgentTest, DecryptWithoutInit) {
171171
LocalDataBatchProtectionAgent agent;
172172

173173
std::vector<uint8_t> test_data = {1, 2, 3, 4};
174-
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}};
174+
std::map<std::string, std::string> encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}, {"dict_page_num_values", "1"}};
175175
auto result = agent.Decrypt(test_data, encoding_attributes);
176176

177177
ASSERT_NE(result, nullptr);
@@ -203,7 +203,7 @@ TEST_F(LocalDataBatchProtectionAgentTest, MissingPageEncoding) {
203203
Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, std::nullopt));
204204

205205
std::vector<uint8_t> test_data = {1, 2, 3, 4};
206-
std::map<std::string, std::string> encoding_attributes = {{"page_type", "DICTIONARY_PAGE"}};
206+
std::map<std::string, std::string> encoding_attributes = {{"page_type", "DICTIONARY_PAGE"}, {"dict_page_num_values", "1"}};
207207
auto result = agent.Encrypt(test_data, encoding_attributes);
208208

209209
ASSERT_NE(result, nullptr);

src/processing/encryption_sequencer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace {
6262
int64_t join_with_length_prefix_ns,
6363
int64_t compress_ns) {
6464

65-
std::cout << "+++++ DecodeAndEncrypt timings (microseconds + nanoseconds) +++++" << std::endl;
65+
std::cout << "----- DecodeAndEncrypt timings (microseconds + nanoseconds) -----" << std::endl;
6666
PrintDurationLine("DecompressAndSplit", decompress_and_split_ns);
6767
PrintDurationLine("ParseValueBytesIntoTypedList", parse_value_bytes_into_typed_list_ns);
6868
PrintDurationLine("EncryptValueList", encrypt_value_list_ns);
@@ -174,7 +174,7 @@ bool DataBatchEncryptionSequencer::DecodeAndEncrypt(tcb::span<const uint8_t> pla
174174

175175
// Decompress and split plaintext into level and value bytes
176176
auto stage_start = std::chrono::steady_clock::now();
177-
auto [level_bytes, value_bytes] = DecompressAndSplit(
177+
auto [level_bytes, value_bytes, num_elements] = DecompressAndSplit(
178178
plaintext, compression_, encoding_attributes_converted_);
179179
decompress_and_split_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
180180
std::chrono::steady_clock::now() - stage_start).count();
@@ -355,7 +355,7 @@ bool DataBatchEncryptionSequencer::ConvertEncodingAttributesToValues() {
355355
add_int("page_v2_num_nulls");
356356
add_bool("page_v2_is_compressed");
357357
} else if (page_type == "DICTIONARY_PAGE") {
358-
// DICTIONARY_PAGE has no specific encoding attributes
358+
add_int("dict_page_num_values");
359359
} else {
360360
throw InvalidInputException("Unexpected page type: " + page_type);
361361
}

0 commit comments

Comments
 (0)