Forum Discussion
- eguoFormer Employee
Looks like you are facing a transformation issue. Normal snaps can do the job.
Assume your input data is flat like what’s in following picture.
They would looks like this in a snap preview:
[ { "S": "1", "STATUSDESCRIPTION": "Testing 1.", "P": "urgent" }, { "S": "2", "STATUSDESCRIPTION": "Testing 2.", "P": "normal" } ]
A pipeline like this will produce the expected output:
The Group By N snap can group individual input records into an array.
The Mapper snap should looks like this:
- matt_bostromNew Contributor II
this is perfect! on my health check call it was the same solution you provided. hopefully this helps others. @del I’m sure your solution works but this other one requires no code so good to know going forward!
- delContributor III
Yep, that’s good to know. I guess I missed the release of the Group By N snap. I wouldn’t have had to develop my own 🙂 .
- delContributor III
@matt.bostrom, The simplest way that I know of is to use a Script snap. I’m not a Python expert (so someone can improve on this), but code in the execute method would look something like this:
def execute(self): tickets = [] out = java.util.HashMap() while self.input.hasNext(): try: in_doc = self.input.next() tickets.append(in_doc) except Exception as e: errWrapper = { 'errMsg' : str(e.args) } self.log.error("Error in python script") self.error.write(errWrapper) out["tickets"] = tickets self.output.write(out)
I’ve run into similar needs before on a couple of occasions, so I have written a custom snap to achieve this same result. I can share the java code with you as well if you want to develop your own snap.