【问题标题】:Apache Nifi Validating Nested JsonApache Nifi 验证嵌套 Json
【发布时间】:2019-02-21 15:46:29
【问题描述】:

我正在使用 Avro 模式对嵌套 Json 使用 Apache Nifi 验证记录。我在使用 JSON 中的 map 字段时遇到了特殊问题。

架构:

{
  "type": "record",
  "name": "Test",
  "namespace": "test_events",
  "fields": [
    {
      "name": "id",
      "type": "string"
    },
    {
      "name": "test_attributes",
      "type": {
        "type": "record",
        "name": "test_attributes.instance",
        "fields": [
          {
            "name": "normal_field",
            "type": [
              "null",
              "string"
            ]
          },
          {
            "name": "nested_field",
            "type": [
              "null",
              {
                "type": "map",
                "values": [
                  "null",
                  "int"
                ]
              }
            ]
          }
        ]
      }
    }
  ]
}

Json 数据:

{
  "id": "aplhanum123",
  "test_attributes": {
    "normal_field": "normal",
    "nested_field": {
      "meaning": 42
    }
  }
}

无效消息:

由于以下原因,此 FlowFile 中的记录无效: ;这 以下 1 个字段的值的类型与架构不匹配: [/test_attributes/nested_field]

我不明白这个消息。我想 Json 中的 nested_field 是有效的 map ,因此不应被处理器无效。我错过了什么?

编辑: * 删除了示例 JSON 中的 }。 * Nifi-1.7.1,使用 JsonTreeReader 验证记录

【问题讨论】:

  • 你使用什么处理器,控制服务,nifi的哪个版本?我在 nifi-1.8 中进行了尝试,并且在删除最终的 } 后成功验证了 json。我将 ValidateRecord 处理器与 JsonTreeReader 一起使用。
  • 我将 Nifi-1.7 与 ValidateRecord 和 JsonTreeReader 一起使用。我相信您指的是JSON中的最终}?你是对的,这是我的一个错误。那不应该在那里。

标签: json validation avro apache-nifi


【解决方案1】:

发现NIFI-5678(确认存在错误)和https://github.com/apache/nifi/pull/3060/commits/c66de368d07f37a8652c09e4b116b232972821ac,已在1.8.0 版中发布。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-07
    • 2020-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-23
    • 1970-01-01
    相关资源
    最近更新 更多