Merging rows into a string

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
sim
Participant
Posts: 13
Joined: Wed Feb 18, 2004 6:20 pm

Merging rows into a string

Post by sim »

I have data in a sequential file. My data look like this:

25UB|23435
25XZ|89435
25MB|46377
25MD|38204
25YN|32048

I want to convert this data to:
25UB|23435|25XZ|89435|25MB|46377|25MD|38204|25YN|32048

Thanks
vigneshra
Participant
Posts: 86
Joined: Wed Jun 09, 2004 6:07 am
Location: Chennai

Post by vigneshra »

You can achieve this very easily using stage variables. Keep accumulating the rows into a string without passing them onto the target and after the all the rows are appended pass the string at a stretch to the target.
Someswar Barkataki
Participant
Posts: 6
Joined: Tue Jul 13, 2004 7:40 am

Re: Merging rows into a string

Post by Someswar Barkataki »

Vigneshra,

Could you please explain how to know that job has reached the last row of the input file and how to pass only the last appended row?

I had faced the similar problem, and I solved it creating a new column appending each row values using a stage variable as Vigneshra mentioned. This gives me concatanated row values at the last row of my new column. However, I donot know how to determine the end of the input file to pass only the last row. That's why I passed all the rows and created a sequential file. Then I created a hash file taking the sequential file as input just to get the last row.

I feel my design is not the best one but still it works.
Thanks,
Somesh
sim
Participant
Posts: 13
Joined: Wed Feb 18, 2004 6:20 pm

Post by sim »

I did like this:
I declared two stage variables...mergedRow, i, and totalRecCount
mergedRow = If @INROWNUM = i Then InputLink.col1 else mergedRow: InputLink.col1
i = i+1 (i has initial value 0)

Now, in the output link from the transformer, I put a constraint @INROWNUM = totalRecCount

I am getting totalRecCount through Aggregator, Merge to the transformer.

This output only the last fully merged record with out having to store the data in a file.
Post Reply