Skip to content

Commit 7207c19

Browse files
committed
test that verifies the default value bug
1 parent 9f8dfce commit 7207c19

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

coral-schema/src/test/java/com/linkedin/coral/schema/avro/SchemaUtilitiesTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,22 @@ public void testToNullableSchema() {
9090

9191
Assert.assertEquals(outputSchema.toString(true), TestUtils.loadSchema("testToNullableSchema-expected.avsc"));
9292
}
93+
94+
/**
95+
* Test that ToLowercaseSchemaVisitor properly lowercases field names in default values.
96+
* This test demonstrates the bug where complex default values (records, maps, arrays)
97+
* retain their original casing while the schema itself is lowercased.
98+
*/
99+
@Test
100+
public void testLowercaseSchemaWithComplexDefaultValues() {
101+
Schema inputSchema =
102+
AvroCompatibilityHelper.parse(TestUtils.loadSchema("testLowercaseSchemaWithDefaultValues-input.avsc"));
103+
Schema outputSchema = ToLowercaseSchemaVisitor.visit(inputSchema);
104+
105+
// Compare with expected output, trimming whitespace for comparison
106+
String expected = TestUtils.loadSchema("testLowercaseSchemaWithDefaultValues-expected.avsc").trim();
107+
String actual = outputSchema.toString(true).trim();
108+
109+
Assert.assertEquals(actual, expected);
110+
}
93111
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"type" : "record",
3+
"name" : "testrecord",
4+
"namespace" : "com.test",
5+
"fields" : [ {
6+
"name" : "simple_field",
7+
"type" : "int",
8+
"default" : 42
9+
}, {
10+
"name" : "struct_field",
11+
"type" : {
12+
"type" : "record",
13+
"name" : "nestedrecord",
14+
"fields" : [ {
15+
"name" : "firstname",
16+
"type" : "string"
17+
}, {
18+
"name" : "lastname",
19+
"type" : "string"
20+
}, {
21+
"name" : "age",
22+
"type" : "int"
23+
} ]
24+
},
25+
"default" : {
26+
"firstname" : "John",
27+
"lastname" : "Doe",
28+
"age" : 30
29+
}
30+
}, {
31+
"name" : "map_field",
32+
"type" : {
33+
"type" : "map",
34+
"values" : "string"
35+
},
36+
"default" : {
37+
"key_one" : "value1",
38+
"key_two" : "value2"
39+
}
40+
}, {
41+
"name" : "array_field",
42+
"type" : {
43+
"type" : "array",
44+
"items" : {
45+
"type" : "record",
46+
"name" : "arrayitem",
47+
"fields" : [ {
48+
"name" : "item_name",
49+
"type" : "string"
50+
} ]
51+
}
52+
},
53+
"default" : [ {
54+
"item_name" : "item1"
55+
}, {
56+
"item_name" : "item2"
57+
} ]
58+
} ]
59+
}
60+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"type" : "record",
3+
"name" : "TestRecord",
4+
"namespace" : "com.test",
5+
"fields" : [ {
6+
"name" : "Simple_Field",
7+
"type" : "int",
8+
"default" : 42
9+
}, {
10+
"name" : "Struct_Field",
11+
"type" : {
12+
"type" : "record",
13+
"name" : "NestedRecord",
14+
"fields" : [ {
15+
"name" : "firstName",
16+
"type" : "string"
17+
}, {
18+
"name" : "lastName",
19+
"type" : "string"
20+
}, {
21+
"name" : "Age",
22+
"type" : "int"
23+
} ]
24+
},
25+
"default" : {
26+
"firstName" : "John",
27+
"lastName" : "Doe",
28+
"Age" : 30
29+
}
30+
}, {
31+
"name" : "Map_Field",
32+
"type" : {
33+
"type" : "map",
34+
"values" : "string"
35+
},
36+
"default" : {
37+
"Key_One" : "value1",
38+
"Key_Two" : "value2"
39+
}
40+
}, {
41+
"name" : "Array_Field",
42+
"type" : {
43+
"type" : "array",
44+
"items" : {
45+
"type" : "record",
46+
"name" : "ArrayItem",
47+
"fields" : [ {
48+
"name" : "Item_Name",
49+
"type" : "string"
50+
} ]
51+
}
52+
},
53+
"default" : [ {
54+
"Item_Name" : "item1"
55+
}, {
56+
"Item_Name" : "item2"
57+
} ]
58+
} ]
59+
}
60+

0 commit comments

Comments
 (0)