Avro Maven插件:不支持类型

时间:2018-03-13 01:08:10

标签: maven avro

我有一个文件Pojo.avsc,其中包含以下声明:

{
  "namespace": "io.fama.pubsub.schema",
  "type": "record",
  "name": "Pojo",
  "fields": [
    {
      "name": "field",
      "type": "string"
    }
  ]
}

我有一个文件PojoCollection.avsc,它只包含一组Pojo对象。

{
  "namespace": "io.fama.pubsub.schema",
  "type": "record",
  "name": "PojoCollection",
  "fields": [
    {
      "name": "collection",
      "type": {
        "type": "array",
        "items": {
          "name": "pojo",
          "type": "Pojo"
        }
      }
    }
  ]
}

我的avro-maven-plugin配置如下:

<plugin>
    <groupId>org.apache.avro</groupId>
    <artifactId>avro-maven-plugin</artifactId>
    <version>1.8.2</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>schema</goal>
            </goals>
            <configuration>
                <imports>
                    <import>${basedir}/src/main/avro/Pojo.avsc</import>
                </imports>
            </configuration>
        </execution>
    </executions>
</plugin>

这会导致以下异常:

Caused by: org.apache.avro.SchemaParseException: Type not supported: Pojo
    at org.apache.avro.Schema.parse(Schema.java:1319)
    at org.apache.avro.Schema.parse(Schema.java:1306)
    at org.apache.avro.Schema.parse(Schema.java:1269)
    at org.apache.avro.Schema$Parser.parse(Schema.java:1032)
    at org.apache.avro.Schema$Parser.parse(Schema.java:997)
    at org.apache.avro.mojo.SchemaMojo.doCompile(SchemaMojo.java:73)
    at org.apache.avro.mojo.AbstractAvroMojo.compileFiles(AbstractAvroMojo.java:223)
    at org.apache.avro.mojo.AbstractAvroMojo.execute(AbstractAvroMojo.java:172)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    ... 21 more

这是一个avro maven插件错误吗?或者我的avsc文件有问题吗?

1 个答案:

答案 0 :(得分:3)

这是您的数组定义的问题。它看起来应该是

{
  "namespace": "io.fama.pubsub.schema",
  "type": "record",
  "name": "PojoCollection",
  "fields": [
    {
      "name": "pojosCollection",
      "type": {
        "type": "array",
        "items": "Pojo"
      }
    }
  ]
}

必须在items属性中定义数组的类型。