avro与嵌套模式的数组

时间:2016-06-21 17:23:47

标签: schema avro

我试图在apache avro中表示“订单”及其相关条目。请参阅下面的架构。尝试在eclipse中构建它时,我收到以下错误。任何帮助表示赞赏。

[ERROR] Failed to execute goal org.apache.avro:avro-maven-plugin:1.8.1:schema (default) on project avrosample: Execution default of goal org.apache.avro:avro-maven-plugin:1.8.1:schema failed: Undefined name: "com.company.domain.entry" -> [Help 1]

**Schema For Entry:**
{"namespace": "com.company.domain",
 "type": "record",
 "name": "entry",
 "fields": [
     {"name": "id", "type": "long"},
     {"name": "description",  "type": "string"},
     {"name": "quantity", "type: “int”}

 ]
}

**Schema for Order:**
{"namespace": "com.company.domain",
 "type": "record",
 "name": "order",
 "fields": [
     {"name": "id", "type": "long"},
     {"name": "date",  "type": "long"},
     {"name": "entries", "type": {"items": "array", "items": "com.company.domain.entry"} }}

 ]
}

1 个答案:

答案 0 :(得分:0)

如果我没弄错的话,你就不能以这种方式将Entry-schema链接到Order-schema。为什么不使用Order的联合模式?像这样:

{
  "type": "record",
  "name": "Order",
  "namespace": "com.company.domain",
  "fields": [
    {
      "name": "id",
      "type": "long"
    },
    {
      "name": "date",
      "type": "long"
    },
    {
      "name": "entries",
      "type": {
        "type": "array",
        "items": {
          "type": "record",
          "name": "Entry",
          "fields": [
            {
              "name": "id",
              "type": "long"
            },
            {
              "name": "description",
              "type": "string"
            },
            {
             "name": "quantity",
              "type": "int"
            }
          ]
        },
        "java-class": "java.util.List"
      }
    }
  ]
}