Skip to content

Commit

Permalink
AVRO-2918: fix compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
clesaec committed Sep 12, 2023
1 parent 9c95d20 commit 575feb9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
7 changes: 5 additions & 2 deletions lang/java/avro/src/main/java/org/apache/avro/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,11 @@ public boolean hasChild() {
return this.childs != null && !(this.childs.isEmpty());
}

@Override
public Schema getParent() {
return null;
}

@Override
public Stream<Schema> visitHierarchy() {
final Stream<Schema> childsStream;
Expand Down Expand Up @@ -1188,8 +1193,6 @@ public boolean equals(Object o) {
if (!(o instanceof RecordSchema))
return false;
RecordSchema that = (RecordSchema) o;
if (!equalCachedHash(that))
return false;
if (!equalNames(that))
return false;
if (!propsEqual(that))
Expand Down
8 changes: 8 additions & 0 deletions lang/java/avro/src/test/java/org/apache/avro/TestSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,4 +644,12 @@ void add_types() {
assertNotNull(f1);
assertEquals(schemaRecord1, f1.schema());
}

@Test
void cycleRecord() {
String cycledSchema = " { \"type\": \"record\", \"name\": \"type1\", \n" + " \"fields\": [\n"
+ " { \"name\": \"f1\", \"type\": {\"type\": \"array\", \"items\": \"type1\" } }\n" + " ]\n" + " }";
Schema schema = new Schema.Parser().parse(cycledSchema);
Assertions.assertSame(schema, schema.getField("f1").schema().getElementType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1412,9 +1412,11 @@ public void setOutputCharacterEncoding(String outputCharacterEncoding) {
this.outputCharacterEncoding = outputCharacterEncoding;
}

public String getSchemaParentClass(boolean isError) {
if (isError) {
public String getSchemaParentClass(Schema schema) {
if (schema.isError()) {
return this.errorSpecificClass;
} else if (schema.getParent() != null) {
return schema.getParent().getFullName();
} else {
return this.recordSpecificClass;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ import org.apache.avro.message.SchemaStore;
@$annotation
#end
@org.apache.avro.specific.AvroGenerated
#if ($schema.class.simpleName == "ExtendedRecordSchema")
public class ${this.mangleTypeIdentifier($schema.getName())} extends ${schema.getParent().getFullName()} implements org.apache.avro.specific.SpecificRecord {
#else
public class ${this.mangleTypeIdentifier($schema.getName())} extends ${this.getSchemaParentClass($schema.isError())} implements org.apache.avro.specific.SpecificRecord {
#end
public class ${this.mangleTypeIdentifier($schema.getName())} extends ${this.getSchemaParentClass($schema)} implements org.apache.avro.specific.SpecificRecord {
private static final long serialVersionUID = ${this.fingerprint64($schema)}L;

#set ($schemaString = $this.javaSplit($schema.toString()))
Expand Down

0 comments on commit 575feb9

Please sign in to comment.