【问题标题】:JSON to JSON transform using JOLTTransformJSON NiFi使用 JOLTTransformJSON NiFi 将 JSON 转换为 JSON
【发布时间】:2023-02-06 15:43:09
【问题描述】:

我在用JOLTTransformJsonNifi 中的处理器。

我的输入是:

[
  {
    "col_name": "time",
    "data_type": "timestamp",
    "is_nullable": true
  },
  {
    "col_name": "otherData",
    "data_type": "string",
    "is_nullable": false
  }
]

我正在使用下面的规格:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "col_name": "name",
        "data_type": "type[0]",
        "is_nullable": {
          "true": "type[1]",
          "false": "type[1]"
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "*": {
        "type[1]": "notnull"
      }
    }
  }
]

预期产出是 :

{
  "type": "record",
  "name": "table_name",
  "fields": [
    {
      "name": "time",
      "type": [
        "timestamp",
        "null"
      ]
    },
    {
      "name": "otherData",
      "type": [
        "string",
        "notnull"
      ]
    }
  ]
}

但是将下面的作为当前结果通过组合数组中的所有值,例如:

{
  "name": [
    "time",
    "otherData"
  ],
  "type": [
    [
      "timestamp",
      "int"
    ],
    null
  ]
}

有人可以帮助我错过了什么吗?

【问题讨论】:

    标签: json bigdata transform etl apache-nifi


    【解决方案1】:

    您可以使用以下内容转移通过遍历数组的对象来转换规范,以便能够反复应用技巧:

    [
      {
        "operation": "shift",
        "spec": {
          "#record": "type", // fixed values formed by using # wildcards left-hand-side
          "#table_name": "name",
          "*": {
            "col_*": "fields[#2].&(0,1)",// replicate the 1st replacement of the asterisk from the current(0th) level
            "data_*": "fields[#2].&(0,1)",
            "is_nullable": {//conditional logic starts here
              "true": {
                "#null": "fields[#4].type"
              },
              "false": {
                "#notnull": "fields[#4].type"
              }
            }
          }
        }
      }
    ]
    

    【讨论】:

      猜你喜欢
      • 2022-11-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2020-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多