[
https://issues.apache.org/jira/browse/AVRO-1994?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Thiruvalluvan M. G. updated AVRO-1994:
--------------------------------------
Status: Patch Available (was: Open)
Here is the patch:
The schema
{code}
{
"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" },
{ "name": "SecondNull", "type": "null" }
]
}
{code}
now produces:
{code}
struct TestPrimitiveTypes {
bool Boolean;
int32_t Int;
int64_t Long;
float Float;
double Double;
std::vector<uint8_t> Bytes;
std::string String;
TestPrimitiveTypes() : Boolean(bool()),
Int(int32_t()),
Long(int64_t()),
Float(float()),
Double(double()),
Bytes(std::vector<uint8_t>()),
String(std::string())
{ }
};
{code}
That is, it does not create a member for type {{null}}. But it does encode and
decode {{null}}s.
{code}
template<> struct codec_traits<pt::TestPrimitiveTypes> {
static void encode(Encoder& e, const pt::TestPrimitiveTypes& v) {
e.encodeNull();
avro::encode(e, v.Boolean);
avro::encode(e, v.Int);
avro::encode(e, v.Long);
avro::encode(e, v.Float);
avro::encode(e, v.Double);
avro::encode(e, v.Bytes);
avro::encode(e, v.String);
e.encodeNull();
}
static void decode(Decoder& d, pt::TestPrimitiveTypes& v) {
if (avro::ResolvingDecoder *rd =
dynamic_cast<avro::ResolvingDecoder *>(&d)) {
const std::vector<size_t> fo = rd->fieldOrder();
for (std::vector<size_t>::const_iterator it = fo.begin();
it != fo.end(); ++it) {
switch (*it) {
case 0:
d.decodeNull();
break;
case 1:
avro::decode(d, v.Boolean);
break;
case 2:
avro::decode(d, v.Int);
break;
case 3:
avro::decode(d, v.Long);
break;
case 4:
avro::decode(d, v.Float);
break;
case 5:
avro::decode(d, v.Double);
break;
case 6:
avro::decode(d, v.Bytes);
break;
case 7:
avro::decode(d, v.String);
break;
case 8:
d.decodeNull();
break;
default:
break;
}
}
} else {
d.decodeNull();
avro::decode(d, v.Boolean);
avro::decode(d, v.Int);
avro::decode(d, v.Long);
avro::decode(d, v.Float);
avro::decode(d, v.Double);
avro::decode(d, v.Bytes);
avro::decode(d, v.String);
d.decodeNull();
}
}
};
{code}
> 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
>
> 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)