[ 
https://issues.apache.org/jira/browse/AVRO-530?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17731530#comment-17731530
 ] 

Christophe Le Saec commented on AVRO-530:
-----------------------------------------

*Back to this JIRA :*
[~kniemitalo] :
 - the proposed [PR|https://github.com/apache/avro/pull/1768] works also with 
"forward references" (tested with your example)
 - it preserves Canonical Form result, with example, it generates :
{code:json}
{"name":"Main","type":"record",fields":[{"name":"f1","type":{"name":"Sub","type":"enum","symbols":["OPEN","CLOSE"]}},{"name":"f2","type":"Sub"}]}
{code}

 

But, in java, it also allow recursing type, as
{code:json}
{ "protocol" : "recurse",   "types": [
   {"name": "Parent", "type": "record", "fields": [{"name": "childs", "type":{ 
"type":"array", "items": "Child"}}]},
   {"name": "Child", "type": "record", "fields": [{"name": "parent", "type": 
"Parent"}]}
]}
{code}
that works fine until we try to serialize it with encoder ... throwing 
StackOverflowError exception ...
({_}in rust, borrowing mechanism seems to prevent that kind of issue{_})

> allow for mutual recursion in type definitions
> ----------------------------------------------
>
>                 Key: AVRO-530
>                 URL: https://issues.apache.org/jira/browse/AVRO-530
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: spec
>    Affects Versions: 1.3.2
>            Reporter: Jeff Hodges
>            Assignee: Christophe Le Saec
>            Priority: Major
>              Labels: pull-request-available
>
> Suppose you have these two types in your protocol:
> {code}
> {"name": "User", "type": "record", "fields": [{"name": "current_status", 
> "type": "Status"}]}
> {"name": "Status", "type": "record", "fields": [{"name": "author", "type": 
> "User"}]}
> {code}
> This will raise an error! The current workaround is to define one of them at 
> their first usage. Like:
> {code}
> {"name": "User", "type": "record", "fields": [{"name": "current_status", 
> "type": {"name": "Status", "type": "record", "fields": [.. lots of fields 
> ...]}]}
> {code}
> But this is incredibly unwieldy. It would be really nice for the spec to 
> require all the parsers to allow for mutual recursion, instead. It could be 
> done by implementing a two-pass parser. One pass to acquire names referenced, 
> and a second to fill in those names with their appropriate references.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to