[prev in list] [next in list] [prev in thread] [next in thread]
List: avro-user
Subject: Re: Java code generation for nested non-optional records
From: Teemu_Kanstrén <tkanstren () gmail ! com>
Date: 2015-08-21 16:28:50
Message-ID: CAGagL=erjMM=N1hXbgBYChr1q=+pmepBFrt0eDw5DCODK+Kgxw () mail ! gmail ! com
[Download RAW message or body]
Thanks! This works. So it was the extra [] left over from the optional
definition.
These schemas keep confusing me with all the combinations and braces.. :)
On 21 August 2015 at 18:28, Prajwal Tuladhar <praj@infynyxx.com> wrote:
> How about?
>
> {
> "namespace": "avr=C3=B2.test",
> "type": "record",
> "name": "TopObj",
> "fields": [
> {
> "name": "inner1",
> "type": {
> "name": "Inner1",
> "type": "record",
> "fields": [
> {
> "name": "value1",
> "type": "string"
> },
> {
> "name": "value2",
> "type": "string"
> }
> ]
> }
> },
> {
> "name": "inner2",
> "type": [
> {
> "type": "record",
> "name": "Inner2",
> "fields": [
> {
> "name": "value3",
> "type": "string"
> },
> {
> "name": "value4",
> "type": "string"
> }
> ]
> },
> "null"
> ]
> }
> ]
> }
>
>
> On Fri, Aug 21, 2015 at 3:00 PM, Teemu Kanstr=C3=A9n <tkanstren@gmail.com=
>
> wrote:
>
>> Hello all,
>>
>> I am using the Maven Avro compiler to generate Java code for my Avro
>> schemas. Problem. If I have a nested record which is optional, everythin=
g
>> generates OK. If the type is not optional, the generated reference is se=
t
>> to generic Object type and I cannot use it. What might I be doing wrong?
>>
>> Example schema:
>>
>> {
>> "namespace": "avro.test",
>> "type": "record",
>> "name": "TopObj",
>> "fields": [
>> {"name": "inner1", "type": [
>> {"type": "record", "name": "Inner1",
>> "fields": [
>> {"name": "value1", "type": "string"},
>> {"name": "value2", "type": "string"}
>> ]
>> }]
>> },
>> {"name": "inner2", "type": [
>> {"type": "record", "name": "Inner2",
>> "fields": [
>> {"name": "value3", "type": "string"},
>> {"name": "value4", "type": "string"}
>> ]
>> }, "null"]
>> }
>> ]
>> }
>>
>> Running the Avro Java code generator for this produces three classes as =
expected: TopObj, Inner1 and Inner2. However, in TopObject, the definitions=
are as:
>>
>> @Deprecated public java.lang.Object inner1;
>> @Deprecated public avro.test.Inner2 inner2;
>>
>> If I set inner1 as optional (add the , "null" to it) the type also becom=
es Inner1 in TopObj, which is as I would expect. But I do not want it to be=
optional.
>>
>> How do I get inner1 to generate as type Inner1 in TopObj?
>>
>> Cheers & thanks,
>>
>> Teemu
>>
>>
>
>
> --
> --
> Cheers,
> Praj
>
[Attachment #3 (text/html)]
<div dir="ltr">Thanks! This works. So it was the extra [] left over from the optional \
definition.<div><br></div><div>These schemas keep confusing me with all the \
combinations and braces.. :)</div></div><div class="gmail_extra"><br><div \
class="gmail_quote">On 21 August 2015 at 18:28, Prajwal Tuladhar <span \
dir="ltr"><<a href="mailto:praj@infynyxx.com" \
target="_blank">praj@infynyxx.com</a>></span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">How about?<div><br></div><div><pre>{ \
"namespace": "avrò.test", "type": "record",
"name": "TopObj",
"fields": [
{
"name": "inner1",
"type": {
"name": "Inner1",
"type": "record",
"fields": [
{
"name": "value1",
"type": "string"
},
{
"name": "value2",
"type": "string"
}
]
}
},
{
"name": "inner2",
"type": [
{
"type": "record",
"name": "Inner2",
"fields": [
{
"name": "value3",
"type": "string"
},
{
"name": "value4",
"type": "string"
}
]
},
"null"
]
}
]
}</pre>
<div align="center"></div></div></div><div class="gmail_extra"><div><div \
class="h5"><br><div class="gmail_quote">On Fri, Aug 21, 2015 at 3:00 PM, Teemu \
Kanstrén <span dir="ltr"><<a href="mailto:tkanstren@gmail.com" \
target="_blank">tkanstren@gmail.com</a>></span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">Hello all,<div><br></div><div> I am using the \
Maven Avro compiler to generate Java code for my Avro schemas. Problem. If I have a \
nested record which is optional, everything generates OK. If the type is not \
optional, the generated reference is set to generic Object type and I cannot use it. \
What might I be doing wrong?</div><div><br></div><div> Example \
schema:</div><div><br></div><div><pre \
style="color:rgb(0,0,0);font-family:'Courier New'">{<br> <span \
style="color:#660e7a;font-weight:bold">"namespace"</span>: <span \
style="color:#008000;font-weight:bold">"avro.test"</span>,<br> <span \
style="color:#660e7a;font-weight:bold">"type"</span>: <span \
style="color:#008000;font-weight:bold">"record"</span>,<br> <span \
style="color:#660e7a;font-weight:bold">"name"</span>: <span \
style="color:#008000;font-weight:bold">"TopObj"</span>,<br> <span \
style="color:#660e7a;font-weight:bold">"fields"</span>: [<br> {<span \
style="color:#660e7a;font-weight:bold">"name"</span>: <span \
style="color:#008000;font-weight:bold">"inner1"</span>, <span \
style="color:#660e7a;font-weight:bold">"type"</span>: [<br> {<span \
style="color:#660e7a;font-weight:bold">"type"</span>: <span \
style="color:#008000;font-weight:bold">"record"</span>, <span \
style="color:#660e7a;font-weight:bold">"name"</span>: <span \
style="color:#008000;font-weight:bold">"Inner1"</span>,<br> <span \
style="color:#660e7a;font-weight:bold">"fields"</span>: [<br> \
{<span style="color:#660e7a;font-weight:bold">"name"</span>: <span \
style="color:#008000;font-weight:bold">"value1"</span>, <span \
style="color:#660e7a;font-weight:bold">"type"</span>: <span \
style="color:#008000;font-weight:bold">"string"</span>},<br> \
{<span style="color:#660e7a;font-weight:bold">"name"</span>: <span \
style="color:#008000;font-weight:bold">"value2"</span>, <span \
style="color:#660e7a;font-weight:bold">"type"</span>: <span \
style="color:#008000;font-weight:bold">"string"</span>}<br> ]<br> \
}]<br> },<br> {<span \
style="color:#660e7a;font-weight:bold">"name"</span>: <span \
style="color:#008000;font-weight:bold">"inner2"</span>, <span \
style="color:#660e7a;font-weight:bold">"type"</span>: [<br> {<span \
style="color:#660e7a;font-weight:bold">"type"</span>: <span \
style="color:#008000;font-weight:bold">"record"</span>, <span \
style="color:#660e7a;font-weight:bold">"name"</span>: <span \
style="color:#008000;font-weight:bold">"Inner2"</span>,<br> <span \
style="color:#660e7a;font-weight:bold">"fields"</span>: [<br> \
{<span style="color:#660e7a;font-weight:bold">"name"</span>: <span \
style="color:#008000;font-weight:bold">"value3"</span>, <span \
style="color:#660e7a;font-weight:bold">"type"</span>: <span \
style="color:#008000;font-weight:bold">"string"</span>},<br> \
{<span style="color:#660e7a;font-weight:bold">"name"</span>: <span \
style="color:#008000;font-weight:bold">"value4"</span>, <span \
style="color:#660e7a;font-weight:bold">"type"</span>: <span \
style="color:#008000;font-weight:bold">"string"</span>}<br> ]<br> \
}, <span style="color:#008000;font-weight:bold">"null"</span>]<br> }<br> \
]<br>}</pre><pre style="color:rgb(0,0,0);font-family:'Courier New'"><span \
style="color:rgb(34,34,34);font-family:arial,sans-serif;white-space:normal">Running \
the Avro Java code generator for this produces three classes as expected: TopObj, \
Inner1 and Inner2. However, in TopObject, the definitions are \
as:</span><br></pre><pre style="color:rgb(0,0,0);font-family:'Courier \
New'"><pre style="font-family:'Courier New'"><span \
style="color:#808000">@Deprecated </span><span \
style="color:#000080;font-weight:bold">public </span>java.lang.Object <span \
style="color:#660e7a;font-weight:bold">inner1</span>;<br><span \
style="color:#808000">@Deprecated </span><span \
style="color:#000080;font-weight:bold">public </span>avro.test.Inner2 <span \
style="color:#660e7a;font-weight:bold">inner2</span>;<br></pre><pre \
style="font-family:'Courier New'"><span \
style="color:rgb(34,34,34);font-family:arial,sans-serif;white-space:normal">If I set \
inner1 as optional (add the , "null" to it) the type also becomes Inner1 in \
TopObj, which is as I would expect. But I do not want it to be \
optional.</span></pre><pre style="font-family:'Courier New'"><span \
style="color:rgb(34,34,34);font-family:arial,sans-serif;white-space:normal">How do I \
get inner1 to generate as type Inner1 in TopObj? </span></pre><pre \
style="font-family:'Courier New'"><span \
style="color:rgb(34,34,34);font-family:arial,sans-serif;white-space:normal">Cheers \
& thanks,</span></pre><pre style="font-family:'Courier New'"><span \
style="color:rgb(34,34,34);font-family:arial,sans-serif;white-space:normal">Teemu</span></pre></pre></div></div>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span \
class="HOEnZb"><font color="#888888">-- <br><div><div dir="ltr"><div><div \
dir="ltr">--<br></div><div>Cheers,<br></div><div>Praj<br></div></div></div></div> \
</font></span></div> </blockquote></div><br></div>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic