Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avro-Tools JSON to Avro Schema fails: org.apache.avro.SchemaParseException: Undefined name:

Tags:

avro

I am trying to create two Avro schemas using the avro-tools-1.7.4.jar create schema command.

I have two JSON schemas which look like this:

{
 "name": "TestAvro",
 "type": "record",
 "namespace": "com.avro.test",
 "fields": [
    {"name": "first",     "type": "string"},
    {"name": "last",      "type": "string"},
    {"name": "amount",     "type": "double"} 
 ]
}


{
 "name": "TestArrayAvro",
 "type": "record",
 "namespace": "com.avro.test",
 "fields": [
    {"name": "date",     "type": "string"},
    {"name": "records",  "type":      
           {"type":"array","items":"com.avro.test.TestAvro"}}
    ]
 }

When I run the create schema on these two files the first one works fine and generates the java. The second one fails every time. It does not like the array items when I try and use the first Schema as the type. This is the error I get:

Exception in thread "main" org.apache.avro.SchemaParseException: Undefined name: "com.test.avro.TestAvro"
at org.apache.avro.Schema.parse(Schema.java:1052)

Both files are located in the same path directory.

like image 614
medium Avatar asked Mar 16 '14 21:03

medium


1 Answers

Use the below avsc file:

[{
    "name": "TestAvro",
    "type": "record",
    "namespace": "com.avro.test",
    "fields": [
        {
            "name": "first",
            "type": "string"
        },
        {
            "name": "last",
            "type": "string"
        },
        {
            "name": "amount",
            "type": "double"
        }
    ]
},
{
    "name": "TestArrayAvro",
    "type": "record",
    "namespace": "com.avro.test",
    "fields": [
        {
            "name": "date",
            "type": "string"
        },
        {
            "name": "records",
            "type": {
                "type": "array",
                "items": "com.avro.test.TestAvro"
            }
        }
    ]
}]
like image 170
Princey James Avatar answered Sep 24 '22 02:09

Princey James