Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Schema for Array of Array in Avro

avatar

Greetings!

I was trying to write some sample Avro schemas, and was unable to create one for an array of array.

Sample json -
{
  "testarray":[[1,2,3][4,5,6] ... ]
}		
My best try to create the schema -
{
  "name": "testarray",
  "type": {
    "type":"array",
    "items": {
      "type": {
        "type":"array",
        "items": {
          "name": "temp",
          "type":"long"
        }
      }
    }
  }
}

But the schema parser throws this error -

---

Exception in thread "main" org.apache.avro.SchemaParseException: No type: {"name":"testarray","type":{"type":"array","items":{"type":{"type":"array","items":{"name":"temp","type":"long"}}}}}

at org.apache.avro.Schema.getRequiredText(Schema.java:1372)

at org.apache.avro.Schema.parse(Schema.java:1231)

at org.apache.avro.Schema$Parser.parse(Schema.java:1031)

at org.apache.avro.Schema$Parser.parse(Schema.java:996)

at com.flipkart.de.App.main(App.java:54)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Process finished with exit code 1
---
Is there something wrong with the schema I've written, or is this not supported in Avro?
Any help would be much appreciated.
2 REPLIES 2

avatar
@Akshay Aggarwal

Try this format:

{

"name": "testarray"
"type": "array", 
"items": {
	"name": "Record1Array”, 
	"type": "record", 
	"fields" : [{
		“name": "Array1Value”, 
		"type": {
			"type": "array", 
			"items": {
				"name": "Record2Array”,
				"type":"record", 
				"fields" : [{
						"name”:”Array2Value”, 
						"type": "string"
					   }]
				  }
			}
		  }]
	}
}

Also, when dealing with Avro use Avro IDL; It makes writing/testing schemas easier.

avatar

This schema corresponds to an array of records (which in turn has arrays), but not an array of array?