0

我正在尝试使用这个 avro 模式

{
  "type": "record",
  "name": "ComplianceEntity",
  "namespace": "com.linkedin.events.metadata",
  "fields": [
    {
      "name": "fieldPath",
      "type": "string"
    },
    {
      "name": "complianceDataType",
      "type": {
        "type": "enum",
        "name": "ComplianceDataType",

        "symbols": [
          "NONE",
          "MEMBER_ID"
        ],
        "symbolDocs": {
          "NONE": "None of the following types apply",
          "MEMBER_ID": "ID for LinkedIn members"
        }
      }
    },
    {
      "name": "complianceDataTypeUrn",
      "type": [
        "null",
        "string"
      ],
      "default": null
    },
    {
      "name": "fieldFormat",
      "type": [
        "null",
        {
          "type": "enum",
          "name": "FieldFormat",
          "symbols": [
            "NUMERIC"
          ],
          "symbolDocs": {
            "NUMERIC": "Numerical format, 12345"
          },
          "doc": "The field format"
        }
      ]
    },
    {
      "name": "securityClassification",
      "type": "SecurityClassification"
    },
    {
      "name": "valuePattern",
      "default": null,
      "type": [
        "null",
        "string"
      ]
    }
  ]
}

使用 avro-tools 生成和 avro 文件:

java -jar ./avro-tools-1.8.2.jar compile schema ComplianceEntity.avsc .

但我收到以下错误消息:

线程“main”org.apache.avro.SchemaParseException 中的异常:“SecurityClassification”不是定义的名称。“securityClassification”字段的类型必须是定义的名称或 {“type”: ...} 表达式。

谁能告诉,为什么 SecurityClassification 没有被识别为定义的名称?

4

1 回答 1

1

您将它用作字段的类型,但是您没有像 for 那样正确定义它complianceDataType,这就是您获得 avro 异常的原因

{
      "name": "securityClassification",
      "type": "SecurityClassification"
}

确保如果您有超过 1 个模式,则传递所有模式,尤其是依赖模式。AVRO 1.5.3 https://issues.apache.org/jira/browse/AVRO-877支持它。

java -jar ./avro-tools-1.8.2.jar compile schema SecurityClassification.avsc ComplianceEntity.avsc .
于 2018-10-17T13:14:23.500 回答