cancel
Showing results for 
Search instead for 
Did you mean: 

Converting rows into column

kkishore
New Contributor III

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:

image

any leads here

1 ACCEPTED SOLUTION

bojanvelevski
Valued Contributor

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

View solution in original post

3 REPLIES 3

bojanvelevski
Valued Contributor

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

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?