shangxinli commented on code in PR #374:
URL: https://github.com/apache/iceberg-cpp/pull/374#discussion_r2616477315
##########
src/iceberg/test/avro_test.cc:
##########
@@ -244,4 +246,234 @@ TEST_F(AvroReaderTest, AvroWriterNestedType) {
WriteAndVerify(schema, expected_string);
}
+// Comprehensive tests using in-memory MockFileIO
+
+TEST_F(AvroReaderTest, AllPrimitiveTypes) {
+ auto schema = std::make_shared<iceberg::Schema>(std::vector<SchemaField>{
+ SchemaField::MakeRequired(1, "bool_col",
std::make_shared<BooleanType>()),
+ SchemaField::MakeRequired(2, "int_col", std::make_shared<IntType>()),
+ SchemaField::MakeRequired(3, "long_col", std::make_shared<LongType>()),
+ SchemaField::MakeRequired(4, "float_col", std::make_shared<FloatType>()),
+ SchemaField::MakeRequired(5, "double_col",
std::make_shared<DoubleType>()),
+ SchemaField::MakeRequired(6, "string_col",
std::make_shared<StringType>()),
+ SchemaField::MakeRequired(7, "binary_col",
std::make_shared<BinaryType>())});
+
+ std::string expected_string = R"([
+ [true, 42, 1234567890, 3.14, 2.71828, "test", "AQID"],
+ [false, -100, -9876543210, -1.5, 0.0, "hello", "BAUG"]
+ ])";
+
+ WriteAndVerify(schema, expected_string);
+}
+
+// Skipping DecimalType test - requires specific decimal encoding in JSON
+
+TEST_F(AvroReaderTest, DateTimeTypes) {
+ auto schema = std::make_shared<iceberg::Schema>(std::vector<SchemaField>{
+ SchemaField::MakeRequired(1, "date_col", std::make_shared<DateType>()),
+ SchemaField::MakeRequired(2, "time_col", std::make_shared<TimeType>()),
+ SchemaField::MakeRequired(3, "timestamp_col",
std::make_shared<TimestampType>())});
+
+ // Dates as days since epoch, time/timestamps as microseconds
+ std::string expected_string = R"([
+ [18628, 43200000000, 1640995200000000],
+ [18629, 86399000000, 1641081599000000]
+ ])";
+
+ WriteAndVerify(schema, expected_string);
+}
+
+TEST_F(AvroReaderTest, NestedStruct) {
+ auto schema = std::make_shared<iceberg::Schema>(std::vector<SchemaField>{
+ SchemaField::MakeRequired(1, "id", std::make_shared<IntType>()),
+ SchemaField::MakeRequired(
+ 2, "person",
+ std::make_shared<iceberg::StructType>(std::vector<SchemaField>{
+ SchemaField::MakeRequired(3, "name",
std::make_shared<StringType>()),
+ SchemaField::MakeRequired(4, "age", std::make_shared<IntType>()),
+ SchemaField::MakeOptional(
+ 5, "address",
+
std::make_shared<iceberg::StructType>(std::vector<SchemaField>{
+ SchemaField::MakeRequired(6, "street",
+
std::make_shared<StringType>()),
+ SchemaField::MakeRequired(7, "city",
+
std::make_shared<StringType>())}))}))});
+
+ std::string expected_string = R"([
+ [1, ["Alice", 30, ["123 Main St", "NYC"]]],
+ [2, ["Bob", 25, ["456 Oak Ave", "LA"]]]
+ ])";
+
+ WriteAndVerify(schema, expected_string);
+}
+
+TEST_F(AvroReaderTest, ListType) {
+ auto schema = std::make_shared<iceberg::Schema>(std::vector<SchemaField>{
+ SchemaField::MakeRequired(1, "id", std::make_shared<IntType>()),
+ SchemaField::MakeRequired(2, "tags",
+
std::make_shared<ListType>(SchemaField::MakeRequired(
+ 3, "element",
std::make_shared<StringType>())))});
+
+ std::string expected_string = R"([
+ [1, ["tag1", "tag2", "tag3"]],
+ [2, ["foo", "bar"]],
+ [3, []]
+ ])";
+
+ WriteAndVerify(schema, expected_string);
+}
+
+TEST_F(AvroReaderTest, MapType) {
+ auto schema = std::make_shared<iceberg::Schema>(
+ std::vector<SchemaField>{SchemaField::MakeRequired(
+ 1, "properties",
+ std::make_shared<MapType>(
+ SchemaField::MakeRequired(2, "key",
std::make_shared<StringType>()),
+ SchemaField::MakeRequired(3, "value",
std::make_shared<IntType>())))});
+
+ std::string expected_string = R"([
+ [[["key1", 100], ["key2", 200]]],
+ [[["a", 1], ["b", 2], ["c", 3]]]
+ ])";
+
+ WriteAndVerify(schema, expected_string);
+}
+
+TEST_F(AvroReaderTest, ComplexNestedTypes) {
+ auto schema = std::make_shared<iceberg::Schema>(std::vector<SchemaField>{
+ SchemaField::MakeRequired(1, "id", std::make_shared<IntType>()),
+ SchemaField::MakeRequired(2, "nested_list",
+
std::make_shared<ListType>(SchemaField::MakeRequired(
+ 3, "element",
+
std::make_shared<ListType>(SchemaField::MakeRequired(
+ 4, "element",
std::make_shared<IntType>())))))});
+
+ std::string expected_string = R"([
+ [1, [[1, 2], [3, 4]]],
+ [2, [[5], [6, 7, 8]]]
+ ])";
+
+ WriteAndVerify(schema, expected_string);
+}
+
+TEST_F(AvroReaderTest, OptionalFieldsWithNulls) {
+ auto schema = std::make_shared<iceberg::Schema>(std::vector<SchemaField>{
+ SchemaField::MakeRequired(1, "id", std::make_shared<IntType>()),
+ SchemaField::MakeOptional(2, "name", std::make_shared<StringType>()),
+ SchemaField::MakeOptional(3, "age", std::make_shared<IntType>())});
+
+ std::string expected_string = R"([
+ [1, "Alice", 30],
+ [2, null, 25],
+ [3, "Charlie", null],
+ [4, null, null]
+ ])";
+
+ WriteAndVerify(schema, expected_string);
+}
+
+// Test both direct decoder and GenericDatum paths
+TEST_F(AvroReaderTest, DirectDecoderVsGenericDatum) {
Review Comment:
Converted the Avro tests to use parameterized tests as recommended. Created
AvroReaderParameterizedTest fixture and Converted 12 tests to TEST_P. Added
INSTANTIATE_TEST_SUITE_P and Removed DirectDecoderVsGenericDatum test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]