Skip to content

Commit

Permalink
AVRO-2918: include generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
clesaec committed Jul 6, 2023
1 parent bb84a43 commit 11c1657
Show file tree
Hide file tree
Showing 32 changed files with 1,283 additions and 920 deletions.
9 changes: 9 additions & 0 deletions lang/java/avro/src/main/java/org/apache/avro/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ public boolean hasChild() {
throw new AvroRuntimeException("Not a record: " + this);
}

public Schema getParent() {
throw new AvroRuntimeException("Not a record: " + this);
}

public Stream<Schema> visitHierarchy() {
throw new AvroRuntimeException("Not a record: " + this);
}
Expand Down Expand Up @@ -1190,6 +1194,11 @@ public ExtendedRecordSchema(RecordSchema parent, Name name, String doc, boolean
this.parent.addChild(this);
}

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

@Override
public List<Field> getFields() {
Stream<Field> parentFields = parent.hasFields() ? parent.getFields().stream() : Stream.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.ObjectOutput;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.nio.ByteBuffer;
import java.util.Arrays;
Expand Down Expand Up @@ -76,9 +77,13 @@ public class SpecificData extends GenericData {
private static final Function<Class<?>, SpecificData> MODEL_CACHE = new ClassValueCache<>(c -> {
Field specificDataField;
try {
specificDataField = c.getDeclaredField("MODEL$");
Field coderField = c.getDeclaredField("CODER");
coderField.setAccessible(true);
Object internal = coderField.get(null);
specificDataField = internal.getClass().getDeclaredField("MODEL$");
specificDataField.setAccessible(true);
return (SpecificData) specificDataField.get(null);
Object o = specificDataField.get(internal);
return (SpecificData) o;
} catch (NoSuchFieldException e) {
// Return default instance
return SpecificData.get();
Expand Down Expand Up @@ -416,15 +421,15 @@ else if (type instanceof ParameterizedType) {
Schema schema = names.get(fullName);
if (schema == null)
try {
schema = (Schema) (c.getDeclaredField("SCHEMA$").get(null));
schema = (Schema) (c.getDeclaredMethod("getClassSchema").invoke(null));

if (!fullName.equals(getClassName(schema)))
// HACK: schema mismatches class. maven shade plugin? try replacing.
schema = new Schema.Parser()
.parse(schema.toString().replace(schema.getNamespace(), c.getPackage().getName()));
} catch (NoSuchFieldException e) {
} catch (NoSuchMethodException e) {
throw new AvroRuntimeException("Not a Specific class: " + c);
} catch (IllegalAccessException e) {
} catch (IllegalAccessException | InvocationTargetException e) {
throw new AvroRuntimeException(e);
}
names.put(fullName, schema);
Expand Down
Loading

0 comments on commit 11c1657

Please sign in to comment.