Avro 架构格式异常 - “SecurityClassification”不是定义的名称

Avro Schema format Exception - “SecurityClassification” is not a defined name

我正在尝试使用这个 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 工具生成 avro 文件:

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

但我收到以下错误消息:

Exception in thread "main" org.apache.avro.SchemaParseException: "SecurityClassification" is not a defined name. The type of the "securityClassification" field must be a defined name or a {"type": ...} expression.

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

您正在使用它作为您的字段类型,但是您没有像 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 .