gamliel
gamliel

Reputation: 11

Solving Avro Schema Problems

Is there any way of getting useful information about avro schema problems?

I am trying to make the following work

{ "namespace": "format.data.something", "type": "record", "name": "data", "fields": [ { "name": "generator", "type": "string" }, { "name": "mapping", "type": { "name": "mappingItemSequence", "type": "array", "items": { "name": "item", "type": { "name": "mappingItem", "type": "record", "fields": [ { "name": "content", "type": "string" }, { "name": "tokenOutput", "type": { "name": "token", "type": "string" } }, { "name": "inputTokens", "type": { "name": "tokensSequence", "type": "array", "items": { "name": "tokenInput", "type": { "name": "token", "type": "string" } } } } ] } } } } ] }

and I receive a quite cryptic message from maven:

Execution default of goal org.apache.avro:avro-maven-plugin:1.8.2:schema failed: No type: {"name":"item","type":{"name":"mappingItem","type":"record","fields":[{"name":"content","type":"string"},{"name":"tokenOutput","type":{"name":"token","type":"string"}},{"name":"inputTokens","type":{"name":"tokensSequence","type":"array","items":{"name":"tokenInput","type":{"name":"token","type":"string"}}}}]}}

I am using apache avro 1.8.2 and I am trying to compile to java with maven.

Thank you very much.

Upvotes: 1

Views: 2308

Answers (1)

hlagos
hlagos

Reputation: 7947

The problem is essentially that you are adding extra information to your array type declaration. The attribute name is not required as part of your array definition type (documentationhere).

The following schema should work for you

{
  "namespace": "format.data.something",
  "type": "record",
  "name": "data",
  "fields": [
    {
      "name": "generator",
      "type": "string"
    },
    {
      "name": "mapping",
      "type": {
        "type": "array",
        "items": {
            "name": "mappingItem",
            "type": "record",
            "fields": [
              {
                "name": "content",
                "type": "string"
              },
              {
                "name": "tokenOutput",
                "type": {
                  "name": "token",
                  "type": "string"
                }
              },
              {
                  "name": "tokensSequence",
                  "type": { "type":"array",  "items": "string"}

              }
            ]

        }
      }
    }
  ]
}

Upvotes: 3

Related Questions