Converting rows into column

I am trying below data converting rows into columns

input:
[
{
“CARRIERCODE”: “abc”,
“SHIPCARRIERTRACKINGNUM”: “531”,
“DATETIMEVALUE”: “2022-05-16 08:05:00”,
“DATETIMETYPE”: “ACTUAL_DELIVERY”,
“DATEVALUE”: “2022-05-16”
},
{
“CARRIERCODE”: “abc”,
“SHIPCARRIERTRACKINGNUM”: “531”,
“DATETIMEVALUE”: “2022-05-11 09:31:00”,
“DATETIMETYPE”: “ACTUAL_PICKUP”,
“DATEVALUE”: “2022-05-11”
},
{
“CARRIERCODE”: “abc”,
“SHIPCARRIERTRACKINGNUM”: “531”,
“DATETIMEVALUE”: “2022-05-11 12:00:00”,
“DATETIMETYPE”: “SHIP”,
“DATEVALUE”: “2022-05-11”
},
{
“CARRIERCODE”: “abc”,
“SHIPCARRIERTRACKINGNUM”: “531”,
“DATETIMEVALUE”: “2022-05-11 09:49:00”,
“DATETIMETYPE”: “ACTUAL_TENDER”,
“DATEVALUE”: “2022-05-11”
},

expected output:

any leads here

Hi @kkishore,

Group the incoming data by CARRIERCODE & SHIPCARRIERTRACKINGNUM:

image

And add the following expression in a mapper after the group by snap:

$group.map(x=>{[x.DATETIMETYPE+"_DATETIMEVALUE"]:x.DATETIMEVALUE,[x.DATETIMETYPE+"_DATEVALUE"]:x.DATEVALUE}).reduce((acc,curr)=>acc.extend(curr),{}).extend($groupBy)

Hope this helps,
Regards

3 Likes

Thank you @bojanvelevski , perfect it is working as expected.

Thank you @kkishore, can you please mark @bojanvelevski’s suggestion as a Solution so that anybody looking at this thread in the future can refer to the solution directly?

1 Like