You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Mina Aslani <as...@gmail.com> on 2018/10/19 19:43:57 UTC
AVRO Schema with optional field ("type": "record")
Hi,
I am adding AVRO schema to the kafka messages, however, I would like to
know how I can make a field of "type": "record" optional.
*Note*: "default":null does not help.
Any idea? Can you elaborate the solution/workaround with an example please?
Best regards,
Mina
Re: AVRO Schema with optional field ("type": "record")
Posted by Mina Aslani <as...@gmail.com>.
How can I do the same thing in the .avro format?
On Friday, October 19, 2018, Jacob Sheck <sh...@gmail.com> wrote:
> Can you use a union with null? This would be the IDL exmple.
>
> record RecordConfig {
> ...
> }
>
> union {null, RecordConfig} record = null;
>
> On Fri, Oct 19, 2018 at 2:44 PM Mina Aslani <as...@gmail.com> wrote:
>
> > Hi,
> >
> > I am adding AVRO schema to the kafka messages, however, I would like to
> > know how I can make a field of "type": "record" optional.
> > *Note*: "default":null does not help.
> >
> > Any idea? Can you elaborate the solution/workaround with an example
> please?
> >
> > Best regards,
> > Mina
> >
>
Re: AVRO Schema with optional field ("type": "record")
Posted by Jacob Sheck <sh...@gmail.com>.
The idl2schemata tool in avro-tools can help:
[user@host]$ cat test.idl
protocol EmployeeProtocol
{
record Employee {
string name;
long employeeId;
}
record EmployeeWithUnion{
union {null, Employee} optionalEmployee = null;
}
}
[user@host]$ java -jar avro-tools-1.8.2.jar idl2schemata test.idl test
[user@host]$ cat test/EmployeeWithUnion.avsc
{
"type" : "record",
"name" : "EmployeeWithUnion",
"fields" : [ {
"name" : "optionalEmployee",
"type" : [ "null", {
"type" : "record",
"name" : "Employee",
"fields" : [ {
"name" : "name",
"type" : "string"
}, {
"name" : "employeeId",
"type" : "long"
} ]
} ],
"default" : null
} ]
}
On Fri, Oct 19, 2018 at 8:21 PM Jacob Sheck <sh...@gmail.com> wrote:
> Can you use a union with null? This would be the IDL exmple.
>
> record RecordConfig {
> ...
> }
>
> union {null, RecordConfig} record = null;
>
> On Fri, Oct 19, 2018 at 2:44 PM Mina Aslani <as...@gmail.com> wrote:
>
>> Hi,
>>
>> I am adding AVRO schema to the kafka messages, however, I would like to
>> know how I can make a field of "type": "record" optional.
>> *Note*: "default":null does not help.
>>
>> Any idea? Can you elaborate the solution/workaround with an example
>> please?
>>
>> Best regards,
>> Mina
>>
>
Re: AVRO Schema with optional field ("type": "record")
Posted by Jacob Sheck <sh...@gmail.com>.
Can you use a union with null? This would be the IDL exmple.
record RecordConfig {
...
}
union {null, RecordConfig} record = null;
On Fri, Oct 19, 2018 at 2:44 PM Mina Aslani <as...@gmail.com> wrote:
> Hi,
>
> I am adding AVRO schema to the kafka messages, however, I would like to
> know how I can make a field of "type": "record" optional.
> *Note*: "default":null does not help.
>
> Any idea? Can you elaborate the solution/workaround with an example please?
>
> Best regards,
> Mina
>