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

Sachin Goyal commented on AVRO-695:
-----------------------------------

Thanks Doug.

I created the patch using *diff -r* and it can be patched using *patch -i 
<patch-file>*

For non-string map-keys, I have submitted a separate patch at 
https://issues.apache.org/jira/browse/AVRO-680

Could you please explain your comment regarding circular references in more 
detail?
I will change my patch accordingly.

For example, here is a circular reference schema generated using Avro:
{code:javascript}
{
  "type" : "record",
  "name" : "SimpleParent",
  "namespace" : "org.apache.avro.generic",
  "fields" : [ {
    "name" : "parentName",
    "type" : [ "null", "string" ],
    "default" : null
  }, {
    "name" : "child",
    "type" : [ "null", {
      "type" : "record",
      "name" : "SimpleChild",
      "fields" : [ {
        "name" : "childName",
        "type" : [ "null", "string" ],
        "default" : null
      }, {
        "name" : "parent",
        "type" : [ "null", "SimpleParent"],
        "default" : null
      } ]
    }, "string" ],
    "default" : null
  } ]
}
{code}

The current code converts it to the following:
{code:javascript}
{
  "type" : "record",
  "name" : "SimpleParent",
  "namespace" : "org.apache.avro.generic",
  "fields" : [ {
    "name" : "__crefId",
    "type" : "string"
  }, {
    "name" : "parentName",
    "type" : [ "null", "string" ],
    "default" : null
  }, {
    "name" : "child",
    "type" : [ "null", {
      "type" : "record",
      "name" : "SimpleChild",
      "fields" : [ {
        "name" : "__crefId",
        "type" : "string"
      }, {
        "name" : "childName",
        "type" : [ "null", "string" ],
        "default" : null
      }, {
        "name" : "parent",
        "type" : [ "null", "SimpleParent", "string" ],
        "default" : null
      } ],
      "circularRefIdPrefix" : "__crefId"
    }, "string" ],
    "default" : null
  } ],
  "circularRefIdPrefix" : "__crefId"
}
{code}

Can you please apply your comments above to this example?
It will help me in understanding how it would be different from the above 
solution.

As per my understanding, circular references can come in any record-type 
element.
So CustomeEncoder approach would need to write it as a record sometimes or a 
string/int sometimes.
Can a CustomEncoder pass the control to regular Avro Encoder to write a record 
normally?

> Cycle Reference Support
> -----------------------
>
>                 Key: AVRO-695
>                 URL: https://issues.apache.org/jira/browse/AVRO-695
>             Project: Avro
>          Issue Type: New Feature
>          Components: spec
>    Affects Versions: 1.7.6
>            Reporter: Moustapha Cherri
>         Attachments: avro-1.4.1-cycle.patch.gz, avro-1.4.1-cycle.patch.gz, 
> avro_circular_references.zip, avro_circular_refs_2014_06_14.zip, 
> circular_refs_and_nonstring_map_keys_2014_06_25.zip
>
>   Original Estimate: 672h
>  Remaining Estimate: 672h
>
> This is a proposed implementation to add cycle reference support to Avro. It 
> basically introduce a new type named Cycle. Cycles contains a string 
> representing the path to the other reference.
> For example if we have an object of type Message that have a member named 
> previous with type Message too. If we have have this hierarchy:
> message
>   previous : message2
> message2
>   previous : message2
> When serializing the cycle path for "message2.previous" will be "previous".
> The implementation depend on ANTLR to evaluate those cycle at read time to 
> resolve them. I used ANTLR 3.2. This dependency is not mandated; I just used 
> ANTLR to speed thing up. I kept in this implementation the generated code 
> from ANTLR though this should not be the case as this should be generated 
> during the build. I only updated the Java code.
> I did not make full unit testing but you can find "avrotest.Main" class that 
> can be used a preliminary test.
> Please do not hesitate to contact me for further clarification if this seems 
> interresting.
> Best regards,
> Moustapha Cherri



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to