cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Merge multiple documents to an array in ultra pipeline

thilkip
New Contributor

We need to merge multiple documents to single array and looking for help. Since it is ultra task, we are running out of optionsโ€ฆ

Input data:

[
{โ€œRecordโ€: โ€œ1โ€},
{โ€œRecordโ€: โ€œ2โ€},
{โ€œRecordโ€: โ€œ5โ€},
{โ€œRecordโ€: โ€œ4โ€},
{โ€œRecordโ€: โ€œ6โ€}
]

Expected Output:
[ โ€œresponseโ€: [{โ€œRecordโ€: โ€œ1โ€}, {โ€œRecordโ€: โ€œ2โ€}, {โ€œRecordโ€: โ€œ5โ€}, {โ€œRecordโ€: โ€œ4โ€}, {โ€œRecordโ€: โ€œ6โ€}]
]

25 REPLIES 25

koryknick
Employee
Employee

I donโ€™t have a DB2 instance to test with at the moment, but it appears you could do the same thing with different syntax:

koryknick
Employee
Employee

It should be noted that Iโ€™m recommending that you push the creation of the array back to the source database because you are trying to prevent calling a child pipeline, which is the recommended pattern for aggregating data in an Ultra pipeline. This is required because Ultra is a streaming service of one record in, one record out. So any type of function that aggregates data (including Sort, Group By *, etc) will be stuck waiting on end of upstream input which will never come because of the nature of the data flow in Ultra. This is also why your Script snap isnโ€™t working the way you were expecting - itโ€™s waiting on the end of input, which never comes in an Ultra pipeline.

bojanvelevski
Valued Contributor

Hi again @thilkip,

This task of yours was very intriguing, so I dedicated quite sometime experimenting and I found a solution that works in development mode, with snaps supported by Ultra Task. Here is the pipeline:

Documents_to_Array_Format.slp (7.3 KB)

Here is the final result:

image

I am pretty curious about this one, can you please send feedback on the pipelineโ€™s behaviour?
In addition I am sending you a Python script, that is also tested and works. I know that you allready tried with a script but I am offering some options. Thanks,

Doc_to_Array.txt (1.6 KB)

Best Regards,
Bojan

Thank you for your time and help. We did validate the script in ultra task and saw the same behavior like earlier.

image

We will test the other approach using Formatter snap and let you know.

Thank you again

vamsi
New Contributor II

@thilkip Have you been able to achieve this scenario using the Script in the Ultra sscenario. We ran in to the same problem