[
https://issues.apache.org/jira/browse/AVRO-1285?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14527491#comment-14527491
]
Zoltan Farkas commented on AVRO-1285:
-------------------------------------
I have written a relative simple self contained recursive schema:
{"type":"record","name":"SampleNode","namespace":"org.spf4j.ssdump2.avro",
"fields":[
{"name":"count","type":"int","default":0},
{"name":"subNodes","type":
{"type":"array","items":{
"type":"record","name":"SamplePair",
"fields":[
{"name":"method","type":
{"type":"record","name":"Method",
"fields":[
{"name":"declaringClass","type":{"type":"string","avro.java.string":"String"}},
{"name":"methodName","type":{"type":"string","avro.java.string":"String"}}
]}},
{"name":"node","type":"SampleNode"}]}}}]}
Attempting to serialize/deserialize a SampleNode object generated from this
schema fails with a NPE in Parser.java:86
here is the serialization/deserialization code that fails:
@Test
public void testRw() throws IOException {
final SampleNode terminal =
SampleNode.newBuilder().setCount(1).setSubNodes(Collections.EMPTY_LIST).build();
final Method method =
Method.newBuilder().setMethodName("test").setDeclaringClass("test").build();
final SamplePair samplePair = SamplePair.newBuilder()
.setMethod(method)
.setNode(terminal).build();
SampleNode data = SampleNode.newBuilder().setCount(10)
.setSubNodes(Arrays.asList(samplePair)).build();
try (ByteArrayBuilder bab = new ByteArrayBuilder()) {
SpecificDatumWriter<SampleNode> writer = new
SpecificDatumWriter<>(data.getSchema());
final BinaryEncoder directBinaryEncoder =
EncoderFactory.get().directBinaryEncoder(bab, null);
writer.write(data, directBinaryEncoder);
directBinaryEncoder.flush();
ByteArrayInputStream bis = new
ByteArrayInputStream(bab.getBuffer(), 0, bab.size());
SpecificDatumReader<SampleNode> reader = new
SpecificDatumReader<>(data.getSchema());
BinaryDecoder directBinaryDecoder =
DecoderFactory.get().directBinaryDecoder(bis, null);
SampleNode read = reader.read(null, directBinaryDecoder);
Assert.assertEquals(read, data);
}
}
> Avro schema compile does not support circular reference
> -------------------------------------------------------
>
> Key: AVRO-1285
> URL: https://issues.apache.org/jira/browse/AVRO-1285
> Project: Avro
> Issue Type: New Feature
> Components: java
> Reporter: Viji
> Priority: Minor
> Attachments: multipass.tar
>
>
> While declaring a Schema, doing a circular reference is not possible if the
> Schema for the external reference is in another file. Attached is a project
> that provides 2 schemas that exhibits this missing feature.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)