My understanding about the question is you have a csv with a header and line(s). you are processing them differently and after that you want the data in CSV style first line is header and rest is content (line/s).
If so I would like to suggest two different solutions :
- use a json splitter right after the CSV snap. you can configure it as:
this can take sometime during insertion but each line will have a header
- after doing union you can use a script snap. Here is my jython (python) code. You can use JS or ruby:
#Import the interface required by the Script snap.
from com.snaplogic.scripting.language import ScriptHook
import java.util
class TransformScript(ScriptHook):
def init(self, input, output, error, log):
self.input = input
self.output = output
self.error = error
self.log = log
#The “execute()” method is called once when the pipeline is started
# and allowed to process its inputs or just send data to its outputs.
def execute(self):
self.log.info(“Executing Transform script”)
wrapper = java.util.ArrayList()
while self.input.hasNext():
try:
# Read the next document, wrap it in a map and write out the wrapper
in_doc = self.input.next()
#wrapper['original'] = in_doc
header = in_doc.get('DOCUMENTHEADER')
line_acc = in_doc.get('ACCOUNTGL')
line_cur = in_doc.get('CURRENCYAMOUNT')
if (header != None):
wrapper.add(0, header)
if (line_acc != None):
wrapper.add(line_acc)
if (line_cur != None):
wrapper.add(line_cur)
except Exception as e:
errWrapper = {
'errMsg' : str(e.args)
}
self.log.error("Error in python script")
self.error.write(errWrapper)
self.output.write(in_doc, wrapper)
self.log.info("Finished executing the Transform script")
#The Script Snap will look for a ScriptHook object in the “hook”
#variable. The snap will then call the hook’s “execute” method.
hook = TransformScript(input, output, error, log)
the output will be an array which has header at 0th index follwed by lines
Hope this helps!