hnandarusdy
hnandarusdy

Reputation: 452

merge rows in pentaho PDI kettle

I was wondering if I could merge 2 or more rows in pentaho?

example: I have 2 rows of

case:'001',
owner:'Barack'
date:'2017-04-10'

case:'001',
owner:'Trump'
date:'2017-02-10'

Then I want to have a mongoDB output :

case:'001'
ownerHistory:[
{
owner:'Barack'
date:'2017-04-10'
},
{
owner:'Trump'
date:'2017-02-10'
}
]

Upvotes: 0

Views: 837

Answers (1)

Cyrus
Cyrus

Reputation: 2195

The MongoDB Output step supports modifier updates that affect individual fields in a document and the $push operation to add items to a list/array. Using those, you don't need to merge any rows, you can just send them all to the MongoDB Output step.

With the Modifier update active each next row will be either inserted if the case doesn't exist yet or have the owner added to the array if it does.

Unfortunately, if you run this transformation a second time with the same incoming data, it will add more copies of the owners. I haven't found a way to fix that, so I hope you don't have that in your use case.

Perhaps if you split the data and insert/replace the using the first record for each case, then do the $push updates for the second and later records you can manage it.

MongoDB configuration screenshot

Upvotes: 1

Related Questions