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

StackOverflow https://stackoverflow.com/questions/22443051

  •  15-06-2023
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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"
            }
        }
    ]
}]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top