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/13 07:48:41 UTC
[jira] [Commented] (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=15863296#comment-15863296 ]
Darryl Green commented on AVRO-1994:
------------------------------------
Thanks for the fast turn-around on this issue.
One question/comment on the patch:
I did make a change that seemed to fix the problem locally with:
{code}
#include "boost/blank"
namespace avro {
typedef boost::blank null;
}
{code}
And the obvious/mechanical changes to generator and codec_traits to support this type.
{code}
template <> struct codec_traits<avro::null> {
/**
* Encodes a given value.
*/
static void encode(Encoder& e, const avro::null&) {
e.encodeNull();
}
/**
* Decodes into a given value.
*/
static void decode(Decoder& d, avro::null&) {
d.decodeNull();
}
};
{code}
and
{code}
string CodeGen::cppTypeOf(const NodePtr& n)
{
switch (n->type()) {
...
case avro::AVRO_NULL:
return "avro::null";
default:
return "$Undefined$";
}
}
{code}
The only reason I mention this is that it plays nicely with/is consistent with changes to use boost::variant (which can use boost::blank to represent "empty" state of a union) to represent Avro unions and support visitation. While there may be advantages in avoiding having a null value take up space (even struct{} has a non-zero size) there are also advantages in a null field "existing" like any other.
Note I haven't proposed a variant patch yet because what I have breaks recursive type support and I can't see a way out of that without it becoming a change that doesn't actually address the problems I had hoped to fix.
> 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)