[
https://issues.apache.org/jira/browse/AVRO-840?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13124033#comment-13124033
]
Thiruvalluvan M. G. commented on AVRO-840:
------------------------------------------
If there are no objections, I'll commit this tomorrow.
> C++ generate nullable types for optional fields int the schema
> ---------------------------------------------------------------
>
> Key: AVRO-840
> URL: https://issues.apache.org/jira/browse/AVRO-840
> Project: Avro
> Issue Type: Improvement
> Components: c++
> Reporter: Ramana Suvarapu
> Assignee: Thiruvalluvan M. G.
> Priority: Critical
> Labels: C++
> Attachments: AVRO-840.patch
>
>
> To represent optional fields, we use unions in our schema. See the example
> below.
> {
> "type" : "record",
> "name" : "Contact",
> "fields" : [
> {"name" : "FirstName","type" : ["string" ]},
> {"name" : "MiddleName","type" : [null, "string" ]},
> {"name" : "LastName", "type" : ["string" ]},
> {"name" : "PhoneNum","type" : [null, "string" ]},
> {"name" : "Id","type" : [null, "long" ]}
> ]
> }
> In this schema PhoneNum, MiddleName and Id fields are declared as unions as
> they are optional fields. For this schema, Avrogencpp generates Contact
> structure and 3 separate union structures for each of the optional fields in
> the schema.
> struct Contact
> {
> String FirstName;
> String LastName;
> Union_0 MiddleName;
> Union_1 PhoneNum;
> Union_3 Id;
> }
> Instead is it possible to create a new template based NullableType to
> represent optional fields. Basically if the schema has union with 2 fields
> and first field is null, it should generate Nullable type.
> For the above scheme, it should generate something like this.
> struct Contact
> {
> String FirstName;
> String LastName;
> Nullable<string> MiddleName;
> Nullable<string> PhoneNum;
> Nullable< long > Id;
> }
> This will reduce the number of generated unions in generated code and improve
> the readability and usability of the code.
> Let me know if it's feasible to implement this.
> Thanks,
> Ramana
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira