You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Patrick Nip <pn...@yahoo-inc.com> on 2014/09/25 20:47:12 UTC
Is this a bug?
According to the documentation:
https://avro.apache.org/docs/current/api/cpp/html/classavro_1_1GenericDatum.html#a879e7b725023bfd8246e15f07cb5bef0
avro::GenericDatum::GenericDatum ( const ValidSchema<https://avro.apache.org/docs/current/api/cpp/html/classavro_1_1ValidSchema.html> & schema )
Constructs a datum corresponding to the given avro type.
The value will the appropraite default corresponding to the data type.
Parameters:
schema The schema that defines the avro type.
A GenericDatum when given a valid schema should have all its field fill with reasonable default. But it seems it is failing for union schema. I have a written the following piece of code which I input the script with a schema and then try to encode it and save the result in a file:
14 avro::ValidSchema load(const char* filename)
15 {
16 std::ifstream ifs(filename);
17 avro::ValidSchema result;
18 avro::compileJsonSchema(ifs, result);
19 return result;
20 }
21
22 int
23 main(int argc, char ** argv)
24 {
25 avro::ValidSchema sch = load(argv[1]); // load a schema
26
27 avro::GenericDatum metaDatum( sch );
28 std::auto_ptr<avro::OutputStream> out = avro::fileOutputStream( argv[2], 1 ); // write the result to a specified file
29 avro::EncoderPtr en = avro::jsonEncoder( sch );
30 en->init ( *out );
31 avro::encode ( *en, metaDatum );
32 en->flush();
33
34 return 0;
35 }
Case and point:
[pnip =>avro_rhel6<= my_avro]$ cat union.schema
[ "bytes", "long”]
[pnip =>avro_rhel6<= my_avro]$ ./schemaTest union.schema /tmp/result
terminate called after throwing an instance of 'avro::Exception'
what(): Not that many names
Aborted
It seems to work on other schema types (have not check all yet) but failed on union type schema