Skip to content

Commit

Permalink
[AVRO-2943] Add new GenericData String/Utf8 ARRAY comparison test (#2137
Browse files Browse the repository at this point in the history
)

GenericRecord comparison already handles String vs Utf8 for ARRAY elements.
This just adds a unit test to explicitly verify the current correct behaviour.

Also renamed GenericData String/Utf8 MAP unit tests which were added
on #974 to improve
clarity on what those tests are actually verifying.

https://issues.apache.org/jira/browse/AVRO-2943
  • Loading branch information
frankgrimes97 committed Mar 13, 2023
1 parent 69974bc commit 5c0b17d
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ void testEquals() {
}

@Test
public void testMapKeyEquals() {
Schema mapSchema = new Schema.Parser().parse("{\"type\": \"map\", \"values\": \"string\"}");
Field myMapField = new Field("my_map", Schema.createMap(mapSchema), null, null);
public void testMapKeyEqualsStringAndUtf8Compatibility() {
Field myMapField = new Field("my_map", Schema.createMap(Schema.create(Schema.Type.STRING)), null, null);
Schema schema = Schema.createRecord("my_record", "doc", "mytest", false);
schema.setFields(Arrays.asList(myMapField));
GenericRecord r0 = new GenericData.Record(schema);
Expand All @@ -178,9 +177,8 @@ public void testMapKeyEquals() {
}

@Test
public void testMapValuesEquals() {
Schema mapSchema = new Schema.Parser().parse("{\"type\": \"map\", \"values\": \"string\"}");
Field myMapField = new Field("my_map", Schema.createMap(mapSchema), null, null);
public void testMapValuesEqualsStringAndUtf8Compatibility() {
Field myMapField = new Field("my_map", Schema.createMap(Schema.create(Schema.Type.STRING)), null, null);
Schema schema = Schema.createRecord("my_record", "doc", "mytest", false);
schema.setFields(Arrays.asList(myMapField));
GenericRecord r0 = new GenericData.Record(schema);
Expand All @@ -198,6 +196,24 @@ public void testMapValuesEquals() {
assertEquals(r1, r0);
}

@Test
public void testArrayValuesEqualsStringAndUtf8Compatibility() {
Field myArrayField = new Field("my_array", Schema.createArray(Schema.create(Schema.Type.STRING)), null, null);
Schema schema = Schema.createRecord("my_record", "doc", "mytest", false);
schema.setFields(Arrays.asList(myArrayField));
GenericRecord r0 = new GenericData.Record(schema);
GenericRecord r1 = new GenericData.Record(schema);

List<CharSequence> array1 = Arrays.asList("valueOne");
r0.put("my_array", array1);

List<CharSequence> array2 = Arrays.asList(new Utf8("valueOne"));
r1.put("my_array", array2);

assertEquals(r0, r1);
assertEquals(r1, r0);
}

private Schema recordSchema() {
List<Field> fields = new ArrayList<>();
fields.add(new Field("anArray", Schema.createArray(Schema.create(Type.STRING)), null, null));
Expand Down

0 comments on commit 5c0b17d

Please sign in to comment.