Hello,
I'm using the avro c++ api (1.7.8) to serialize/deserialize avro files.
The schema I want to use is the following:
{
"name": "cpx",
"type": "record",
"fields": [
{"name": "numbername", "type": "string"},
{"name": "re", "type": "double"},
{"name": "im", "type": "double", "default": 0} ]
}I try to write programmatically the schema above in c++ in the following way:
#include <avro/Schema.hh>
static avro::Schema getMySchema() { avro::RecordSchema node0("cpx");
{ avro::Schema node1 = avro::StringSchema();
node0.addField("numbername", node1); } { avro::Schema node1 =
avro::DoubleSchema(); node0.addField("re", node1); } {
avro::Schema node1 = avro::DoubleSchema(); node0.addField("im", node1);
}
return node0;}
Then I write the file using something like:
...
...
avro::DataFileWriter<ObjAvro> pDfw_m = new
avro::DataFileWriter<ObjAvro>(filename_p, *(
new avro::ValidSchema(getMySchema());
...
...
const ObjAvro& avro_l = ...
pDfw_m.write(avro_l);
...
The problem is that the schema at the top of the output file created is
different tothe input schema. It looks like:
{
"name": "cpx",
"type": "record",
"fields": [
{"name": "numbername", "type": "string"},
{"name": "re", "type": "double"},
{"name": "im", "type": "double"} ]
}
Is there a way to specify the default values directly in the c++ code above (in
the method getMySchema)?
(So that the schema of my output file will match the one of my input file.)
After a look in the source code, I see where the defaultAttributes are stored
for a record node, and what the method .addField does.
The method addField adds the name of the leaf to the Node member
leafNameAttributes_ and the leaf to the Node member leafAttributes_, but I
can't see a simple way to add default values to the NodeRecord member
defaultValues (NodeImpl.hh).
Thanks in advance.
Regards.
Pierre