04-21-2021 09:52 PM
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”}]
]
04-22-2021 08:14 AM
Hi @thilkip ,
Use Pipeline Execute with the option Reuse executions to process documents set to disabled. Inside this pipeline put your input data and use group by n. Something like this:
04-22-2021 08:17 AM
yes. this will work but we dont want to call child as it is a ultra task and wanted to have ms response time
04-22-2021 08:43 AM
A triggered task has more latency than ultra, but doesn’t have any restriction on types of Snaps. Is the performance suitable for your use case?
04-22-2021 08:46 AM
not really, that is the challenge we are running into…looking to get the millisecond response from api using ultra task
04-22-2021 08:43 AM
Use this script, it groups all inputs into single array:
execute : function () {
this.log.info("Executing Transform Script");
var groupByN = new ArrayList();
var wrapper = {};
while (this.input.hasNext()) {
try {
// Read the next input document, store it a new LinkedHashMap, and write this as an output document.
// We must use a serializable Java type liked LinkedHashMap for each output instead of a native
// JavaScript object so that downstream Snaps like Copy can process it correctly.
var inDoc = this.input.next();
groupByN.add(inDoc);
wrapper = {"Data": groupByN};
}
catch (err) {
var errDoc = new LinkedHashMap();
errDoc.put("error", err);
this.log.error(err);
this.error.write(errDoc);
}
}
this.output.write(wrapper);
this.log.info("Script executed");
}
I tested it with ultra task and it seems it works.