avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thiruvalluvan M. G. (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AVRO-1994) C++ Code Generator Generates Invalid Code if Field is of type Null
Date Mon, 13 Feb 2017 18:38:41 GMT

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

Thiruvalluvan M. G. commented on AVRO-1994:
-------------------------------------------

Hi [~da77a]

I did consider the option of having some Null type. The reason I decided to handle nulls specifically
is to avoid requiring value for Null type. It is always a problem with Null (or void) types.
Java has some ugly corner issues with void and Void. C++ used to have template issues with
void types. Your solution, as you point out, makes a more uniform treatment of Nulls.

The only practical use of null seems to be a branch of a union. The C++ handles it in a specific
way not similar to the other types. Again the reason is not having a value for null type.
I think set_null() and is_null() is cleaner than set_null(blank) and get_null(). So, not using
{{boost::blank}} in structs is in a way consistent with what we already do with unions.

That is, while uniform treatment of nulls with other type is appealing, using a blank value
looks artificial. But I can go either way. When you are ready, please go ahead and submit
your patch.


> C++ Code Generator Generates Invalid Code if Field is of type Null
> ------------------------------------------------------------------
>
>                 Key: AVRO-1994
>                 URL: https://issues.apache.org/jira/browse/AVRO-1994
>             Project: Avro
>          Issue Type: Bug
>          Components: c++
>            Reporter: Darryl Green
>         Attachments: AVRO-1994.patch
>
>
> An simple schema like this:
> {
>         "name": "TestPrimitiveTypes",
>         "type": "record",
>         "fields": [
>             { "name": "Null", "type": "null" },
>             { "name": "Boolean", "type": "boolean" },
>             { "name": "Int", "type": "int" },
>             { "name": "Long", "type": "long" },
>             { "name": "Float", "type": "float" },
>             { "name": "Double", "type": "double" },
>             { "name": "Bytes", "type": "bytes" },
>             { "name": "String", "type": "string" }
>         ]
>     }
> Generates this C++ struct.
> struct TestPrimitiveTypes {
>     $Undefined$ Null; // <-- BUG!
>     bool Boolean;
>     int32_t Int;
>     int64_t Long;
>     float Float;
>     double Double;
>     std::vector<uint8_t> Bytes;
>     std::string String;
>     TestPrimitiveTypes() :
>         Null($Undefined$()),
>         Boolean(bool()),
>         Int(int32_t()),
>         Long(int64_t()),
>         Float(float()),
>         Double(double()),
>         Bytes(std::vector<uint8_t>()),
>         String(std::string())
>         { }
> };
> Note the C++ type of the field Null is $Undefined$ which is obviously invalid/won't compile.




--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message