json 如何在NIFI中使用Jolttransform规范进行Map?

cuxqih21  于 2023-06-25  发布在  其他
关注(0)|答案(1)|浏览(158)

我正在准备颠簸说明书,但我无法完成它,请帮助。

**注意:**有一个credits数组,该数组的值需要Map到schema字段,schema字段的类型为creditrecord。
输入:

{
  "schema": {
    "fields": [
      {
        "name": "user",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "billed",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "currency",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "currency_conversion_rate",
        "type": "FLOAT",
        "mode": "NULLABLE"
      },
      {
        "name": "usage_unit",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "adjustment_info_mode",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "adjustment_info_type",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "InvoiceMonth",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "credits",
        "type": "RECORD",
        "mode": "REPEATED",
        "fields": [
          {
            "name": "name",
            "type": "STRING",
            "mode": "NULLABLE"
          },
          {
            "name": "amount",
            "type": "FLOAT",
            "mode": "NULLABLE"
          },
          {
            "name": "full_name",
            "type": "STRING",
            "mode": "NULLABLE"
          },
          {
            "name": "id",
            "type": "STRING",
            "mode": "NULLABLE"
          },
          {
            "name": "type",
            "type": "STRING",
            "mode": "NULLABLE"
          }
        ]
      },
      {
        "name": "resource_name",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "resource_global_name",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "label",
        "type": "STRING",
        "mode": "NULLABLE"
      }
    ]
  },
  "InvoiceMonth": "202006",
  "credits": [
    {
      "v": {
        "f": [
          {
            "v": "ae391_credit:0"
          },
          {
            "v": "-0.010237"
          },
          {
            "v": "Committed dollar "
          },
          {
            "v": "ae31_credit:0"
          },
          {
            "v": "COMMITTED_BASE"
          }
        ]
      }
    },
    {
      "v": {
        "f": [
          {
            "v": "ae391_credit:0"
          },
          {
            "v": "-0.010237"
          },
          {
            "v": "Committed dollar "
          },
          {
            "v": "ae31_credit:0"
          },
          {
            "v": "COMMITTED_BASE"
          }
        ]
      }
    }
  ],
  "resource_name": "projects-0",
  "resource_global_name": "//compute.googleapis.com/",
  "label": ""
}

我试过这种震动:

[
  {
    "operation": "shift",
    "spec": {
      "credits": {
        "*": {
          "*": {
            "*": {
              "*": {
                "@v": "[&3].@(5,schema.fields.fields[&].name)"
              }
            }
          }
        }
      }
    }
  }
]

预期输出:

[
  {
    "name": "ae391_credit:0",
    "amount": "-0.010237",
    "full_name": "Committed dollar",
    "id": "ae31_credit:0",
    "type": "COMMITTED_BASE"
  },
  {
    "name": "ae391_credit:0",
    "amount": "-0.010237",
    "full_name": "Committed dollar",
    "id": "ae31_credit:0",
    "type": "COMMITTED_BASE"
  }
]
vmpqdwk3

vmpqdwk31#

您可以使用shift操作,并将内部fields向上移动,然后使用另一个移位来获取名称的值作为credits数组中的键。

[
  {
    "operation": "shift",
    "spec": {
      "credits": "&",
      "schema": {
        "fields": {
          "*": {
            "fields": "&"
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "credits": {
        "*": {
          "*": {
            "*": {
              "*": {
                "*": "[&4].@(6,fields[&1].name)"
              }
            }
          }
        }
      }
    }
  }
]

相关问题