преобразование толчка с вложенным объектом - PullRequest
0 голосов
/ 07 февраля 2020
    [
  {
    "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_fini sh».

Я не могу определить jolt-spe c для этого.

    [
  {
    "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
    }
  }
]

Ответы [ 2 ]

0 голосов
/ 10 февраля 2020

подписка сработала.

[{
  "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"
      }
    }
  }
}]
0 голосов
/ 08 февраля 2020

Убедитесь, что у вас есть атрибут 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:

enter image description here

Validation:

enter image description here

...