使用嵌套对象进行颠簸变换

jolt transform with nested object

    [
  {
    "cluster_id": "0125-175512-node489",
    "custom_tag": {
      "app_name": "testing1",
      "total_time": 32
    }
  },
  {
    "cluster_id": "0125-175512-node489",
    "custom_tag": {
      "app_name": "testing2",
      "total_time": 34
    }
  }
]

我希望o/p是这样的

1) 添加一个常量新字段"new_addition" 2) 将嵌套值 "custom_tag.app_name" 复制到上一层。 3) 将嵌套值 "custom_tag.total_time" 复制到上一层,但属性名称不同 "time_to_finish".

我无法弄清楚这个的震动规格。

    [
  {
    "cluster_id": "0125-175512-node489",
    "app_name": "testing1",
    "new_addition": "new const value",
    "time_to_finish": 32,
    "custom_tag": {
      "app_name": "testing1",
      "total_time": 32
    }
  },
  {
    "cluster_id": "0125-175512-node489",
    "app_name": "testing2",
    "new_addition": "new const value",
    "time_to_finish": 34,
    "custom_tag": {
      "app_name": "testing2",
      "total_time": 34
    }
  }
]

确保您的 new_addition 属性具有流文件的值。

Try with this Jolt spec:

[{
"operation": "shift",
"spec": {
    "*": "&", // get all elements
    "custom_tag": {
        "app_name": "app_name", //copy app_name to one level up
        "total_time": "time_to_finish", //copy total_time to one level up and change name.
        "@": "&" //get all the struct elements as is
    }
}
}, {
    "operation": "default",
    "spec": {
        "new_addition": "${new_addition}" //get the attribute value and add new_addition element to top level.
    }
}]

Output:

{
  "cluster_id" : "0125-175512-node489",
  "custom_tag" : {
    "app_name" : "testing2",
    "total_time" : 34
  },
  "app_name" : "testing2",
  "time_to_finish" : 34,
  "new_addition" : "new_addition"
}

Jolt transform Processor config:

Validation:

以下有效。

[{
  "operation": "shift",
  "spec": {
    "@": "&",
    "*": {
      "custom_tag": {
        "app_name": "&3[&2].app_name",
        "total_time": "&3[&2].time_to_finish"
      }
    }
  }
}, {
  "operation": "default",
  "spec": {
    "root[]": {
      "*": {
        "new_addition": "1"
      }
    }
  }
}]