From e2849e775d21abe279b9e4661eeac59be466a3dd Mon Sep 17 00:00:00 2001 From: David Grossman Date: Fri, 26 Jan 2024 13:39:00 -0800 Subject: [PATCH] [schema builder] don't generate ref'ed arrays and maps (#545) --- .../input/SchemaWithClasspathImport.avsc | 17 +++++++++++++++++ .../codegen/SpecificRecordGeneratorUtil.java | 10 ++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/avro-builder/builder/src/test/resources/test-projects/classpath-project/input/SchemaWithClasspathImport.avsc b/avro-builder/builder/src/test/resources/test-projects/classpath-project/input/SchemaWithClasspathImport.avsc index 939a47040..6a6236ad7 100644 --- a/avro-builder/builder/src/test/resources/test-projects/classpath-project/input/SchemaWithClasspathImport.avsc +++ b/avro-builder/builder/src/test/resources/test-projects/classpath-project/input/SchemaWithClasspathImport.avsc @@ -7,6 +7,23 @@ { "name": "date", "type": "build.generated.SimpleRecord" + }, + { + "name": "unionArrayReference", + "type" :[ + "null", + { + "type": "array", + "items": "build.generated.SimpleRecord" + } + ] + }, + { + "name": "mapReference", + "type": { + "type": "map", + "values": "build.generated.SimpleRecord" + } } ] } diff --git a/avro-codegen/src/main/java/com/linkedin/avroutil1/codegen/SpecificRecordGeneratorUtil.java b/avro-codegen/src/main/java/com/linkedin/avroutil1/codegen/SpecificRecordGeneratorUtil.java index 9e9b219dd..66d3a1306 100644 --- a/avro-codegen/src/main/java/com/linkedin/avroutil1/codegen/SpecificRecordGeneratorUtil.java +++ b/avro-codegen/src/main/java/com/linkedin/avroutil1/codegen/SpecificRecordGeneratorUtil.java @@ -314,10 +314,16 @@ private static List getNestedInternalSchemaListForRecord(AvroRe }); break; case MAP: - schemaQueue.add(((AvroMapSchema) fieldSchema).getValueSchema()); + AvroMapSchema mapSchema = (AvroMapSchema) fieldSchema; + if (mapSchema.getValueSchemaOrRef().getRef() == null) { + schemaQueue.add(mapSchema.getValueSchema()); + } break; case ARRAY: - schemaQueue.add(((AvroArraySchema) fieldSchema).getValueSchema()); + AvroArraySchema arraySchema = (AvroArraySchema) fieldSchema; + if (arraySchema.getValueSchemaOrRef().getRef() == null) { + schemaQueue.add(arraySchema.getValueSchema()); + } break; } }