Jolt: concat Array values

久未见 提交于 2020-06-01 06:41:00

问题


Following my previous post Jolt: split/ concat array values in Nifi

Now I'd like another value (ts) to be replicated into each split. My input:

[
  {
    "value0": 0,
    "value1": 1,
    "value2": 2,
    "ts": 1
  },
  {
    "value0": 3,
    "value1": 4,
    "value2": 5,
    "ts": 2
  }
]

Desired output:

[ {
  "value0" : 0,
  "ts": 1
}, {
  "value1" : 1,
  "ts": 1
}, {
  "value2" : 2,
  "ts": 1
}, {
  "value0" : 3,
  "ts": 2
}, {
  "value1" : 4,
  "ts": 2
}, {
  "value2" : 5,
  "ts": 2
} ]

The initial Jolt:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "value*": "[].&"
      }
    }
}
]

Thanks !


回答1:


At the max you could do this, beyond this to achieve the above will be very tricky, using some chained spec it might be possible.

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "value*": "[].&",
        "ts": "[].&"
      }
    }
  }
]

Output for above spec:

[ {
  "ts" : 1
}, {
  "value0" : 0
}, {
  "value1" : 1
}, {
  "value2" : 2
}, {
  "ts" : 2
}, {
  "value0" : 3
}, {
  "value1" : 4
}, {
  "value2" : 5
} ]


来源:https://stackoverflow.com/questions/61416100/jolt-concat-array-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!