Request help with Avro IDL

2016-11-05 Thread Kamesh Kompella
I am trying to write up an IDL file so that the following avsc file will be 
generated by avro-tools. JSON needs to be an array of objects. I don’t know how 
to do this with IDL. Is it possible to achieve the following using IDL.

The avsc I am shooting for:

{
  "items": { 
"fields": [
{   
  "name": "name",
"type": "string"
},  
{   
  "name": "age",
  "type": "int"
}   
],  
"name": "person",
"type": "record"
  },
"type": “array”,
   “name”: “PersonArray"
}

The JSON that works with this is:

[{“name”: “foo”, “age”: 3}]

Can this be written in an IDL? If so, please advise on what I will use top mark 
out the array. So far, I have the following:

protocol PersonProtocol {
  record Person {
string name;
int age;
  }

  record PersonArray {
array people;
  }
}


which accepts the JSON below. Notice that I am stuck with the field name 
“people”. The JSON is now an object instead of an array.

{"people":[{"name”:"foo","age”:3}]

I appreciate any help with this.

Thanks
Kamesh





Is this a valid Avro schema?

2016-09-02 Thread Kamesh Kompella
Hi there,
 First, please look at the following schema 

{"name": "user_record",
  "namespace": "com.user",
  "type": "record",
  "fields" : [ 
{"name": "name", "type": "string"},
{"name": "id", "type": "long"}
  ]}

and the following JSON:  

{"name": “Foo", “id": 42}

When I run avro-tools with the option fromjson, I get a .avro file. Stuff works.

If I enclose the schema above into array as shown below (I bolded the array 
begin and end in red for clarity), avro-tools (version 1.8.1) throws the 
following exception and dies. 


[{"name": "user_record",
  "namespace": "com.user",
  "type": "record",
  "fields" : [ 
{"name": "name", "type": "string"},
{"name": "id", "type": "long"}
  ]}]

I get the following exception: 

Exception in thread "main" org.apache.avro.AvroTypeException: Unknown union 
branch name at org.apache.avro.io.JsonDecoder.readIndex(JsonDecoder.java:445)

Does it make sense to enclose a schema into array? Is this a bug in avro-tools 
or is this an invalid schema? The exception above seems to indicate that a 
schema file may not begin with a JSON array of schemas. 

The documentation seems to indicate schema may be defined as union of other 
other schemas.

I cloned the code base and I could not locate a single instance of avsc file in 
it that defined its schema as a JSON array. Hence, the question.

I appreciate your response.

Regards
Kamesh