diff --git a/src/client/dbps_api_client.cpp b/src/client/dbps_api_client.cpp index 210f0bb..a88483d 100644 --- a/src/client/dbps_api_client.cpp +++ b/src/client/dbps_api_client.cpp @@ -183,7 +183,7 @@ EncryptApiResponse DBPSApiClient::Encrypt( Type::type datatype, const std::optional& datatype_length, CompressionCodec::type compression, - Format::type format, + Encoding::type encoding, const std::map& encoding_attributes, CompressionCodec::type encrypted_compression, const std::string& key_id, @@ -195,7 +195,7 @@ EncryptApiResponse DBPSApiClient::Encrypt( json_request.datatype_ = datatype; json_request.datatype_length_ = datatype_length; json_request.compression_ = compression; - json_request.format_ = format; + json_request.encoding_ = encoding; json_request.encoding_attributes_ = encoding_attributes; json_request.encrypted_compression_ = encrypted_compression; json_request.key_id_ = key_id; @@ -265,7 +265,7 @@ DecryptApiResponse DBPSApiClient::Decrypt( Type::type datatype, const std::optional& datatype_length, CompressionCodec::type compression, - Format::type format, + Encoding::type encoding, const std::map& encoding_attributes, CompressionCodec::type encrypted_compression, const std::string& key_id, @@ -278,7 +278,7 @@ DecryptApiResponse DBPSApiClient::Decrypt( json_request.datatype_ = datatype; json_request.datatype_length_ = datatype_length; json_request.compression_ = compression; - json_request.format_ = format; + json_request.encoding_ = encoding; json_request.encoding_attributes_ = encoding_attributes; json_request.encrypted_compression_ = encrypted_compression; json_request.key_id_ = key_id; diff --git a/src/client/dbps_api_client.h b/src/client/dbps_api_client.h index 05bf3f0..150ee26 100644 --- a/src/client/dbps_api_client.h +++ b/src/client/dbps_api_client.h @@ -164,7 +164,7 @@ class DBPSApiClient { * @param column_name Name of the database column for which this data is being encrypted * @param datatype The data type of the plaintext (e.g., BYTE_ARRAY, STRING, etc.) * @param compression Compression algorithm used to compress the plaintext before this call (format of the input) - * @param format Data format specification (Parquet formats supported) + * @param encoding Data encoding specification (Parquet encodings supported) * @param encoding_attributes Map of string key-value pairs containing encoding-specific attributes * @param encrypted_compression Compression algorithm to be used to compress the encrypted data (format of the output) * @param key_id Identifier for the encryption key to be used (not the key itself) @@ -173,7 +173,7 @@ class DBPSApiClient { * * @return The encryption API response object containing comprehensive information about the call * - * @note Data types, compression types, and formats as defined in the enums.h file are supported + * @note Data types, compression types, and encodings as defined in the enums.h file are supported */ EncryptApiResponse Encrypt( span plaintext, @@ -181,7 +181,7 @@ class DBPSApiClient { Type::type datatype, const std::optional& datatype_length, CompressionCodec::type compression, - Format::type format, + Encoding::type encoding, const std::map& encoding_attributes, CompressionCodec::type encrypted_compression, const std::string& key_id, @@ -196,7 +196,7 @@ class DBPSApiClient { * @param column_name Name of the database column for which this data is being decrypted * @param datatype The data type of the original plaintext (e.g., BYTE_ARRAY, STRING, etc.) * @param compression Compression algorithm used to compress the encrypted data before this call (format of the input) - * @param format Data format specification (Parquet formats supported) + * @param encoding Data encoding specification (Parquet encodings supported) * @param encoding_attributes Map of string key-value pairs containing encoding-specific attributes * @param encrypted_compression Compression algorithm to be used to compress the decrypted data (format of the output) * @param key_id Identifier for the encryption key to be used for decryption (not the key itself) @@ -205,7 +205,7 @@ class DBPSApiClient { * * @return The decryption API response object containing comprehensive information about the call * - * @note Data types, compression types, and formats as defined in the enums.h file are supported + * @note Data types, compression types, and encodings as defined in the enums.h file are supported */ DecryptApiResponse Decrypt( span ciphertext, @@ -213,7 +213,7 @@ class DBPSApiClient { Type::type datatype, const std::optional& datatype_length, CompressionCodec::type compression, - Format::type format, + Encoding::type encoding, const std::map& encoding_attributes, CompressionCodec::type encrypted_compression, const std::string& key_id, diff --git a/src/client/dbps_api_client_test.cpp b/src/client/dbps_api_client_test.cpp index aa4e0a3..dd43a10 100644 --- a/src/client/dbps_api_client_test.cpp +++ b/src/client/dbps_api_client_test.cpp @@ -236,7 +236,7 @@ TEST(DBPSApiClient, DecryptApiResponseGetResponsePlaintextWithValidData) { json_response.decrypted_value_ = StringToBytes("test@example.com"); json_response.datatype_ = Type::BYTE_ARRAY; json_response.compression_ = CompressionCodec::UNCOMPRESSED; - json_response.format_ = Format::PLAIN; + json_response.encoding_ = Encoding::PLAIN; json_response.user_id_ = "test_user"; json_response.role_ = "test_role"; json_response.access_control_ = "test_access"; @@ -280,7 +280,7 @@ TEST(DBPSApiClient, EncryptWithValidData) { "value": "dGVzdEBleGFtcGxlLmNvbQ==", "value_format": { "compression": "UNCOMPRESSED", - "format": "PLAIN" + "encoding": "PLAIN" } }, "data_batch_encrypted": { @@ -325,7 +325,7 @@ TEST(DBPSApiClient, EncryptWithValidData) { Type::BYTE_ARRAY, // datatype std::nullopt, // datatype_length CompressionCodec::UNCOMPRESSED, // compression - Format::PLAIN, // format + Encoding::PLAIN, // encoding std::map{}, // encoding_attributes CompressionCodec::UNCOMPRESSED, // encrypted_compression "test_key_123", // key_id @@ -366,7 +366,7 @@ TEST(DBPSApiClient, DecryptWithValidData) { }, "value_format": { "compression": "UNCOMPRESSED", - "format": "PLAIN" + "encoding": "PLAIN" } }, "data_batch_encrypted": { @@ -388,7 +388,7 @@ TEST(DBPSApiClient, DecryptWithValidData) { "value": "dGVzdEBleGFtcGxlLmNvbQ==", "value_format": { "compression": "UNCOMPRESSED", - "format": "PLAIN" + "encoding": "PLAIN" } }, "access": { @@ -417,7 +417,7 @@ TEST(DBPSApiClient, DecryptWithValidData) { Type::BYTE_ARRAY, // datatype std::nullopt, // datatype_length CompressionCodec::UNCOMPRESSED, // compression - Format::PLAIN, // format + Encoding::PLAIN, // encoding std::map{}, // encoding_attributes CompressionCodec::UNCOMPRESSED, // encrypted_compression "test_key_123", // key_id @@ -464,7 +464,7 @@ TEST(DBPSApiClient, EncryptWithInvalidData) { Type::BYTE_ARRAY, // datatype std::nullopt, // datatype_length CompressionCodec::UNCOMPRESSED, // compression - Format::PLAIN, // format + Encoding::PLAIN, // encoding std::map{}, // encoding_attributes CompressionCodec::UNCOMPRESSED, // encrypted_compression "test_key_123", // key_id @@ -494,7 +494,7 @@ TEST(DBPSApiClient, DecryptWithInvalidData) { Type::BYTE_ARRAY, // datatype std::nullopt, // datatype_length CompressionCodec::UNCOMPRESSED, // compression - Format::PLAIN, // format + Encoding::PLAIN, // encoding std::map{}, // encoding_attributes CompressionCodec::UNCOMPRESSED, // encrypted_compression "test_key_123", // key_id @@ -521,7 +521,7 @@ TEST(DBPSApiClient, EncryptWithInvalidJsonResponse) { "value": "dGVzdEBleGFtcGxlLmNvbQ==", "value_format": { "compression": "UNCOMPRESSED", - "format": "PLAIN" + "encoding": "PLAIN" } }, "data_batch_encrypted": { @@ -560,7 +560,7 @@ TEST(DBPSApiClient, EncryptWithInvalidJsonResponse) { Type::BYTE_ARRAY, // datatype std::nullopt, // datatype_length CompressionCodec::UNCOMPRESSED, // compression - Format::PLAIN, // format + Encoding::PLAIN, // encoding std::map{}, // encoding_attributes CompressionCodec::UNCOMPRESSED, // encrypted_compression "test_key_123", // key_id @@ -585,7 +585,7 @@ TEST(DBPSApiClient, DecryptWithInvalidJsonResponse) { }, "value_format": { "compression": "UNCOMPRESSED", - "format": "PLAIN" + "encoding": "PLAIN" } }, "data_batch_encrypted": { @@ -626,7 +626,7 @@ TEST(DBPSApiClient, DecryptWithInvalidJsonResponse) { Type::BYTE_ARRAY, // datatype std::nullopt, // datatype_length CompressionCodec::UNCOMPRESSED, // compression - Format::PLAIN, // format + Encoding::PLAIN, // encoding std::map{}, // encoding_attributes CompressionCodec::UNCOMPRESSED, // encrypted_compression "test_key_123", // key_id @@ -653,7 +653,7 @@ TEST(DBPSApiClient, EncryptWithEncodingAttributes) { "value": "dGVzdEBleGFtcGxlLmNvbQ==", "value_format": { "compression": "UNCOMPRESSED", - "format": "PLAIN", + "encoding": "PLAIN", "encoding_attributes": { "page_type": "DATA_PAGE", "page_encoding": "PLAIN", @@ -709,7 +709,7 @@ TEST(DBPSApiClient, EncryptWithEncodingAttributes) { Type::BYTE_ARRAY, // datatype std::nullopt, // datatype_length CompressionCodec::UNCOMPRESSED, // compression - Format::PLAIN, // format + Encoding::PLAIN, // encoding encoding_attributes, // encoding_attributes CompressionCodec::UNCOMPRESSED, // encrypted_compression "test_key_123", // key_id diff --git a/src/common/dbpa_interface.h b/src/common/dbpa_interface.h index 726633c..4eb64be 100644 --- a/src/common/dbpa_interface.h +++ b/src/common/dbpa_interface.h @@ -123,7 +123,7 @@ class DBPS_EXPORT DataBatchProtectionAgentInterface { * Encrypts the provided plaintext data using the configured encryption parameters. * * @param plaintext Binary data to be encrypted, provided as a span of bytes - * @param encoding_attributes A map of string key-values. The plaintext is encoded with a type defined in enums.h Format::type. + * @param encoding_attributes A map of string key-values. The plaintext is encoded with a type defined in enums.h Encoding::type. * Each encoding type requires additional attributes to be properly decoded. These attributes are specified in the map so an * implementation can properly interpret and process the input text. * diff --git a/src/common/dbpa_interface_test.cpp b/src/common/dbpa_interface_test.cpp index 585d007..4c6263e 100644 --- a/src/common/dbpa_interface_test.cpp +++ b/src/common/dbpa_interface_test.cpp @@ -108,7 +108,7 @@ TEST(DBPAInterface, AgentEncryptDecrypt) { MockAgent agent; std::vector original = {10, 20, 30}; - std::map encoding_attributes = {{"format", "PLAIN"}}; + std::map encoding_attributes = {{"page_encoding", "PLAIN"}}; auto encrypted = agent.Encrypt(span(original.data(), original.size()), encoding_attributes); ASSERT_TRUE(encrypted->success()); diff --git a/src/common/dbpa_local.cpp b/src/common/dbpa_local.cpp index 1413678..338e0eb 100644 --- a/src/common/dbpa_local.cpp +++ b/src/common/dbpa_local.cpp @@ -179,9 +179,9 @@ std::unique_ptr LocalDataBatchProtectionAgent::Encrypt( return std::make_unique("initialization", *initialized_); } - // Extract page_encoding from encoding_attributes and convert to Format::type - auto format_opt = dbps::external::ExtractPageEncoding(encoding_attributes); - if (!format_opt.has_value()) { + // Extract page_encoding from encoding_attributes and convert to Encoding::type + auto encoding_opt = dbps::external::ExtractPageEncoding(encoding_attributes); + if (!encoding_opt.has_value()) { std::cerr << "ERROR: LocalDataBatchProtectionAgent::Encrypt() - page_encoding not found or invalid in encoding_attributes." << std::endl; return std::make_unique("parameter_validation", "page_encoding not found or invalid in encoding_attributes"); } @@ -192,7 +192,7 @@ std::unique_ptr LocalDataBatchProtectionAgent::Encrypt( datatype_, datatype_length_, compression_type_, - format_opt.value(), + encoding_opt.value(), encoding_attributes, compression_type_, column_key_id_, @@ -205,7 +205,7 @@ std::unique_ptr LocalDataBatchProtectionAgent::Encrypt( std::vector plaintext_vec(plaintext.begin(), plaintext.end()); // Call the sequencer to encrypt - bool encrypt_result = sequencer.ConvertAndEncrypt(plaintext_vec); + bool encrypt_result = sequencer.DecodeAndEncrypt(plaintext_vec); if (!encrypt_result) { std::cerr << "ERROR: LocalDataBatchProtectionAgent::Encrypt() - Encryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_ << std::endl; @@ -230,9 +230,9 @@ std::unique_ptr LocalDataBatchProtectionAgent::Decrypt( return std::make_unique("initialization", *initialized_); } - // Extract page_encoding from encoding_attributes and convert to Format::type - auto format_opt = dbps::external::ExtractPageEncoding(encoding_attributes); - if (!format_opt.has_value()) { + // Extract page_encoding from encoding_attributes and convert to Encoding::type + auto encoding_opt = dbps::external::ExtractPageEncoding(encoding_attributes); + if (!encoding_opt.has_value()) { std::cerr << "ERROR: LocalDataBatchProtectionAgent::Decrypt() - page_encoding not found or invalid in encoding_attributes." << std::endl; return std::make_unique("parameter_validation", "page_encoding not found or invalid in encoding_attributes"); } @@ -243,7 +243,7 @@ std::unique_ptr LocalDataBatchProtectionAgent::Decrypt( datatype_, datatype_length_, compression_type_, - format_opt.value(), + encoding_opt.value(), encoding_attributes, compression_type_, column_key_id_, @@ -256,7 +256,7 @@ std::unique_ptr LocalDataBatchProtectionAgent::Decrypt( std::vector ciphertext_vec(ciphertext.begin(), ciphertext.end()); // Call the sequencer to decrypt - bool decrypt_result = sequencer.ConvertAndDecrypt(ciphertext_vec); + bool decrypt_result = sequencer.DecryptAndEncode(ciphertext_vec); if (!decrypt_result) { std::cerr << "ERROR: LocalDataBatchProtectionAgent::Decrypt() - Decryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_ << std::endl; diff --git a/src/common/dbpa_remote.cpp b/src/common/dbpa_remote.cpp index 65e1142..e480fa5 100644 --- a/src/common/dbpa_remote.cpp +++ b/src/common/dbpa_remote.cpp @@ -258,9 +258,9 @@ std::unique_ptr RemoteDataBatchProtectionAgent::Encrypt(span(std::move(empty_response)); } - // Extract page_encoding from encoding_attributes and convert to Format::type - auto format_opt = ExtractPageEncoding(encoding_attributes); - if (!format_opt.has_value()) { + // Extract page_encoding from encoding_attributes and convert to Encoding::type + auto encoding_opt = ExtractPageEncoding(encoding_attributes); + if (!encoding_opt.has_value()) { std::cerr << "ERROR: RemoteDataBatchProtectionAgent::Encrypt() - page_encoding not found or invalid in encoding_attributes." << std::endl; auto empty_response = std::make_unique(); empty_response->SetApiClientError("page_encoding not found or invalid in encoding_attributes"); @@ -274,7 +274,7 @@ std::unique_ptr RemoteDataBatchProtectionAgent::Encrypt(span RemoteDataBatchProtectionAgent::Decrypt(span(std::move(empty_response)); } - // Extract page_encoding from encoding_attributes and convert to Format::type - auto format_opt = ExtractPageEncoding(encoding_attributes); - if (!format_opt.has_value()) { + // Extract page_encoding from encoding_attributes and convert to Encoding::type + auto encoding_opt = ExtractPageEncoding(encoding_attributes); + if (!encoding_opt.has_value()) { std::cerr << "ERROR: RemoteDataBatchProtectionAgent::Decrypt() - page_encoding not found or invalid in encoding_attributes." << std::endl; auto empty_response = std::make_unique(); empty_response->SetApiClientError("page_encoding not found or invalid in encoding_attributes"); @@ -330,7 +330,7 @@ std::unique_ptr RemoteDataBatchProtectionAgent::Decrypt(span RemoteDataBatchProtectionAgent::Decrypt(span ExtractUserId(const std::string& app_context) } /** - * Extract page_encoding from encoding_attributes map and convert to Format::type + * Extract page_encoding from encoding_attributes map and convert to Encoding::type * * @param encoding_attributes Map of encoding attribute key-value pairs - * @return Format::type value if page_encoding found and valid, std::nullopt otherwise + * @return Encoding::type value if page_encoding found and valid, std::nullopt otherwise * - * Expected key: "page_encoding" with value as string representation of Format enum + * Expected key: "page_encoding" with value as string representation of Encoding enum */ -inline std::optional ExtractPageEncoding(const std::map& encoding_attributes) { +inline std::optional ExtractPageEncoding(const std::map& encoding_attributes) { using namespace dbps::enum_utils; auto it = encoding_attributes.find("page_encoding"); if (it != encoding_attributes.end()) { const std::string& encoding_str = it->second; - auto format_opt = to_format_enum(encoding_str); - if (format_opt.has_value()) { - return format_opt.value(); + auto encoding_opt = to_encoding_enum(encoding_str); + if (encoding_opt.has_value()) { + return encoding_opt.value(); } else { std::cerr << "ERROR: ExtractPageEncoding() - Unknown page_encoding: " << encoding_str << std::endl; return std::nullopt; diff --git a/src/common/dbpa_utils_test.cpp b/src/common/dbpa_utils_test.cpp index 4f08e9d..8c767e1 100644 --- a/src/common/dbpa_utils_test.cpp +++ b/src/common/dbpa_utils_test.cpp @@ -87,7 +87,7 @@ TEST(DBPAUtilsTest, ExtractPageEncoding_ValidPlainEncoding) { auto result = ExtractPageEncoding(encoding_attributes); ASSERT_TRUE(result.has_value()); - EXPECT_EQ(result.value(), Format::PLAIN); + EXPECT_EQ(result.value(), Encoding::PLAIN); } TEST(DBPAUtilsTest, ExtractPageEncoding_ValidRLEEncoding) { @@ -95,7 +95,7 @@ TEST(DBPAUtilsTest, ExtractPageEncoding_ValidRLEEncoding) { auto result = ExtractPageEncoding(encoding_attributes); ASSERT_TRUE(result.has_value()); - EXPECT_EQ(result.value(), Format::RLE); + EXPECT_EQ(result.value(), Encoding::RLE); } TEST(DBPAUtilsTest, ExtractPageEncoding_ValidDeltaBinaryPackedEncoding) { @@ -103,7 +103,7 @@ TEST(DBPAUtilsTest, ExtractPageEncoding_ValidDeltaBinaryPackedEncoding) { auto result = ExtractPageEncoding(encoding_attributes); ASSERT_TRUE(result.has_value()); - EXPECT_EQ(result.value(), Format::DELTA_BINARY_PACKED); + EXPECT_EQ(result.value(), Encoding::DELTA_BINARY_PACKED); } TEST(DBPAUtilsTest, ExtractPageEncoding_WithOtherAttributes) { @@ -115,7 +115,7 @@ TEST(DBPAUtilsTest, ExtractPageEncoding_WithOtherAttributes) { auto result = ExtractPageEncoding(encoding_attributes); ASSERT_TRUE(result.has_value()); - EXPECT_EQ(result.value(), Format::PLAIN); + EXPECT_EQ(result.value(), Encoding::PLAIN); } TEST(DBPAUtilsTest, ExtractPageEncoding_MissingPageEncodingKey) { @@ -136,7 +136,7 @@ TEST(DBPAUtilsTest, ExtractPageEncoding_EmptyMap) { } TEST(DBPAUtilsTest, ExtractPageEncoding_InvalidEncodingValue) { - std::map encoding_attributes = {{"page_encoding", "INVALID_FORMAT"}}; + std::map encoding_attributes = {{"page_encoding", "INVALID_ENCODING"}}; auto result = ExtractPageEncoding(encoding_attributes); EXPECT_FALSE(result.has_value()); @@ -150,11 +150,11 @@ TEST(DBPAUtilsTest, ExtractPageEncoding_EmptyEncodingValue) { } TEST(DBPAUtilsTest, ExtractPageEncoding_CaseSensitivity) { - // Assuming the to_format_enum is case-sensitive + // Assuming the to_encoding_enum is case-sensitive std::map encoding_attributes = {{"page_encoding", "plain"}}; auto result = ExtractPageEncoding(encoding_attributes); - // This test depends on whether to_format_enum is case-sensitive + // This test depends on whether to_encoding_enum is case-sensitive // If it's case-sensitive, this should fail // Adjust expectation based on actual implementation EXPECT_FALSE(result.has_value()); diff --git a/src/common/enum_utils.cpp b/src/common/enum_utils.cpp index 184d411..049abf2 100644 --- a/src/common/enum_utils.cpp +++ b/src/common/enum_utils.cpp @@ -96,29 +96,29 @@ std::optional to_compression_enum(std::string_view s) { return lookup::from_string_impl(s, kCodecPairs); } -// For dbps::external::Format +// For dbps::external::Encoding namespace { -using F = ::dbps::external::Format::type; -inline constexpr std::array, 11> kFormatPairs{{ - {F::PLAIN, "PLAIN"}, - {F::PLAIN_DICTIONARY, "PLAIN_DICTIONARY"}, - {F::RLE, "RLE"}, - {F::BIT_PACKED, "BIT_PACKED"}, - {F::DELTA_BINARY_PACKED, "DELTA_BINARY_PACKED"}, - {F::DELTA_LENGTH_BYTE_ARRAY, "DELTA_LENGTH_BYTE_ARRAY"}, - {F::DELTA_BYTE_ARRAY, "DELTA_BYTE_ARRAY"}, - {F::RLE_DICTIONARY, "RLE_DICTIONARY"}, - {F::BYTE_STREAM_SPLIT, "BYTE_STREAM_SPLIT"}, - {F::UNDEFINED, "UNDEFINED"}, - {F::UNKNOWN, "UNKNOWN"}, +using E = ::dbps::external::Encoding::type; +inline constexpr std::array, 11> kEncodingPairs{{ + {E::PLAIN, "PLAIN"}, + {E::PLAIN_DICTIONARY, "PLAIN_DICTIONARY"}, + {E::RLE, "RLE"}, + {E::BIT_PACKED, "BIT_PACKED"}, + {E::DELTA_BINARY_PACKED, "DELTA_BINARY_PACKED"}, + {E::DELTA_LENGTH_BYTE_ARRAY, "DELTA_LENGTH_BYTE_ARRAY"}, + {E::DELTA_BYTE_ARRAY, "DELTA_BYTE_ARRAY"}, + {E::RLE_DICTIONARY, "RLE_DICTIONARY"}, + {E::BYTE_STREAM_SPLIT, "BYTE_STREAM_SPLIT"}, + {E::UNDEFINED, "UNDEFINED"}, + {E::UNKNOWN, "UNKNOWN"}, }}; } // anon -std::string_view to_string(F v) { - return lookup::to_string_impl(v, kFormatPairs); +std::string_view to_string(E v) { + return lookup::to_string_impl(v, kEncodingPairs); } -std::optional to_format_enum(std::string_view s) { - return lookup::from_string_impl(s, kFormatPairs); +std::optional to_encoding_enum(std::string_view s) { + return lookup::from_string_impl(s, kEncodingPairs); } } diff --git a/src/common/enum_utils.h b/src/common/enum_utils.h index 01904f6..06ca2cb 100644 --- a/src/common/enum_utils.h +++ b/src/common/enum_utils.h @@ -32,8 +32,8 @@ std::optional<::dbps::external::Type::type> to_datatype_enum(std::string_view s) std::string_view to_string(::dbps::external::CompressionCodec::type v); std::optional<::dbps::external::CompressionCodec::type> to_compression_enum(std::string_view s); -// For dbps::external::Format -std::string_view to_string(::dbps::external::Format::type v); -std::optional<::dbps::external::Format::type> to_format_enum(std::string_view s); +// For dbps::external::Encoding +std::string_view to_string(::dbps::external::Encoding::type v); +std::optional<::dbps::external::Encoding::type> to_encoding_enum(std::string_view s); } diff --git a/src/common/enum_utils_test.cpp b/src/common/enum_utils_test.cpp index 0f570b7..bfdade7 100644 --- a/src/common/enum_utils_test.cpp +++ b/src/common/enum_utils_test.cpp @@ -165,79 +165,78 @@ TEST(EnumUtils, CompressionCodecInvalidFromString) { ASSERT_FALSE(result.has_value()); } -// Test Format enum conversions -TEST(EnumUtils, FormatToStringConversion) { - ASSERT_EQ("PLAIN", std::string(to_string(Format::PLAIN))); - ASSERT_EQ("PLAIN_DICTIONARY", std::string(to_string(Format::PLAIN_DICTIONARY))); - ASSERT_EQ("RLE", std::string(to_string(Format::RLE))); - ASSERT_EQ("BIT_PACKED", std::string(to_string(Format::BIT_PACKED))); - ASSERT_EQ("DELTA_BINARY_PACKED", std::string(to_string(Format::DELTA_BINARY_PACKED))); - ASSERT_EQ("DELTA_LENGTH_BYTE_ARRAY", std::string(to_string(Format::DELTA_LENGTH_BYTE_ARRAY))); - ASSERT_EQ("DELTA_BYTE_ARRAY", std::string(to_string(Format::DELTA_BYTE_ARRAY))); - ASSERT_EQ("RLE_DICTIONARY", std::string(to_string(Format::RLE_DICTIONARY))); - ASSERT_EQ("BYTE_STREAM_SPLIT", std::string(to_string(Format::BYTE_STREAM_SPLIT))); - ASSERT_EQ("UNDEFINED", std::string(to_string(Format::UNDEFINED))); - ASSERT_EQ("UNKNOWN", std::string(to_string(Format::UNKNOWN))); +// Test Encoding enum conversions +TEST(EnumUtils, EncodingToStringConversion) { + ASSERT_EQ("PLAIN", std::string(to_string(Encoding::PLAIN))); + ASSERT_EQ("PLAIN_DICTIONARY", std::string(to_string(Encoding::PLAIN_DICTIONARY))); + ASSERT_EQ("RLE", std::string(to_string(Encoding::RLE))); + ASSERT_EQ("BIT_PACKED", std::string(to_string(Encoding::BIT_PACKED))); + ASSERT_EQ("DELTA_BINARY_PACKED", std::string(to_string(Encoding::DELTA_BINARY_PACKED))); + ASSERT_EQ("DELTA_LENGTH_BYTE_ARRAY", std::string(to_string(Encoding::DELTA_LENGTH_BYTE_ARRAY))); + ASSERT_EQ("DELTA_BYTE_ARRAY", std::string(to_string(Encoding::DELTA_BYTE_ARRAY))); + ASSERT_EQ("RLE_DICTIONARY", std::string(to_string(Encoding::RLE_DICTIONARY))); + ASSERT_EQ("BYTE_STREAM_SPLIT", std::string(to_string(Encoding::BYTE_STREAM_SPLIT))); + ASSERT_EQ("UNDEFINED", std::string(to_string(Encoding::UNDEFINED))); + ASSERT_EQ("UNKNOWN", std::string(to_string(Encoding::UNKNOWN))); } -TEST(EnumUtils, FormatFromStringConversion) { - auto result = to_format_enum("PLAIN"); +TEST(EnumUtils, EncodingFromStringConversion) { + auto result = to_encoding_enum("PLAIN"); ASSERT_TRUE(result.has_value()); - ASSERT_EQ(Format::PLAIN, result.value()); + ASSERT_EQ(Encoding::PLAIN, result.value()); - result = to_format_enum("PLAIN_DICTIONARY"); + result = to_encoding_enum("PLAIN_DICTIONARY"); ASSERT_TRUE(result.has_value()); - ASSERT_EQ(Format::PLAIN_DICTIONARY, result.value()); + ASSERT_EQ(Encoding::PLAIN_DICTIONARY, result.value()); - result = to_format_enum("RLE"); + result = to_encoding_enum("RLE"); ASSERT_TRUE(result.has_value()); - ASSERT_EQ(Format::RLE, result.value()); + ASSERT_EQ(Encoding::RLE, result.value()); - result = to_format_enum("BIT_PACKED"); + result = to_encoding_enum("BIT_PACKED"); ASSERT_TRUE(result.has_value()); - ASSERT_EQ(Format::BIT_PACKED, result.value()); + ASSERT_EQ(Encoding::BIT_PACKED, result.value()); - result = to_format_enum("DELTA_BINARY_PACKED"); + result = to_encoding_enum("DELTA_BINARY_PACKED"); ASSERT_TRUE(result.has_value()); - ASSERT_EQ(Format::DELTA_BINARY_PACKED, result.value()); + ASSERT_EQ(Encoding::DELTA_BINARY_PACKED, result.value()); - result = to_format_enum("DELTA_LENGTH_BYTE_ARRAY"); + result = to_encoding_enum("DELTA_LENGTH_BYTE_ARRAY"); ASSERT_TRUE(result.has_value()); - ASSERT_EQ(Format::DELTA_LENGTH_BYTE_ARRAY, result.value()); + ASSERT_EQ(Encoding::DELTA_LENGTH_BYTE_ARRAY, result.value()); - result = to_format_enum("DELTA_BYTE_ARRAY"); + result = to_encoding_enum("DELTA_BYTE_ARRAY"); ASSERT_TRUE(result.has_value()); - ASSERT_EQ(Format::DELTA_BYTE_ARRAY, result.value()); + ASSERT_EQ(Encoding::DELTA_BYTE_ARRAY, result.value()); - result = to_format_enum("RLE_DICTIONARY"); + result = to_encoding_enum("RLE_DICTIONARY"); ASSERT_TRUE(result.has_value()); - ASSERT_EQ(Format::RLE_DICTIONARY, result.value()); + ASSERT_EQ(Encoding::RLE_DICTIONARY, result.value()); - result = to_format_enum("BYTE_STREAM_SPLIT"); + result = to_encoding_enum("BYTE_STREAM_SPLIT"); ASSERT_TRUE(result.has_value()); - ASSERT_EQ(Format::BYTE_STREAM_SPLIT, result.value()); + ASSERT_EQ(Encoding::BYTE_STREAM_SPLIT, result.value()); - result = to_format_enum("UNDEFINED"); + result = to_encoding_enum("UNDEFINED"); ASSERT_TRUE(result.has_value()); - ASSERT_EQ(Format::UNDEFINED, result.value()); + ASSERT_EQ(Encoding::UNDEFINED, result.value()); - result = to_format_enum("UNKNOWN"); + result = to_encoding_enum("UNKNOWN"); ASSERT_TRUE(result.has_value()); - ASSERT_EQ(Format::UNKNOWN, result.value()); + ASSERT_EQ(Encoding::UNKNOWN, result.value()); } -TEST(EnumUtils, FormatInvalidFromString) { - auto result = to_format_enum("INVALID"); +TEST(EnumUtils, EncodingInvalidFromString) { + auto result = to_encoding_enum("INVALID"); ASSERT_FALSE(result.has_value()); - - result = to_format_enum("RAWC_DATA"); // missing underscore + result = to_encoding_enum("RAWC_DATA"); // missing underscore ASSERT_FALSE(result.has_value()); - result = to_format_enum(""); + result = to_encoding_enum(""); ASSERT_FALSE(result.has_value()); - result = to_format_enum("XML"); // common format + result = to_encoding_enum("XML"); // common encoding ASSERT_FALSE(result.has_value()); } @@ -275,17 +274,17 @@ TEST(EnumUtils, RoundTripCompressionCodecConversion) { } } -TEST(EnumUtils, RoundTripFormatConversion) { - // Test all Format enum values - Format::type formats[] = { - Format::PLAIN, Format::PLAIN_DICTIONARY, Format::RLE, Format::BIT_PACKED, Format::DELTA_BINARY_PACKED, Format::DELTA_LENGTH_BYTE_ARRAY, Format::DELTA_BYTE_ARRAY, Format::RLE_DICTIONARY, Format::BYTE_STREAM_SPLIT, Format::UNDEFINED, Format::UNKNOWN +TEST(EnumUtils, RoundTripEncodingConversion) { + // Test all Encoding enum values + Encoding::type encodings[] = { + Encoding::PLAIN, Encoding::PLAIN_DICTIONARY, Encoding::RLE, Encoding::BIT_PACKED, Encoding::DELTA_BINARY_PACKED, Encoding::DELTA_LENGTH_BYTE_ARRAY, Encoding::DELTA_BYTE_ARRAY, Encoding::RLE_DICTIONARY, Encoding::BYTE_STREAM_SPLIT, Encoding::UNDEFINED, Encoding::UNKNOWN }; - for (auto format : formats) { - auto str = to_string(format); - auto converted = to_format_enum(str); + for (auto encoding : encodings) { + auto str = to_string(encoding); + auto converted = to_encoding_enum(str); ASSERT_TRUE(converted.has_value()); - ASSERT_EQ(format, converted.value()); + ASSERT_EQ(encoding, converted.value()); } } @@ -294,7 +293,7 @@ TEST(EnumUtils, RoundTripFormatConversion) { TEST(EnumUtils, EmptyStringHandling) { ASSERT_FALSE(to_datatype_enum("").has_value()); ASSERT_FALSE(to_compression_enum("").has_value()); - ASSERT_FALSE(to_format_enum("").has_value()); + ASSERT_FALSE(to_encoding_enum("").has_value()); } TEST(EnumUtils, WhitespaceHandling) { @@ -336,11 +335,11 @@ TEST(EnumUtils, RuntimeEvaluation) { // Test runtime evaluation of the functions auto type_str = to_string(Type::BYTE_ARRAY); auto codec_str = to_string(CompressionCodec::BZ2); - auto format_str = to_string(Format::RLE); + auto encoding_str = to_string(Encoding::RLE); // Verify the results ASSERT_EQ("BYTE_ARRAY", std::string(type_str)); ASSERT_EQ("BZ2", std::string(codec_str)); - ASSERT_EQ("RLE", std::string(format_str)); + ASSERT_EQ("RLE", std::string(encoding_str)); } // Protection tests: ensure enum_utils stays in sync with enum definitions @@ -382,20 +381,20 @@ TEST(EnumUtils, CompressionCodecEnumCompleteness) { } } -TEST(EnumUtils, FormatEnumCompleteness) { - // Define all known Format enum values - Format::type all_formats[] = { - Format::PLAIN, Format::PLAIN_DICTIONARY, Format::RLE, Format::BIT_PACKED, Format::DELTA_BINARY_PACKED, Format::DELTA_LENGTH_BYTE_ARRAY, Format::DELTA_BYTE_ARRAY, Format::RLE_DICTIONARY, Format::BYTE_STREAM_SPLIT, Format::UNDEFINED, Format::UNKNOWN +TEST(EnumUtils, EncodingEnumCompleteness) { + // Define all known Encoding enum values + Encoding::type all_encodings[] = { + Encoding::PLAIN, Encoding::PLAIN_DICTIONARY, Encoding::RLE, Encoding::BIT_PACKED, Encoding::DELTA_BINARY_PACKED, Encoding::DELTA_LENGTH_BYTE_ARRAY, Encoding::DELTA_BYTE_ARRAY, Encoding::RLE_DICTIONARY, Encoding::BYTE_STREAM_SPLIT, Encoding::UNDEFINED, Encoding::UNKNOWN }; // Test that every enum value can be converted to string and back - for (auto format : all_formats) { - auto str = to_string(format); + for (auto encoding : all_encodings) { + auto str = to_string(encoding); ASSERT_TRUE(str != "UNKNOWN_ENUM"); // Should not return UNKNOWN_ENUM for valid enum - auto converted = to_format_enum(str); + auto converted = to_encoding_enum(str); ASSERT_TRUE(converted.has_value()); - ASSERT_EQ(format, converted.value()); + ASSERT_EQ(encoding, converted.value()); } } @@ -403,7 +402,7 @@ TEST(EnumUtils, StringUniqueness) { // Test that all string representations are unique std::set type_strings; std::set codec_strings; - std::set format_strings; + std::set encoding_strings; // Collect all Type strings Type::type all_types[] = { Type::BOOLEAN, Type::INT32, Type::INT64, Type::INT96, @@ -426,14 +425,14 @@ TEST(EnumUtils, StringUniqueness) { } ASSERT_EQ(10, codec_strings.size()); // All strings should be unique - // Collect all Format strings - Format::type all_formats[] = { - Format::PLAIN, Format::PLAIN_DICTIONARY, Format::RLE, Format::BIT_PACKED, Format::DELTA_BINARY_PACKED, Format::DELTA_LENGTH_BYTE_ARRAY, Format::DELTA_BYTE_ARRAY, Format::RLE_DICTIONARY, Format::BYTE_STREAM_SPLIT, Format::UNDEFINED, Format::UNKNOWN + // Collect all Encoding strings + Encoding::type all_encodings[] = { + Encoding::PLAIN, Encoding::PLAIN_DICTIONARY, Encoding::RLE, Encoding::BIT_PACKED, Encoding::DELTA_BINARY_PACKED, Encoding::DELTA_LENGTH_BYTE_ARRAY, Encoding::DELTA_BYTE_ARRAY, Encoding::RLE_DICTIONARY, Encoding::BYTE_STREAM_SPLIT, Encoding::UNDEFINED, Encoding::UNKNOWN }; - for (auto format : all_formats) { - format_strings.insert(std::string(to_string(format))); + for (auto encoding : all_encodings) { + encoding_strings.insert(std::string(to_string(encoding))); } - ASSERT_EQ(11, format_strings.size()); // All strings should be unique + ASSERT_EQ(11, encoding_strings.size()); // All strings should be unique } @@ -461,19 +460,19 @@ TEST(EnumUtils, CrossEnumStringCollision) { all_strings.insert(std::string(to_string(codec))); } - Format::type all_formats[] = { - Format::PLAIN, Format::PLAIN_DICTIONARY, Format::RLE, Format::BIT_PACKED, Format::DELTA_BINARY_PACKED, Format::DELTA_LENGTH_BYTE_ARRAY, Format::DELTA_BYTE_ARRAY, Format::RLE_DICTIONARY, Format::BYTE_STREAM_SPLIT, Format::UNDEFINED, Format::UNKNOWN + Encoding::type all_encodings[] = { + Encoding::PLAIN, Encoding::PLAIN_DICTIONARY, Encoding::RLE, Encoding::BIT_PACKED, Encoding::DELTA_BINARY_PACKED, Encoding::DELTA_LENGTH_BYTE_ARRAY, Encoding::DELTA_BYTE_ARRAY, Encoding::RLE_DICTIONARY, Encoding::BYTE_STREAM_SPLIT, Encoding::UNDEFINED, Encoding::UNKNOWN }; - for (auto format : all_formats) { - all_strings.insert(std::string(to_string(format))); + for (auto encoding : all_encodings) { + all_strings.insert(std::string(to_string(encoding))); } // Verify two equally named enums are handled correctly. ASSERT_EQ("UNDEFINED", std::string(to_string(Type::UNDEFINED))); - ASSERT_EQ("UNDEFINED", std::string(to_string(Format::UNDEFINED))); + ASSERT_EQ("UNDEFINED", std::string(to_string(Encoding::UNDEFINED))); // Total should be 9 + 10 + 11 = 30 unique strings, but we have 1 collision - // (Type::UNDEFINED and Format::UNDEFINED both map to "UNDEFINED") + // (Type::UNDEFINED and Encoding::UNDEFINED both map to "UNDEFINED") // So we expect 29 unique strings ASSERT_EQ(29, all_strings.size()); } diff --git a/src/common/enums.h b/src/common/enums.h index b038750..3aef5b4 100644 --- a/src/common/enums.h +++ b/src/common/enums.h @@ -53,11 +53,10 @@ struct CompressionCodec { }; }; -// Format for data values +// Encoding for data values // Intentionally similar to parquet::Encoding to ease mapping and for compatibility with a known enum. // Originally defined in Arrow codebase: arrow/blob/main/cpp/src/parquet/types.h -// TODO: Rename to Encoding to match parquet::Encoding (as a further cleanup) -struct Format { +struct Encoding { enum type { PLAIN = 0, PLAIN_DICTIONARY = 2, diff --git a/src/common/json_request.cpp b/src/common/json_request.cpp index 4fca4b9..be88e41 100644 --- a/src/common/json_request.cpp +++ b/src/common/json_request.cpp @@ -290,9 +290,9 @@ void JsonRequest::ParseCommon(const std::string& request_body) { compression_ = *enum_value; } } - if (auto parsed_value = SafeGetFromJsonPath(json_body, {"data_batch", "value_format", "format"})) { - if (auto enum_value = to_format_enum(*parsed_value)) { - format_ = *enum_value; + if (auto parsed_value = SafeGetFromJsonPath(json_body, {"data_batch", "value_format", "encoding"})) { + if (auto enum_value = to_encoding_enum(*parsed_value)) { + encoding_ = *enum_value; } } if (auto parsed_value = SafeGetFromJsonPath(json_body, {"data_batch_encrypted", "value_format", "compression"})) { @@ -337,7 +337,7 @@ bool JsonRequest::IsValid() const { return !column_name_.empty() && datatype_.has_value() && compression_.has_value() && - format_.has_value() && + encoding_.has_value() && encrypted_compression_.has_value() && !key_id_.empty() && !user_id_.empty() && @@ -352,7 +352,7 @@ std::string JsonRequest::GetValidationError() const { if (column_name_.empty()) missing_fields.push_back("column_reference.name"); if (!datatype_.has_value()) missing_fields.push_back("data_batch.datatype_info.datatype"); if (!compression_.has_value()) missing_fields.push_back("data_batch.value_format.compression"); - if (!format_.has_value()) missing_fields.push_back("data_batch.value_format.format"); + if (!encoding_.has_value()) missing_fields.push_back("data_batch.value_format.encoding"); if (!encrypted_compression_.has_value()) missing_fields.push_back("data_batch_encrypted.value_format.compression"); if (key_id_.empty()) missing_fields.push_back("encryption.key_id"); if (user_id_.empty()) missing_fields.push_back("access.user_id"); @@ -436,7 +436,7 @@ std::string EncryptJsonRequest::ToJsonString() const { crow::json::wvalue value_format; value_format["compression"] = std::string(to_string(compression_.value())); - value_format["format"] = std::string(to_string(format_.value())); + value_format["encoding"] = std::string(to_string(encoding_.value())); // Add encoding_attributes if not empty if (!encoding_attributes_.empty()) { @@ -542,7 +542,7 @@ std::string DecryptJsonRequest::ToJsonString() const { crow::json::wvalue value_format; value_format["compression"] = std::string(to_string(compression_.value())); - value_format["format"] = std::string(to_string(format_.value())); + value_format["encoding"] = std::string(to_string(encoding_.value())); // Add encoding_attributes if not empty if (!encoding_attributes_.empty()) { @@ -552,7 +552,7 @@ std::string DecryptJsonRequest::ToJsonString() const { } value_format["encoding_attributes"] = std::move(encoding_attrs); } - + data_batch["value_format"] = std::move(value_format); json["data_batch"] = std::move(data_batch); @@ -679,9 +679,9 @@ void DecryptJsonResponse::Parse(const std::string& response_body) { compression_ = *enum_value; } } - if (auto parsed_value = SafeGetFromJsonPath(json_body, {"data_batch", "value_format", "format"})) { - if (auto enum_value = to_format_enum(*parsed_value)) { - format_ = *enum_value; + if (auto parsed_value = SafeGetFromJsonPath(json_body, {"data_batch", "value_format", "encoding"})) { + if (auto enum_value = to_encoding_enum(*parsed_value)) { + encoding_ = *enum_value; } } if (auto parsed_value = SafeGetFromJsonPath(json_body, {"data_batch", "value"})) { @@ -790,7 +790,7 @@ bool DecryptJsonResponse::IsValid() const { return JsonResponse::IsValid() && datatype_.has_value() && compression_.has_value() && - format_.has_value() && + encoding_.has_value() && !decrypted_value_.empty() && datatype_length_valid; } @@ -807,7 +807,7 @@ std::string DecryptJsonResponse::GetValidationError() const { // Check decrypt-specific fields if (!datatype_.has_value()) missing_fields.push_back("data_batch.datatype_info.datatype"); if (!compression_.has_value()) missing_fields.push_back("data_batch.value_format.compression"); - if (!format_.has_value()) missing_fields.push_back("data_batch.value_format.format"); + if (!encoding_.has_value()) missing_fields.push_back("data_batch.value_format.encoding"); if (decrypted_value_.empty()) missing_fields.push_back("data_batch.value"); // Check for invalid datatype_length @@ -836,7 +836,7 @@ std::string DecryptJsonResponse::ToJsonString() const { crow::json::wvalue value_format; value_format["compression"] = std::string(to_string(compression_.value())); - value_format["format"] = std::string(to_string(format_.value())); + value_format["encoding"] = std::string(to_string(encoding_.value())); data_batch["value_format"] = std::move(value_format); json["data_batch"] = std::move(data_batch); diff --git a/src/common/json_request.h b/src/common/json_request.h index a6da527..5703b35 100644 --- a/src/common/json_request.h +++ b/src/common/json_request.h @@ -41,7 +41,7 @@ class JsonRequest { std::optional datatype_; std::optional datatype_length_; std::optional compression_; - std::optional format_; + std::optional encoding_; std::map encoding_attributes_; std::optional encrypted_compression_; std::string key_id_; @@ -291,7 +291,7 @@ class DecryptJsonResponse : public JsonResponse { std::optional datatype_; std::optional datatype_length_; std::optional compression_; - std::optional format_; + std::optional encoding_; std::vector decrypted_value_; /** diff --git a/src/common/json_request_test.cpp b/src/common/json_request_test.cpp index c218c93..8e3811b 100644 --- a/src/common/json_request_test.cpp +++ b/src/common/json_request_test.cpp @@ -95,7 +95,7 @@ const std::string VALID_ENCRYPT_JSON = R"({ "value": "dGVzdEBleGFtcGxlLmNvbQ==", "value_format": { "compression": "UNCOMPRESSED", - "format": "UNDEFINED" + "encoding": "UNDEFINED" } }, "data_batch_encrypted": { @@ -126,7 +126,7 @@ const std::string VALID_DECRYPT_JSON = R"({ }, "value_format": { "compression": "UNCOMPRESSED", - "format": "UNDEFINED" + "encoding": "UNDEFINED" } }, "data_batch_encrypted": { @@ -159,7 +159,7 @@ TEST(JsonRequest, JsonRequestValidParse) { ASSERT_EQ("email", request.column_name_); ASSERT_EQ(Type::BYTE_ARRAY, request.datatype_.value()); ASSERT_EQ(CompressionCodec::UNCOMPRESSED, request.compression_.value()); - ASSERT_EQ(Format::UNDEFINED, request.format_.value()); + ASSERT_EQ(Encoding::UNDEFINED, request.encoding_.value()); ASSERT_EQ(CompressionCodec::GZIP, request.encrypted_compression_.value()); ASSERT_EQ("key123", request.key_id_); ASSERT_EQ("user456", request.user_id_); @@ -185,7 +185,7 @@ TEST(JsonRequest, JsonRequestMissingRequiredFields) { ASSERT_EQ("email", request.column_name_); ASSERT_FALSE(request.datatype_.has_value()); ASSERT_FALSE(request.compression_.has_value()); - ASSERT_FALSE(request.format_.has_value()); + ASSERT_FALSE(request.encoding_.has_value()); ASSERT_FALSE(request.encrypted_compression_.has_value()); ASSERT_EQ("", request.key_id_); ASSERT_EQ("", request.user_id_); @@ -208,7 +208,7 @@ TEST(JsonRequest, JsonRequestInvalidJson) { ASSERT_EQ("", request.column_name_); ASSERT_FALSE(request.datatype_.has_value()); ASSERT_FALSE(request.compression_.has_value()); - ASSERT_FALSE(request.format_.has_value()); + ASSERT_FALSE(request.encoding_.has_value()); ASSERT_FALSE(request.encrypted_compression_.has_value()); ASSERT_EQ("", request.key_id_); ASSERT_EQ("", request.user_id_); @@ -228,7 +228,7 @@ TEST(JsonRequest, JsonRequestRequiredReferenceIdMissing) { }, "value_format": { "compression": "UNCOMPRESSED", - "format": "UNDEFINED" + "encoding": "UNDEFINED" } }, "data_batch_encrypted": { @@ -250,7 +250,7 @@ TEST(JsonRequest, JsonRequestRequiredReferenceIdMissing) { ASSERT_EQ("email", request.column_name_); ASSERT_EQ(Type::BYTE_ARRAY, request.datatype_.value()); ASSERT_EQ(CompressionCodec::UNCOMPRESSED, request.compression_.value()); - ASSERT_EQ(Format::UNDEFINED, request.format_.value()); + ASSERT_EQ(Encoding::UNDEFINED, request.encoding_.value()); ASSERT_EQ(CompressionCodec::GZIP, request.encrypted_compression_.value()); ASSERT_EQ("key123", request.key_id_); ASSERT_EQ("user456", request.user_id_); @@ -273,7 +273,7 @@ TEST(JsonRequest, EncryptJsonRequestValidParse) { ASSERT_EQ("email", request.column_name_); ASSERT_EQ(Type::BYTE_ARRAY, request.datatype_.value()); ASSERT_EQ(CompressionCodec::UNCOMPRESSED, request.compression_.value()); - ASSERT_EQ(Format::UNDEFINED, request.format_.value()); + ASSERT_EQ(Encoding::UNDEFINED, request.encoding_.value()); ASSERT_EQ(CompressionCodec::GZIP, request.encrypted_compression_.value()); ASSERT_EQ("key123", request.key_id_); ASSERT_EQ("user456", request.user_id_); @@ -297,7 +297,7 @@ TEST(JsonRequest, EncryptJsonRequestMissingValue) { }, "value_format": { "compression": "UNCOMPRESSED", - "format": "UNDEFINED" + "encoding": "UNDEFINED" } }, "data_batch_encrypted": { @@ -325,7 +325,7 @@ TEST(JsonRequest, EncryptJsonRequestMissingValue) { ASSERT_EQ("email", request.column_name_); ASSERT_EQ(Type::BYTE_ARRAY, request.datatype_.value()); ASSERT_EQ(CompressionCodec::UNCOMPRESSED, request.compression_.value()); - ASSERT_EQ(Format::UNDEFINED, request.format_.value()); + ASSERT_EQ(Encoding::UNDEFINED, request.encoding_.value()); ASSERT_EQ(CompressionCodec::GZIP, request.encrypted_compression_.value()); ASSERT_EQ("key123", request.key_id_); ASSERT_EQ("user456", request.user_id_); @@ -348,7 +348,7 @@ TEST(JsonRequest, DecryptJsonRequestValidParse) { ASSERT_EQ("email", request.column_name_); ASSERT_EQ(Type::BYTE_ARRAY, request.datatype_.value()); ASSERT_EQ(CompressionCodec::UNCOMPRESSED, request.compression_.value()); - ASSERT_EQ(Format::UNDEFINED, request.format_.value()); + ASSERT_EQ(Encoding::UNDEFINED, request.encoding_.value()); ASSERT_EQ(CompressionCodec::GZIP, request.encrypted_compression_.value()); ASSERT_EQ("key123", request.key_id_); ASSERT_EQ("user456", request.user_id_); @@ -376,7 +376,7 @@ TEST(JsonRequest, DecryptJsonRequestMissingEncryptedValue) { }, "value_format": { "compression": "UNCOMPRESSED", - "format": "UNDEFINED" + "encoding": "UNDEFINED" } }, "data_batch_encrypted": { @@ -404,7 +404,7 @@ TEST(JsonRequest, DecryptJsonRequestMissingEncryptedValue) { ASSERT_EQ("email", request.column_name_); ASSERT_EQ(Type::BYTE_ARRAY, request.datatype_.value()); ASSERT_EQ(CompressionCodec::UNCOMPRESSED, request.compression_.value()); - ASSERT_EQ(Format::UNDEFINED, request.format_.value()); + ASSERT_EQ(Encoding::UNDEFINED, request.encoding_.value()); ASSERT_EQ(CompressionCodec::GZIP, request.encrypted_compression_.value()); ASSERT_EQ("key123", request.key_id_); ASSERT_EQ("user456", request.user_id_); @@ -491,7 +491,7 @@ TEST(JsonRequest, EncryptJsonRequestWithEncodingAttributes) { "value": "dGVzdEBleGFtcGxlLmNvbQ==", "value_format": { "compression": "UNCOMPRESSED", - "format": "PLAIN", + "encoding": "PLAIN", "encoding_attributes": { "page_type": "DATA_PAGE", "page_encoding": "PLAIN", @@ -523,7 +523,7 @@ TEST(JsonRequest, EncryptJsonRequestWithEncodingAttributes) { ASSERT_EQ("email", request.column_name_); ASSERT_EQ(Type::BYTE_ARRAY, request.datatype_.value()); ASSERT_EQ(CompressionCodec::UNCOMPRESSED, request.compression_.value()); - ASSERT_EQ(Format::PLAIN, request.format_.value()); + ASSERT_EQ(Encoding::PLAIN, request.encoding_.value()); ASSERT_EQ(CompressionCodec::GZIP, request.encrypted_compression_.value()); ASSERT_EQ("key123", request.key_id_); ASSERT_EQ("user456", request.user_id_); @@ -546,7 +546,7 @@ TEST(JsonRequest, EncryptJsonRequestToJsonWithEncodingAttributes) { request.column_name_ = "email"; request.datatype_ = Type::BYTE_ARRAY; request.compression_ = CompressionCodec::UNCOMPRESSED; - request.format_ = Format::PLAIN; + request.encoding_ = Encoding::PLAIN; request.encrypted_compression_ = CompressionCodec::GZIP; request.key_id_ = "key123"; request.user_id_ = "user456"; @@ -631,7 +631,7 @@ const std::string VALID_DECRYPT_RESPONSE_JSON = R"({ "value": "dGVzdEBleGFtcGxlLmNvbQ==", "value_format": { "compression": "UNCOMPRESSED", - "format": "UNDEFINED" + "encoding": "UNDEFINED" } }, "access": { @@ -675,7 +675,7 @@ TEST(JsonRequest, DecryptJsonResponseValidParse) { ASSERT_EQ("ref789", response.reference_id_); ASSERT_EQ(Type::BYTE_ARRAY, response.datatype_.value()); ASSERT_EQ(CompressionCodec::UNCOMPRESSED, response.compression_.value()); - ASSERT_EQ(Format::UNDEFINED, response.format_.value()); + ASSERT_EQ(Encoding::UNDEFINED, response.encoding_.value()); ASSERT_EQ(StringToBinary("test@example.com"), response.decrypted_value_); ASSERT_TRUE(response.IsValid()); @@ -724,7 +724,7 @@ TEST(JsonRequest, DecryptJsonResponseMissingDecryptedValue) { "datatype_info": { "datatype": "BYTE_ARRAY" }, - "value_format": {"compression": "UNCOMPRESSED", "format": "UNDEFINED"} + "value_format": {"compression": "UNCOMPRESSED", "encoding": "UNDEFINED"} } })"); @@ -752,7 +752,7 @@ TEST(JsonRequest, DecryptJsonResponseMissingDatatype) { "debug": {"reference_id": "ref456"}, "data_batch": { "value": "ZGVjcnlwdGVkX2RhdGE=", - "value_format": {"compression": "UNCOMPRESSED", "format": "UNDEFINED"} + "value_format": {"compression": "UNCOMPRESSED", "encoding": "UNDEFINED"} } })"); @@ -794,7 +794,7 @@ TEST(JsonRequest, DecryptJsonResponseToJson) { response.reference_id_ = "ref456"; response.datatype_ = Type::BYTE_ARRAY; response.compression_ = CompressionCodec::UNCOMPRESSED; - response.format_ = Format::UNDEFINED; + response.encoding_ = Encoding::UNDEFINED; response.decrypted_value_ = StringToBinary("decrypted_data"); ASSERT_TRUE(response.IsValid()); @@ -855,7 +855,7 @@ TEST(JsonRequest, DatatypeLengthParsing) { "value": "SGVsbG8sIFdvcmxkIQ==", "value_format": { "compression": "UNCOMPRESSED", - "format": "PLAIN" + "encoding": "PLAIN" } }, "data_batch_encrypted": { @@ -901,7 +901,7 @@ TEST(JsonRequest, DatatypeLengthSerialization) { request.datatype_ = Type::FIXED_LEN_BYTE_ARRAY; request.datatype_length_ = 16; request.compression_ = CompressionCodec::UNCOMPRESSED; - request.format_ = Format::PLAIN; + request.encoding_ = Encoding::PLAIN; request.encrypted_compression_ = CompressionCodec::UNCOMPRESSED; request.key_id_ = "test_key_123"; request.value_ = StringToBinary("Hello, World!"); @@ -921,7 +921,7 @@ TEST(JsonRequest, JsonRequestInvalidDatatypeLength) { "datatype": "FIXED_LEN_BYTE_ARRAY", "length": "not_a_number" }, - "value_format": {"compression": "UNCOMPRESSED", "format": "UNDEFINED"} + "value_format": {"compression": "UNCOMPRESSED", "encoding": "UNDEFINED"} }, "data_batch_encrypted": {"value_format": {"compression": "GZIP"}}, "encryption": {"key_id": "key123"}, @@ -947,7 +947,7 @@ TEST(JsonRequest, DecryptJsonResponseInvalidDatatypeLength) { "datatype": "FIXED_LEN_BYTE_ARRAY", "length": "invalid_int" }, - "value_format": {"compression": "UNCOMPRESSED", "format": "UNDEFINED"}, + "value_format": {"compression": "UNCOMPRESSED", "encoding": "UNDEFINED"}, "value": "decrypted_data" } })"; diff --git a/src/server/dbps_api_server.cpp b/src/server/dbps_api_server.cpp index a342241..4585c03 100644 --- a/src/server/dbps_api_server.cpp +++ b/src/server/dbps_api_server.cpp @@ -170,7 +170,7 @@ int main(int argc, char* argv[]) { request.datatype_.value(), request.datatype_length_, request.compression_.value(), - request.format_.value(), + request.encoding_.value(), request.encoding_attributes_, request.encrypted_compression_.value(), request.key_id_, @@ -180,7 +180,7 @@ int main(int argc, char* argv[]) { ); try { - bool encrypt_result = sequencer.ConvertAndEncrypt(request.value_); + bool encrypt_result = sequencer.DecodeAndEncrypt(request.value_); if (!encrypt_result) { return CreateErrorResponse("Encryption failed: " + sequencer.error_stage_ + " - " + sequencer.error_message_); } @@ -244,7 +244,7 @@ int main(int argc, char* argv[]) { response.datatype_ = request.datatype_; response.datatype_length_ = request.datatype_length_; response.compression_ = request.compression_; - response.format_ = request.format_; + response.encoding_ = request.encoding_; // Use DataBatchEncryptionSequencer for actual decryption // It is safe to use value() because the request is validated above. @@ -253,7 +253,7 @@ int main(int argc, char* argv[]) { request.datatype_.value(), request.datatype_length_, request.compression_.value(), - request.format_.value(), + request.encoding_.value(), request.encoding_attributes_, request.encrypted_compression_.value(), request.key_id_, @@ -263,7 +263,7 @@ int main(int argc, char* argv[]) { ); try { - bool decrypt_result = sequencer.ConvertAndDecrypt(request.encrypted_value_); + bool decrypt_result = sequencer.DecryptAndEncode(request.encrypted_value_); if (!decrypt_result) { return CreateErrorResponse("Decryption failed: " + sequencer.error_stage_ + " - " + sequencer.error_message_); } diff --git a/src/server/encryption_sequencer.cpp b/src/server/encryption_sequencer.cpp index 4e25c3d..232861e 100644 --- a/src/server/encryption_sequencer.cpp +++ b/src/server/encryption_sequencer.cpp @@ -62,7 +62,7 @@ DataBatchEncryptionSequencer::DataBatchEncryptionSequencer( Type::type datatype, const std::optional& datatype_length, CompressionCodec::type compression, - Format::type format, + Encoding::type encoding, const std::map& encoding_attributes, CompressionCodec::type encrypted_compression, const std::string& key_id, @@ -73,7 +73,7 @@ DataBatchEncryptionSequencer::DataBatchEncryptionSequencer( datatype_(datatype), datatype_length_(datatype_length), compression_(compression), - format_(format), + encoding_(encoding), encoding_attributes_(encoding_attributes), encrypted_compression_(encrypted_compression), key_id_(key_id), @@ -88,7 +88,7 @@ DataBatchEncryptionSequencer::DataBatchEncryptionSequencer( Type::type datatype, const std::optional& datatype_length, CompressionCodec::type compression, - Format::type format, + Encoding::type encoding, const std::map& encoding_attributes, CompressionCodec::type encrypted_compression, const std::string& key_id, @@ -100,7 +100,7 @@ DataBatchEncryptionSequencer::DataBatchEncryptionSequencer( datatype_(datatype), datatype_length_(datatype_length), compression_(compression), - format_(format), + encoding_(encoding), encoding_attributes_(encoding_attributes), encrypted_compression_(encrypted_compression), key_id_(key_id), @@ -111,8 +111,7 @@ DataBatchEncryptionSequencer::DataBatchEncryptionSequencer( // Top level encryption/decryption methods. -// TODO: Rename this method so it captures better the flow of decompress/format and encrypt/decrypt operations. -bool DataBatchEncryptionSequencer::ConvertAndEncrypt(const std::vector& plaintext) { +bool DataBatchEncryptionSequencer::DecodeAndEncrypt(const std::vector& plaintext) { // Validate all parameters and key_id if (!ValidateParameters()) { return false; @@ -129,7 +128,7 @@ bool DataBatchEncryptionSequencer::ConvertAndEncrypt(const std::vector& /* * Note on try-catch block: - * - When fully done, ConvertAndEncrypt will support per-value encryption for all cases, except for + * - When fully done, DecodeAndEncrypt will support per-value encryption for all cases, except for * (1) BOOLEAN datatype and (2) RLE_DICTIONARY encoding. * - This try-catch block allows features to be developed incrementally until all features are * complete: Compressions, Encodings, Page types, Datatypes. @@ -143,7 +142,7 @@ bool DataBatchEncryptionSequencer::ConvertAndEncrypt(const std::vector& plaintext, compression_, encoding_attributes_converted_); // Parse value bytes into typed list - auto typed_list = ParseValueBytesIntoTypedList(value_bytes, datatype_, datatype_length_, format_); + auto typed_list = ParseValueBytesIntoTypedList(value_bytes, datatype_, datatype_length_, encoding_); // Encrypt the typed list and level bytes, then join them into a single encrypted byte vector. auto encrypted_value_bytes = encryptor_->EncryptValueList(typed_list); @@ -165,10 +164,10 @@ bool DataBatchEncryptionSequencer::ConvertAndEncrypt(const std::vector& const bool is_compression_supported = (compression_ == CompressionCodec::UNCOMPRESSED || compression_ == CompressionCodec::SNAPPY); - // Format: Only PLAIN is currently supported + // Encoding: Only PLAIN is currently supported // RLE_DICTIONARY is not supported for per-value encryption since the values are not present in the // `plaintext` data, only references to them. - const bool is_format_supported = (format_ == Format::PLAIN && format_ != Format::RLE_DICTIONARY); + const bool is_encoding_supported = (encoding_ == Encoding::PLAIN && encoding_ != Encoding::RLE_DICTIONARY); // Page type: All are supported (DATA_PAGE_V1, DATA_PAGE_V2, DICTIONARY_PAGE) const bool is_page_supported = true; @@ -177,7 +176,7 @@ bool DataBatchEncryptionSequencer::ConvertAndEncrypt(const std::vector& // BOOLEAN is not supported for per-value encryption and always defaults to per-block encryption. const bool is_datatype_supported = (datatype_ != Type::BOOLEAN); - if (is_compression_supported && is_format_supported && is_page_supported && is_datatype_supported) { + if (is_compression_supported && is_encoding_supported && is_page_supported && is_datatype_supported) { // All conditions are supported, therefore an DBPSUnsupportedException exception should not have happened. // Re-throw the exception. throw; @@ -199,8 +198,7 @@ bool DataBatchEncryptionSequencer::ConvertAndEncrypt(const std::vector& } } -// TODO: Rename this method so it captures better the flow of decompress/format and encrypt/decrypt operations. -bool DataBatchEncryptionSequencer::ConvertAndDecrypt(const std::vector& ciphertext) { +bool DataBatchEncryptionSequencer::DecryptAndEncode(const std::vector& ciphertext) { // Validate all parameters and key_id if (!ValidateParameters()) { return false; @@ -241,7 +239,7 @@ bool DataBatchEncryptionSequencer::ConvertAndDecrypt(const std::vector& auto typed_list = encryptor_->DecryptValueList(encrypted_value_bytes); // Convert the decrypted typed list back to value bytes - auto value_bytes = GetTypedListAsValueBytes(typed_list, datatype_, datatype_length_, format_); + auto value_bytes = GetTypedListAsValueBytes(typed_list, datatype_, datatype_length_, encoding_); // Join the decrypted level and value bytes, then compress to get plaintext decrypted_result_ = CompressAndJoin( diff --git a/src/server/encryption_sequencer.h b/src/server/encryption_sequencer.h index acf98fa..c08c4fa 100644 --- a/src/server/encryption_sequencer.h +++ b/src/server/encryption_sequencer.h @@ -48,7 +48,7 @@ using namespace dbps::external; * - Validates supported parameter combinations (uncompressed, base64, plain) * - Provides comprehensive error reporting with stage and message tracking * - * Supports all data types, compression types, and formats. + * Supports all data types, compression types, and encodings. * * The class takes constructor parameters that were previously public attributes in JsonRequest. */ @@ -71,7 +71,7 @@ class DataBatchEncryptionSequencer { Type::type datatype, const std::optional& datatype_length, CompressionCodec::type compression, - Format::type format, + Encoding::type encoding, const std::map& encoding_attributes, CompressionCodec::type encrypted_compression, const std::string& key_id, @@ -86,7 +86,7 @@ class DataBatchEncryptionSequencer { Type::type datatype, const std::optional& datatype_length, CompressionCodec::type compression, - Format::type format, + Encoding::type encoding, const std::map& encoding_attributes, CompressionCodec::type encrypted_compression, const std::string& key_id, @@ -103,8 +103,8 @@ class DataBatchEncryptionSequencer { ~DataBatchEncryptionSequencer() = default; // Main processing methods - bool ConvertAndEncrypt(const std::vector& plaintext); - bool ConvertAndDecrypt(const std::vector& ciphertext); + bool DecodeAndEncrypt(const std::vector& plaintext); + bool DecryptAndEncode(const std::vector& ciphertext); protected: // Parameters for encryption/decryption operations @@ -112,7 +112,7 @@ class DataBatchEncryptionSequencer { Type::type datatype_; std::optional datatype_length_; CompressionCodec::type compression_; - Format::type format_; + Encoding::type encoding_; std::map encoding_attributes_; CompressionCodec::type encrypted_compression_; std::string key_id_; @@ -136,7 +136,7 @@ class DataBatchEncryptionSequencer { /** * Performs comprehensive validation of all parameters and key_id. * Converts string parameters to enums, validates key_id, and checks supported combinations. - * Supports all data types, compression types, and formats. + * Supports all data types, compression types, and encodings. * Returns true if all validation passes, false otherwise. */ bool ValidateParameters(); diff --git a/src/server/encryption_sequencer_test.cpp b/src/server/encryption_sequencer_test.cpp index d55fa28..01eace5 100644 --- a/src/server/encryption_sequencer_test.cpp +++ b/src/server/encryption_sequencer_test.cpp @@ -33,7 +33,7 @@ using namespace dbps::external; // TODO: Move this to a common test utility file. // Methods that will pad byte arrays of strings (or pure bytes) with preceding // bytes that specify the array length. Needed because this is how Parquet -// formats their data. +// encodings represent their data. std::vector EncodeStringByteArray(const std::vector& strings) { std::vector result; for (const auto& str : strings) { @@ -79,14 +79,14 @@ class TestDataBatchEncryptionSequencer : public DataBatchEncryptionSequencer { Type::type datatype, const std::optional& datatype_length, CompressionCodec::type compression, - Format::type format, + Encoding::type encoding, const std::map& encoding_attributes, CompressionCodec::type encrypted_compression, const std::string& key_id, const std::string& user_id, const std::string& application_context, const std::map& encryption_metadata - ) : DataBatchEncryptionSequencer(column_name, datatype, datatype_length, compression, format, encoding_attributes, encrypted_compression, key_id, user_id, application_context, encryption_metadata) {} + ) : DataBatchEncryptionSequencer(column_name, datatype, datatype_length, compression, encoding, encoding_attributes, encrypted_compression, key_id, user_id, application_context, encryption_metadata) {} // Public access to protected methods bool TestConvertEncodingAttributesToValues() { @@ -107,7 +107,7 @@ TEST(EncryptionSequencer, EncryptionDecryption) { Type::BYTE_ARRAY, // datatype std::nullopt, // datatype_length CompressionCodec::UNCOMPRESSED, // compression - Format::PLAIN, // format + Encoding::PLAIN, // encoding {{"page_type", "DICTIONARY_PAGE"}}, // encoding_attributes (mostly empty for basic test) CompressionCodec::UNCOMPRESSED, // encrypted_compression "test_key_123", // key_id @@ -117,23 +117,23 @@ TEST(EncryptionSequencer, EncryptionDecryption) { ); // Test encryption - bool encrypt_result = sequencer.ConvertAndEncrypt(HELLO_WORLD_DATA); + bool encrypt_result = sequencer.DecodeAndEncrypt(HELLO_WORLD_DATA); ASSERT_TRUE(encrypt_result) << "Encryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; } // Test 2: Different key_id produces different encryption { DataBatchEncryptionSequencer sequencer1( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "key1", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "key1", "test_user", "{}", {} ); DataBatchEncryptionSequencer sequencer2( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "key2", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "key2", "test_user", "{}", {} ); - bool result1 = sequencer1.ConvertAndEncrypt(HELLO_WORLD_DATA); - bool result2 = sequencer2.ConvertAndEncrypt(HELLO_WORLD_DATA); + bool result1 = sequencer1.DecodeAndEncrypt(HELLO_WORLD_DATA); + bool result2 = sequencer2.DecodeAndEncrypt(HELLO_WORLD_DATA); ASSERT_TRUE(result1); ASSERT_TRUE(result2); @@ -142,16 +142,16 @@ TEST(EncryptionSequencer, EncryptionDecryption) { // Test 3: Same key_id produces consistent encryption { DataBatchEncryptionSequencer sequencer1( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "same_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "same_key", "test_user", "{}", {} ); DataBatchEncryptionSequencer sequencer2( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "same_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "same_key", "test_user", "{}", {} ); - bool result1 = sequencer1.ConvertAndEncrypt(HELLO_WORLD_DATA); - bool result2 = sequencer2.ConvertAndEncrypt(HELLO_WORLD_DATA); + bool result1 = sequencer1.DecodeAndEncrypt(HELLO_WORLD_DATA); + bool result2 = sequencer2.DecodeAndEncrypt(HELLO_WORLD_DATA); ASSERT_TRUE(result1); ASSERT_TRUE(result2); @@ -160,23 +160,23 @@ TEST(EncryptionSequencer, EncryptionDecryption) { // Test 4: Empty data encryption { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} ); // This should fail because empty input is rejected - bool result = sequencer.ConvertAndEncrypt(EMPTY_DATA); + bool result = sequencer.DecodeAndEncrypt(EMPTY_DATA); EXPECT_FALSE(result) << "Empty data encryption should have failed"; } // Test 5: Binary data encryption { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} ); // Binary data: 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 - bool result = sequencer.ConvertAndEncrypt(BINARY_DATA); + bool result = sequencer.DecodeAndEncrypt(BINARY_DATA); ASSERT_TRUE(result) << "Binary data encryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; } @@ -187,40 +187,40 @@ TEST(EncryptionSequencer, ParameterValidation) { // Test 1: Valid parameters, should succeed { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} ); - bool result = sequencer.ConvertAndEncrypt(HELLO_WORLD_DATA); + bool result = sequencer.DecodeAndEncrypt(HELLO_WORLD_DATA); ASSERT_TRUE(result) << "Valid parameters test failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; } // Test 2: Invalid compression (should succeed with warning) { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::GZIP, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::GZIP, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} ); - bool result = sequencer.ConvertAndEncrypt(HELLO_WORLD_DATA); + bool result = sequencer.DecodeAndEncrypt(HELLO_WORLD_DATA); ASSERT_TRUE(result); EXPECT_TRUE(sequencer.error_stage_.empty()); } - // Test 3: Undefined format is supported + // Test 3: Undefined encoding is supported { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::UNDEFINED, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::UNDEFINED, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} ); - bool result = sequencer.ConvertAndEncrypt(HELLO_WORLD_DATA); - ASSERT_TRUE(result) << "Format UNDEFINED should be supported: " << sequencer.error_message_; - EXPECT_TRUE(sequencer.error_stage_.empty()) << "Unexpected error stage for supported format: " << sequencer.error_stage_; + bool result = sequencer.DecodeAndEncrypt(HELLO_WORLD_DATA); + ASSERT_TRUE(result) << "Encoding UNDEFINED should be supported: " << sequencer.error_message_; + EXPECT_TRUE(sequencer.error_stage_.empty()) << "Unexpected error stage for supported encoding: " << sequencer.error_stage_; } - // Test 4: All formats now supported (including RLE) + // Test 4: All encodings now supported (including RLE) { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::RLE, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::RLE, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} ); - bool result = sequencer.ConvertAndEncrypt(HELLO_WORLD_DATA); - ASSERT_TRUE(result) << "Format RLE should now be supported: " << sequencer.error_message_; - EXPECT_TRUE(sequencer.error_stage_.empty()) << "Unexpected error stage for supported format (RLE): " << sequencer.error_stage_; + bool result = sequencer.DecodeAndEncrypt(HELLO_WORLD_DATA); + ASSERT_TRUE(result) << "Encoding RLE should now be supported: " << sequencer.error_message_; + EXPECT_TRUE(sequencer.error_stage_.empty()) << "Unexpected error stage for supported encoding (RLE): " << sequencer.error_stage_; } } @@ -230,9 +230,9 @@ TEST(EncryptionSequencer, InputValidation) { // Test 1: Empty plaintext { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} ); - bool result = sequencer.ConvertAndEncrypt(EMPTY_DATA); + bool result = sequencer.DecodeAndEncrypt(EMPTY_DATA); EXPECT_FALSE(result) << "Empty plaintext test should have failed"; EXPECT_EQ(sequencer.error_stage_, "validation") << "Wrong error stage for empty plaintext"; } @@ -240,9 +240,9 @@ TEST(EncryptionSequencer, InputValidation) { // Test 2: Empty ciphertext { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} ); - bool result = sequencer.ConvertAndDecrypt(EMPTY_DATA); + bool result = sequencer.DecryptAndEncode(EMPTY_DATA); EXPECT_FALSE(result) << "Empty ciphertext test should have failed"; EXPECT_EQ(sequencer.error_stage_, "validation") << "Wrong error stage for empty ciphertext"; } @@ -250,9 +250,9 @@ TEST(EncryptionSequencer, InputValidation) { // Test 3: Empty key_id { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "", "test_user", "{}", {} ); - bool result = sequencer.ConvertAndEncrypt(HELLO_WORLD_DATA); + bool result = sequencer.DecodeAndEncrypt(HELLO_WORLD_DATA); EXPECT_FALSE(result) << "Empty key_id test should have failed"; EXPECT_EQ(sequencer.error_stage_, "validation") << "Wrong error stage for empty key_id"; } @@ -260,10 +260,10 @@ TEST(EncryptionSequencer, InputValidation) { // Test 4: Missing encryption_metadata { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} // encryption_metadata, setting it to empty map. ); - bool result = sequencer.ConvertAndDecrypt(HELLO_WORLD_DATA); + bool result = sequencer.DecryptAndEncode(HELLO_WORLD_DATA); EXPECT_FALSE(result) << "Missing encryption_metadata test should have failed"; EXPECT_EQ(sequencer.error_stage_, "decrypt_version_check") << "Wrong error stage for missing encryption_metadata"; EXPECT_TRUE(sequencer.error_message_.find("encryption_metadata must contain key") != std::string::npos) << "Wrong error message for missing encryption_metadata"; @@ -272,10 +272,10 @@ TEST(EncryptionSequencer, InputValidation) { // Test 5: Incorrect encryption_metadata version { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {{"dbps_agent_version", "v0.09"}} // encryption_metadata, setting it to incorrect version. ); - bool result = sequencer.ConvertAndDecrypt(HELLO_WORLD_DATA); + bool result = sequencer.DecryptAndEncode(HELLO_WORLD_DATA); EXPECT_FALSE(result) << "Incorrect encryption_metadata version test should have failed"; EXPECT_EQ(sequencer.error_stage_, "decrypt_version_check") << "Wrong error stage for incorrect encryption_metadata version"; EXPECT_TRUE(sequencer.error_message_.find("must match") != std::string::npos) << "Wrong error message for incorrect encryption_metadata version"; @@ -288,16 +288,16 @@ TEST(EncryptionSequencer, RoundTripEncryption) { // Test 1: Basic round trip - "Hello, World!" { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key_123", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key_123", "test_user", "{}", {} ); // Encrypt - bool encrypt_result = sequencer.ConvertAndEncrypt(HELLO_WORLD_DATA); + bool encrypt_result = sequencer.DecodeAndEncrypt(HELLO_WORLD_DATA); ASSERT_TRUE(encrypt_result) << "Round trip encryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; // Decrypt the encrypted result - need encryption_metadata with dbps_agent_version ASSERT_TRUE(sequencer.encryption_metadata_.size() > 0 && sequencer.encryption_metadata_.at("dbps_agent_version").length() > 0); - bool decrypt_result = sequencer.ConvertAndDecrypt(sequencer.encrypted_result_); + bool decrypt_result = sequencer.DecryptAndEncode(sequencer.encrypted_result_); ASSERT_TRUE(decrypt_result) << "Round trip decryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; // Verify the decrypted result matches the original @@ -307,16 +307,16 @@ TEST(EncryptionSequencer, RoundTripEncryption) { // Test 2: Binary data round trip { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "binary_test_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "binary_test_key", "test_user", "{}", {} ); // Encrypt - bool encrypt_result = sequencer.ConvertAndEncrypt(BINARY_DATA); // Binary data: 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 + bool encrypt_result = sequencer.DecodeAndEncrypt(BINARY_DATA); // Binary data: 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 ASSERT_TRUE(encrypt_result) << "Binary round trip encryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; // Decrypt the encrypted result - need encryption_metadata with dbps_agent_version ASSERT_TRUE(sequencer.encryption_metadata_.size() > 0 && sequencer.encryption_metadata_.at("dbps_agent_version").length() > 0); - bool decrypt_result = sequencer.ConvertAndDecrypt(sequencer.encrypted_result_); + bool decrypt_result = sequencer.DecryptAndEncode(sequencer.encrypted_result_); ASSERT_TRUE(decrypt_result) << "Binary round trip decryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; // Verify the decrypted result matches the original @@ -326,18 +326,18 @@ TEST(EncryptionSequencer, RoundTripEncryption) { // Test 3: Single character round trip { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "single_char_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "single_char_key", "test_user", "{}", {} ); // "A" // Encrypt - bool encrypt_result = sequencer.ConvertAndEncrypt(SINGLE_CHAR_DATA); + bool encrypt_result = sequencer.DecodeAndEncrypt(SINGLE_CHAR_DATA); ASSERT_TRUE(encrypt_result) << "Single char round trip encryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; // Decrypt the encrypted result - need encryption_metadata with dbps_agent_version ASSERT_TRUE(sequencer.encryption_metadata_.size() > 0 && sequencer.encryption_metadata_.at("dbps_agent_version").length() > 0); - bool decrypt_result = sequencer.ConvertAndDecrypt(sequencer.encrypted_result_); + bool decrypt_result = sequencer.DecryptAndEncode(sequencer.encrypted_result_); ASSERT_TRUE(decrypt_result) << "Single char round trip decryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; // Verify the decrypted result matches the original @@ -347,15 +347,15 @@ TEST(EncryptionSequencer, RoundTripEncryption) { // Test 4: Different keys produce different encrypted results { DataBatchEncryptionSequencer sequencer1( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "key1", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "key1", "test_user", "{}", {} ); DataBatchEncryptionSequencer sequencer2( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "key2", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "key2", "test_user", "{}", {} ); - bool result1 = sequencer1.ConvertAndEncrypt(HELLO_WORLD_DATA); - bool result2 = sequencer2.ConvertAndEncrypt(HELLO_WORLD_DATA); + bool result1 = sequencer1.DecodeAndEncrypt(HELLO_WORLD_DATA); + bool result2 = sequencer2.DecodeAndEncrypt(HELLO_WORLD_DATA); ASSERT_TRUE(result1); ASSERT_TRUE(result2); @@ -366,8 +366,8 @@ TEST(EncryptionSequencer, RoundTripEncryption) { // But both should decrypt back to the same original - need encryption_metadata with dbps_agent_version ASSERT_TRUE(sequencer1.encryption_metadata_.size() > 0 && sequencer1.encryption_metadata_.at("dbps_agent_version").length() > 0); ASSERT_TRUE(sequencer2.encryption_metadata_.size() > 0 && sequencer2.encryption_metadata_.at("dbps_agent_version").length() > 0); - bool decrypt1 = sequencer1.ConvertAndDecrypt(sequencer1.encrypted_result_); - bool decrypt2 = sequencer2.ConvertAndDecrypt(sequencer2.encrypted_result_); + bool decrypt1 = sequencer1.DecryptAndEncode(sequencer1.encrypted_result_); + bool decrypt2 = sequencer2.DecryptAndEncode(sequencer2.encrypted_result_); ASSERT_TRUE(decrypt1); ASSERT_TRUE(decrypt2); @@ -382,10 +382,10 @@ TEST(EncryptionSequencer, ResultStorage) { // Test 1: Verify encrypted result is stored { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} ); - bool result = sequencer.ConvertAndEncrypt(HELLO_WORLD_DATA); + bool result = sequencer.DecodeAndEncrypt(HELLO_WORLD_DATA); ASSERT_TRUE(result) << "Result storage encryption test failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; // Verify encrypted_result_ is not empty and is different from input @@ -397,16 +397,16 @@ TEST(EncryptionSequencer, ResultStorage) { // Test 2: Verify decrypted result is stored { DataBatchEncryptionSequencer sequencer( - "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} + "test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {} ); // First encrypt something - bool encrypt_result = sequencer.ConvertAndEncrypt(HELLO_WORLD_DATA); + bool encrypt_result = sequencer.DecodeAndEncrypt(HELLO_WORLD_DATA); ASSERT_TRUE(encrypt_result) << "Result storage decryption test failed during encryption"; // Then decrypt it - need encryption_metadata with dbps_agent_version ASSERT_TRUE(sequencer.encryption_metadata_.size() > 0 && sequencer.encryption_metadata_.at("dbps_agent_version").length() > 0); - bool decrypt_result = sequencer.ConvertAndDecrypt(sequencer.encrypted_result_); + bool decrypt_result = sequencer.DecryptAndEncode(sequencer.encrypted_result_); ASSERT_TRUE(decrypt_result) << "Result storage decryption test failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; // Verify decrypted_result_ is not empty and matches original @@ -427,7 +427,7 @@ TEST(EncryptionSequencer, BooleanTypeUsesPerBlockEncryption) { Type::BOOLEAN, std::nullopt, CompressionCodec::UNCOMPRESSED, - Format::PLAIN, + Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", @@ -436,7 +436,7 @@ TEST(EncryptionSequencer, BooleanTypeUsesPerBlockEncryption) { {} ); - bool result = sequencer.ConvertAndEncrypt(boolean_data); + bool result = sequencer.DecodeAndEncrypt(boolean_data); ASSERT_TRUE(result) << "BOOLEAN encryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; // Verify per-block encryption mode as used. @@ -444,13 +444,13 @@ TEST(EncryptionSequencer, BooleanTypeUsesPerBlockEncryption) { EXPECT_EQ(sequencer.encryption_metadata_.at("encrypt_mode_dict_page"), "per_block"); // Verify round-trip works - bool decrypt_result = sequencer.ConvertAndDecrypt(sequencer.encrypted_result_); + bool decrypt_result = sequencer.DecryptAndEncode(sequencer.encrypted_result_); ASSERT_TRUE(decrypt_result) << "BOOLEAN decryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; EXPECT_EQ(sequencer.decrypted_result_, boolean_data); } -// Test RLE_DICTIONARY format uses per-block encryption (not per-value) -TEST(EncryptionSequencer, RleDictionaryFormatUsesPerBlockEncryption) { +// Test RLE_DICTIONARY encoding uses per-block encryption (not per-value) +TEST(EncryptionSequencer, RleDictionaryEncodingUsesPerBlockEncryption) { // RLE_DICTIONARY is not supported for per-value encryption since the values are not present in the data, only references to them std::vector rle_dict_data = {0x02, 0x00, 0x00, 0x00, 0x01}; // some RLE dictionary encoded data @@ -459,7 +459,7 @@ TEST(EncryptionSequencer, RleDictionaryFormatUsesPerBlockEncryption) { Type::INT32, std::nullopt, CompressionCodec::UNCOMPRESSED, - Format::RLE_DICTIONARY, + Encoding::RLE_DICTIONARY, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key", @@ -468,7 +468,7 @@ TEST(EncryptionSequencer, RleDictionaryFormatUsesPerBlockEncryption) { {} ); - bool result = sequencer.ConvertAndEncrypt(rle_dict_data); + bool result = sequencer.DecodeAndEncrypt(rle_dict_data); ASSERT_TRUE(result) << "RLE_DICTIONARY encryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; // Verify it used per-block encryption mode @@ -476,7 +476,7 @@ TEST(EncryptionSequencer, RleDictionaryFormatUsesPerBlockEncryption) { EXPECT_EQ(sequencer.encryption_metadata_.at("encrypt_mode_dict_page"), "per_block"); // Verify round-trip works - bool decrypt_result = sequencer.ConvertAndDecrypt(sequencer.encrypted_result_); + bool decrypt_result = sequencer.DecryptAndEncode(sequencer.encrypted_result_); ASSERT_TRUE(decrypt_result) << "RLE_DICTIONARY decryption failed: " << sequencer.error_stage_ << " - " << sequencer.error_message_; EXPECT_EQ(sequencer.decrypted_result_, rle_dict_data); } @@ -487,10 +487,10 @@ TEST(EncryptionSequencer, FixedLenByteArrayValidation) { // Helper function to test validation failure auto testValidationFailure = [&](const std::optional& datatype_length, const std::string& expected_msg) -> bool { DataBatchEncryptionSequencer sequencer( - "test_column", Type::FIXED_LEN_BYTE_ARRAY, datatype_length, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key_123", "test_user", "{}", {} + "test_column", Type::FIXED_LEN_BYTE_ARRAY, datatype_length, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key_123", "test_user", "{}", {} ); - bool result = sequencer.ConvertAndEncrypt(HELLO_WORLD_DATA); + bool result = sequencer.DecodeAndEncrypt(HELLO_WORLD_DATA); if (result) { std::cout << "ERROR: Should have failed validation" << std::endl; return false; @@ -511,8 +511,8 @@ TEST(EncryptionSequencer, FixedLenByteArrayValidation) { EXPECT_TRUE(testValidationFailure(0, "FIXED_LEN_BYTE_ARRAY datatype_length must be positive")); // Test valid case (should pass parameter validation) - DataBatchEncryptionSequencer sequencer("test_column", Type::FIXED_LEN_BYTE_ARRAY, 16, CompressionCodec::UNCOMPRESSED, Format::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key_123", "test_user", "{}", {}); - bool result = sequencer.ConvertAndEncrypt(FIXED_LEN_BYTE_ARRAY_DATA); + DataBatchEncryptionSequencer sequencer("test_column", Type::FIXED_LEN_BYTE_ARRAY, 16, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, {{"page_type", "DICTIONARY_PAGE"}}, CompressionCodec::UNCOMPRESSED, "test_key_123", "test_user", "{}", {}); + bool result = sequencer.DecodeAndEncrypt(FIXED_LEN_BYTE_ARRAY_DATA); if (!result && sequencer.error_stage_ == "parameter_validation") { ADD_FAILURE() << "Valid datatype_length should pass parameter validation"; @@ -552,7 +552,7 @@ TEST(EncryptionSequencer, ConvertEncodingAttributesToValues_Positive) { {"page_v2_is_compressed", "true"} }; - TestDataBatchEncryptionSequencer sequencer_v2("test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, attribs_v2, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {}); + TestDataBatchEncryptionSequencer sequencer_v2("test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, attribs_v2, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {}); ASSERT_TRUE(sequencer_v2.TestConvertEncodingAttributesToValues()) << "DATA_PAGE_V2 conversion failed: " << sequencer_v2.error_stage_ << " - " << sequencer_v2.error_message_; @@ -572,7 +572,7 @@ TEST(EncryptionSequencer, ConvertEncodingAttributesToValues_Positive) { {"page_v1_repetition_level_encoding", "BIT_PACKED"} }; - TestDataBatchEncryptionSequencer sequencer_v1("test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, attribs_v1, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {}); + TestDataBatchEncryptionSequencer sequencer_v1("test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, attribs_v1, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {}); ASSERT_TRUE(sequencer_v1.TestConvertEncodingAttributesToValues()) << "DATA_PAGE_V1 conversion failed: " << sequencer_v1.error_stage_ << " - " << sequencer_v1.error_message_; @@ -588,7 +588,7 @@ TEST(EncryptionSequencer, ConvertEncodingAttributesToValues_Negative) { // Test missing page_type std::map empty_attribs; - TestDataBatchEncryptionSequencer sequencer1("test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, empty_attribs, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {}); + TestDataBatchEncryptionSequencer sequencer1("test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, empty_attribs, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {}); EXPECT_FALSE(sequencer1.TestConvertEncodingAttributesToValues()); EXPECT_EQ(sequencer1.error_stage_, "encoding_attribute_conversion"); @@ -604,7 +604,7 @@ TEST(EncryptionSequencer, ConvertEncodingAttributesToValues_Negative) { {"page_v2_is_compressed", "true"} }; - TestDataBatchEncryptionSequencer sequencer2("test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, invalid_int, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {}); + TestDataBatchEncryptionSequencer sequencer2("test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, invalid_int, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {}); EXPECT_FALSE(sequencer2.TestConvertEncodingAttributesToValues()); EXPECT_EQ(sequencer2.error_stage_, "encoding_attribute_conversion"); @@ -620,7 +620,7 @@ TEST(EncryptionSequencer, ConvertEncodingAttributesToValues_Negative) { {"page_v2_is_compressed", "maybe"} }; - TestDataBatchEncryptionSequencer sequencer3("test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Format::PLAIN, invalid_bool, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {}); + TestDataBatchEncryptionSequencer sequencer3("test_column", Type::BYTE_ARRAY, std::nullopt, CompressionCodec::UNCOMPRESSED, Encoding::PLAIN, invalid_bool, CompressionCodec::UNCOMPRESSED, "test_key", "test_user", "{}", {}); EXPECT_FALSE(sequencer3.TestConvertEncodingAttributesToValues()); EXPECT_EQ(sequencer3.error_stage_, "encoding_attribute_conversion"); } diff --git a/src/server/parquet_utils.cpp b/src/server/parquet_utils.cpp index 9cc7905..ba7c076 100644 --- a/src/server/parquet_utils.cpp +++ b/src/server/parquet_utils.cpp @@ -143,17 +143,17 @@ std::vector SliceValueBytesIntoRawBytes( const std::vector& bytes, Type::type datatype, const std::optional& datatype_length, - Format::type format) { + Encoding::type encoding) { // RLE_DICTIONARY is not supported for per-value operations since the values themselves are not present in the data, // only references to them. - if (format == Format::RLE_DICTIONARY) { - throw DBPSUnsupportedException("Unsupported format: RLE_DICTIONARY is not supported for per-value operations " + if (encoding == Encoding::RLE_DICTIONARY) { + throw DBPSUnsupportedException("Unsupported encoding: RLE_DICTIONARY is not supported for per-value operations " "since values are not present in the data, only references to them."); } - if (format != Format::PLAIN) { - throw DBPSUnsupportedException("On SliceValueBytesIntoRawBytes, unsupported format: " + std::string(to_string(format))); + if (encoding != Encoding::PLAIN) { + throw DBPSUnsupportedException("On SliceValueBytesIntoRawBytes, unsupported encoding: " + std::string(to_string(encoding))); } // BOOLEAN: boolean values are bit-encoded and not expanded as bytes @@ -207,16 +207,16 @@ std::vector CombineRawBytesIntoValueBytes( const std::vector& elements, Type::type datatype, const std::optional& datatype_length, - Format::type format) { + Encoding::type encoding) { // RLE_DICTIONARY is not supported for per-value operations since the values themselves are not present in the data, // only references to them. - if (format == Format::RLE_DICTIONARY) { - throw DBPSUnsupportedException("Unsupported format: RLE_DICTIONARY is not supported for per-value operations"); + if (encoding == Encoding::RLE_DICTIONARY) { + throw DBPSUnsupportedException("Unsupported encoding: RLE_DICTIONARY is not supported for per-value operations"); } - if (format != Format::PLAIN) { - throw DBPSUnsupportedException("On CombineRawBytesIntoValueBytes, unsupported format: " + std::string(to_string(format))); + if (encoding != Encoding::PLAIN) { + throw DBPSUnsupportedException("On CombineRawBytesIntoValueBytes, unsupported encoding: " + std::string(to_string(encoding))); } // BOOLEAN: boolean values are bit-encoded and not expanded as bytes @@ -345,9 +345,9 @@ TypedListValues ParseValueBytesIntoTypedList( const std::vector& bytes, Type::type datatype, const std::optional& datatype_length, - Format::type format) { + Encoding::type encoding) { std::vector raw_values = - SliceValueBytesIntoRawBytes(bytes, datatype, datatype_length, format); + SliceValueBytesIntoRawBytes(bytes, datatype, datatype_length, encoding); return BuildTypedListFromRawBytes(datatype, raw_values); } @@ -355,7 +355,7 @@ std::vector GetTypedListAsValueBytes( const TypedListValues& list, Type::type datatype, const std::optional& datatype_length, - Format::type format) { + Encoding::type encoding) { std::vector raw_values = BuildRawBytesFromTypedListValues(list); - return CombineRawBytesIntoValueBytes(raw_values, datatype, datatype_length, format); + return CombineRawBytesIntoValueBytes(raw_values, datatype, datatype_length, encoding); } diff --git a/src/server/parquet_utils.h b/src/server/parquet_utils.h index f7abf5d..1616acc 100644 --- a/src/server/parquet_utils.h +++ b/src/server/parquet_utils.h @@ -48,14 +48,14 @@ int CalculateLevelBytesLength(const std::vector& raw, const AttributesMap& encoding_attribs); /** - * Slice a flat byte buffer into RawValueBytes elements according to datatype/format. + * Slice a flat byte buffer into RawValueBytes elements according to datatype/encoding. * This follows the Parquet specific encoding. */ std::vector SliceValueBytesIntoRawBytes( const std::vector& bytes, Type::type datatype, const std::optional& datatype_length, - Format::type format); + Encoding::type encoding); /** * Combine RawValueBytes elements back into a flat value-bytes buffer. @@ -64,7 +64,7 @@ std::vector CombineRawBytesIntoValueBytes( const std::vector& elements, Type::type datatype, const std::optional& datatype_length, - Format::type format); + Encoding::type encoding); /** * Decompresses and splits a Parquet page into level and value bytes. @@ -87,36 +87,36 @@ std::vector CompressAndJoin( const AttributesMap& encoding_attributes); /** - * Parse the value bytes into a typed list based on the data type and format. + * Parse the value bytes into a typed list based on the data type and encoding. * * @param bytes The value bytes to parse * @param datatype The data type of the values * @param datatype_length Optional length for fixed-length types (required for FIXED_LEN_BYTE_ARRAY) - * @param format The format of the data (currently only PLAIN is supported) + * @param encoding The encoding of the data (currently only PLAIN is supported) * @return TypedListValues containing the parsed values - * @throws DBPSUnsupportedException if format or datatype is unsupported + * @throws DBPSUnsupportedException if encoding or datatype is unsupported * @throws InvalidInputException if the data is invalid or malformed */ TypedListValues ParseValueBytesIntoTypedList( const std::vector& bytes, Type::type datatype, const std::optional& datatype_length, - Format::type format); + Encoding::type encoding); /** - * Convert a typed list back into value bytes based on the data type and format. + * Convert a typed list back into value bytes based on the data type and encoding. * This is the reverse operation of ParseValueBytesIntoTypedList. * * @param list The typed list to convert * @param datatype The data type of the values * @param datatype_length Optional length for fixed-length types (required for FIXED_LEN_BYTE_ARRAY) - * @param format The format of the data (currently only PLAIN is supported) + * @param encoding The encoding of the data (currently only PLAIN is supported) * @return std::vector containing the serialized value bytes - * @throws DBPSUnsupportedException if format or datatype is unsupported + * @throws DBPSUnsupportedException if encoding or datatype is unsupported * @throws InvalidInputException if the data is invalid or malformed */ std::vector GetTypedListAsValueBytes( const TypedListValues& list, Type::type datatype, const std::optional& datatype_length, - Format::type format); + Encoding::type encoding); diff --git a/src/server/parquet_utils_test.cpp b/src/server/parquet_utils_test.cpp index 4e9b388..e256a8b 100644 --- a/src/server/parquet_utils_test.cpp +++ b/src/server/parquet_utils_test.cpp @@ -163,7 +163,7 @@ TEST(ParquetUtils, ParseValueBytesIntoTypedList_INT32) { std::vector bytes(reinterpret_cast(values.data()), reinterpret_cast(values.data()) + values.size() * sizeof(int32_t)); - TypedListValues result = ParseValueBytesIntoTypedList(bytes, Type::INT32, std::nullopt, Format::PLAIN); + TypedListValues result = ParseValueBytesIntoTypedList(bytes, Type::INT32, std::nullopt, Encoding::PLAIN); auto* int32_values = std::get_if>(&result); ASSERT_NE(nullptr, int32_values); @@ -175,7 +175,7 @@ TEST(ParquetUtils, ParseValueBytesIntoTypedList_INT64) { std::vector bytes(reinterpret_cast(values.data()), reinterpret_cast(values.data()) + values.size() * sizeof(int64_t)); - TypedListValues result = ParseValueBytesIntoTypedList(bytes, Type::INT64, std::nullopt, Format::PLAIN); + TypedListValues result = ParseValueBytesIntoTypedList(bytes, Type::INT64, std::nullopt, Encoding::PLAIN); auto* int64_values = std::get_if>(&result); ASSERT_NE(nullptr, int64_values); @@ -195,7 +195,7 @@ TEST(ParquetUtils, ParseValueBytesIntoTypedList_BYTE_ARRAY) { reinterpret_cast(&len2) + sizeof(len2)); bytes.insert(bytes.end(), {'w', 'o', 'r', 'l', 'd'}); - TypedListValues result = ParseValueBytesIntoTypedList(bytes, Type::BYTE_ARRAY, std::nullopt, Format::PLAIN); + TypedListValues result = ParseValueBytesIntoTypedList(bytes, Type::BYTE_ARRAY, std::nullopt, Encoding::PLAIN); auto* string_values = std::get_if>(&result); ASSERT_NE(nullptr, string_values); @@ -207,7 +207,7 @@ TEST(ParquetUtils, ParseValueBytesIntoTypedList_BYTE_ARRAY) { TEST(ParquetUtils, ParseValueBytesIntoTypedList_FIXED_LEN_BYTE_ARRAY) { std::vector bytes = {'a', 'b', 'c', 'x', 'y', 'z'}; // Two 3-byte strings - TypedListValues result = ParseValueBytesIntoTypedList(bytes, Type::FIXED_LEN_BYTE_ARRAY, 3, Format::PLAIN); + TypedListValues result = ParseValueBytesIntoTypedList(bytes, Type::FIXED_LEN_BYTE_ARRAY, 3, Encoding::PLAIN); auto* string_values = std::get_if>(&result); ASSERT_NE(nullptr, string_values); @@ -216,28 +216,28 @@ TEST(ParquetUtils, ParseValueBytesIntoTypedList_FIXED_LEN_BYTE_ARRAY) { EXPECT_EQ("xyz", (*string_values)[1]); } -TEST(ParquetUtils, ParseValueBytesIntoTypedList_UnsupportedFormat) { +TEST(ParquetUtils, ParseValueBytesIntoTypedList_UnsupportedEncoding) { std::vector bytes = {0x01, 0x02, 0x03, 0x04}; - EXPECT_THROW(ParseValueBytesIntoTypedList(bytes, Type::INT32, std::nullopt, Format::RLE), + EXPECT_THROW(ParseValueBytesIntoTypedList(bytes, Type::INT32, std::nullopt, Encoding::RLE), DBPSUnsupportedException); } TEST(ParquetUtils, ParseValueBytesIntoTypedList_BOOLEAN_Throws) { // BOOLEAN type is not supported for per-value parsing std::vector bytes = {0xB4}; // 8 boolean values bit-packed - EXPECT_THROW(ParseValueBytesIntoTypedList(bytes, Type::BOOLEAN, std::nullopt, Format::PLAIN), + EXPECT_THROW(ParseValueBytesIntoTypedList(bytes, Type::BOOLEAN, std::nullopt, Encoding::PLAIN), DBPSUnsupportedException); } TEST(ParquetUtils, ParseValueBytesIntoTypedList_InvalidDataSize) { std::vector bytes = {0x01, 0x02, 0x03}; // 3 bytes, not divisible by sizeof(int32_t) - EXPECT_THROW(ParseValueBytesIntoTypedList(bytes, Type::INT32, std::nullopt, Format::PLAIN), + EXPECT_THROW(ParseValueBytesIntoTypedList(bytes, Type::INT32, std::nullopt, Encoding::PLAIN), InvalidInputException); } TEST(ParquetUtils, SliceValueBytesIntoRawBytes_INT32) { std::vector bytes = {0x04,0x03,0x02,0x01, 0x0D,0x0C,0x0B,0x0A}; - auto out = SliceValueBytesIntoRawBytes(bytes, Type::INT32, std::nullopt, Format::PLAIN); + auto out = SliceValueBytesIntoRawBytes(bytes, Type::INT32, std::nullopt, Encoding::PLAIN); ASSERT_EQ(out.size(), 2u); EXPECT_EQ(out[0], (std::vector{0x04,0x03,0x02,0x01})); EXPECT_EQ(out[1], (std::vector{0x0D,0x0C,0x0B,0x0A})); @@ -247,7 +247,7 @@ TEST(ParquetUtils, SliceValueBytesIntoRawBytes_BOOLEAN_Throws) { // BOOLEAN is bit-packed and not supported for per-value slicing std::vector bytes = {0xB4}; // 8 boolean values bit-packed EXPECT_THROW( - SliceValueBytesIntoRawBytes(bytes, Type::BOOLEAN, std::nullopt, Format::PLAIN), + SliceValueBytesIntoRawBytes(bytes, Type::BOOLEAN, std::nullopt, Encoding::PLAIN), DBPSUnsupportedException); } @@ -255,7 +255,7 @@ TEST(ParquetUtils, SliceValueBytesIntoRawBytes_BOOLEAN_MultipleBytes_Throws) { // Multiple bytes of boolean data std::vector bytes = {0xFF, 0x00, 0xAA, 0x55}; // 32 boolean values EXPECT_THROW( - SliceValueBytesIntoRawBytes(bytes, Type::BOOLEAN, std::nullopt, Format::PLAIN), + SliceValueBytesIntoRawBytes(bytes, Type::BOOLEAN, std::nullopt, Encoding::PLAIN), DBPSUnsupportedException); } @@ -265,7 +265,7 @@ TEST(ParquetUtils, SliceValueBytesIntoRawBytes_INT96) { 0x05,0x06,0x07,0x08, 0x09,0x0A,0x0B,0x0C }; - auto out = SliceValueBytesIntoRawBytes(bytes, Type::INT96, std::nullopt, Format::PLAIN); + auto out = SliceValueBytesIntoRawBytes(bytes, Type::INT96, std::nullopt, Encoding::PLAIN); ASSERT_EQ(out.size(), 1u); EXPECT_EQ(out[0], bytes); } @@ -277,7 +277,7 @@ TEST(ParquetUtils, SliceValueBytesIntoRawBytes_BYTE_ARRAY) { append_u32_le(bytes, 3); bytes.insert(bytes.end(), {'x','y','z'}); - auto out = SliceValueBytesIntoRawBytes(bytes, Type::BYTE_ARRAY, std::nullopt, Format::PLAIN); + auto out = SliceValueBytesIntoRawBytes(bytes, Type::BYTE_ARRAY, std::nullopt, Encoding::PLAIN); ASSERT_EQ(out.size(), 2u); EXPECT_EQ(out[0], (std::vector{'h','i'})); EXPECT_EQ(out[1], (std::vector{'x','y','z'})); @@ -286,21 +286,21 @@ TEST(ParquetUtils, SliceValueBytesIntoRawBytes_BYTE_ARRAY) { TEST(ParquetUtils, SliceValueBytesIntoRawBytes_BYTE_ARRAY_Truncated) { std::vector bytes = {0x04,0x00,0x00,0x00, 'a','b','c'}; EXPECT_THROW( - SliceValueBytesIntoRawBytes(bytes, Type::BYTE_ARRAY, std::nullopt, Format::PLAIN), + SliceValueBytesIntoRawBytes(bytes, Type::BYTE_ARRAY, std::nullopt, Encoding::PLAIN), InvalidInputException); } TEST(ParquetUtils, SliceValueBytesIntoRawBytes_FixedSizeMisaligned) { std::vector bytes = {0x00,0x01,0x02}; // not divisible by 8 for INT64 EXPECT_THROW( - SliceValueBytesIntoRawBytes(bytes, Type::INT64, std::nullopt, Format::PLAIN), + SliceValueBytesIntoRawBytes(bytes, Type::INT64, std::nullopt, Encoding::PLAIN), InvalidInputException); } -TEST(ParquetUtils, SliceValueBytesIntoRawBytes_UnsupportedFormat) { +TEST(ParquetUtils, SliceValueBytesIntoRawBytes_UnsupportedEncoding) { std::vector bytes = {0x01,0x00,0x00,0x00}; EXPECT_THROW( - SliceValueBytesIntoRawBytes(bytes, Type::INT32, std::nullopt, Format::RLE), + SliceValueBytesIntoRawBytes(bytes, Type::INT32, std::nullopt, Encoding::RLE), DBPSUnsupportedException); } @@ -309,7 +309,7 @@ TEST(ParquetUtils, CombineRawBytesIntoValueBytes_INT32) { {0x04,0x03,0x02,0x01}, {0x0D,0x0C,0x0B,0x0A} }; - auto out = CombineRawBytesIntoValueBytes(elems, Type::INT32, std::nullopt, Format::PLAIN); + auto out = CombineRawBytesIntoValueBytes(elems, Type::INT32, std::nullopt, Encoding::PLAIN); EXPECT_EQ(out, (std::vector{0x04,0x03,0x02,0x01, 0x0D,0x0C,0x0B,0x0A})); } @@ -320,7 +320,7 @@ TEST(ParquetUtils, CombineRawBytesIntoValueBytes_BOOLEAN_Throws) { {0x00} }; EXPECT_THROW( - CombineRawBytesIntoValueBytes(elems, Type::BOOLEAN, std::nullopt, Format::PLAIN), + CombineRawBytesIntoValueBytes(elems, Type::BOOLEAN, std::nullopt, Encoding::PLAIN), DBPSUnsupportedException); } @@ -328,7 +328,7 @@ TEST(ParquetUtils, CombineRawBytesIntoValueBytes_BOOLEAN_EmptyInput_Throws) { // Even empty input should throw for BOOLEAN type std::vector elems; EXPECT_THROW( - CombineRawBytesIntoValueBytes(elems, Type::BOOLEAN, std::nullopt, Format::PLAIN), + CombineRawBytesIntoValueBytes(elems, Type::BOOLEAN, std::nullopt, Encoding::PLAIN), DBPSUnsupportedException); } @@ -337,7 +337,7 @@ TEST(ParquetUtils, CombineRawBytesIntoValueBytes_BYTE_ARRAY) { {'h','i'}, {'x','y','z'} }; - auto out = CombineRawBytesIntoValueBytes(elems, Type::BYTE_ARRAY, std::nullopt, Format::PLAIN); + auto out = CombineRawBytesIntoValueBytes(elems, Type::BYTE_ARRAY, std::nullopt, Encoding::PLAIN); // Expect [len=2][hi][len=3][xyz] std::vector expected; append_u32_le(expected, 2); @@ -354,16 +354,16 @@ TEST(ParquetUtils, CombineRawBytesIntoValueBytes_FIXED_LEN_BYTE_ARRAY_SizeMismat {'x','y','z'} }; EXPECT_THROW( - CombineRawBytesIntoValueBytes(elems, Type::FIXED_LEN_BYTE_ARRAY, 3, Format::PLAIN), + CombineRawBytesIntoValueBytes(elems, Type::FIXED_LEN_BYTE_ARRAY, 3, Encoding::PLAIN), InvalidInputException); } -TEST(ParquetUtils, CombineRawBytesIntoValueBytes_UnsupportedFormat) { +TEST(ParquetUtils, CombineRawBytesIntoValueBytes_UnsupportedEncoding) { std::vector elems = { {0x04,0x03,0x02,0x01} }; EXPECT_THROW( - CombineRawBytesIntoValueBytes(elems, Type::INT32, std::nullopt, Format::RLE), + CombineRawBytesIntoValueBytes(elems, Type::INT32, std::nullopt, Encoding::RLE), DBPSUnsupportedException); } @@ -373,8 +373,8 @@ TEST(ParquetUtils, SliceAndCombine_RoundTrip_INT64) { 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; - auto sliced = SliceValueBytesIntoRawBytes(bytes, Type::INT64, std::nullopt, Format::PLAIN); - auto combined = CombineRawBytesIntoValueBytes(sliced, Type::INT64, std::nullopt, Format::PLAIN); + auto sliced = SliceValueBytesIntoRawBytes(bytes, Type::INT64, std::nullopt, Encoding::PLAIN); + auto combined = CombineRawBytesIntoValueBytes(sliced, Type::INT64, std::nullopt, Encoding::PLAIN); EXPECT_EQ(bytes, combined); } @@ -386,8 +386,8 @@ TEST(ParquetUtils, SliceAndCombine_RoundTrip_BYTE_ARRAY) { append_u32_le(bytes, 4); bytes.insert(bytes.end(), {'b','a','r','!'}); - auto sliced = SliceValueBytesIntoRawBytes(bytes, Type::BYTE_ARRAY, std::nullopt, Format::PLAIN); - auto combined = CombineRawBytesIntoValueBytes(sliced, Type::BYTE_ARRAY, std::nullopt, Format::PLAIN); + auto sliced = SliceValueBytesIntoRawBytes(bytes, Type::BYTE_ARRAY, std::nullopt, Encoding::PLAIN); + auto combined = CombineRawBytesIntoValueBytes(sliced, Type::BYTE_ARRAY, std::nullopt, Encoding::PLAIN); EXPECT_EQ(bytes, combined); }