You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Darryl Green (JIRA)" <ji...@apache.org> on 2017/02/19 14:46:44 UTC

[jira] [Comment Edited] (AVRO-1994) C++ Code Generator Generates Invalid Code if Field is of type Null

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

Darryl Green edited comment on AVRO-1994 at 2/19/17 2:46 PM:
-------------------------------------------------------------

A patch using boost::blank as the unit type for compatibility with (future) use of boost::variant (or anything that represents a union as something that holds a value, and its only a question of what the type of that value is). See AVRO-855... 

I agree [~thiru_mg] that with the current union interface there is no use for such a value. The changes I have made locally to use boost variant preserve the existing explicit set_null() and is_null() but add the variant interface which makes testing for whether a union (variant) contains null the same as testing for whether it contains any other type. Which is cleaner (allows visitation) and requires a unit type... The implementation of the old interface is simply:

{code}
bool is_null() const {  return (boost::get<boost::blank>(this)); }
void set_null() { this->variant() = boost::blank();  }
{code}



was (Author: da77a):
A patch using boost::blank as the unit type for compatibility with (future) use of boost::variant (or anything that represents a union as something that holds a value, and its only a question of what the type of that value is). See AVRO-855... 

> 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: another-AVRO-1994.patch, 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)