Data Stage CSV column seperation to Multiple rows

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
aahmadfarooq
Participant
Posts: 2
Joined: Thu Apr 09, 2015 5:18 am

Data Stage CSV column seperation to Multiple rows

Post by aahmadfarooq »

Hi,

I have a Table which contains data in this format:

ID CITIES
12 Lahore,Karachi,Islamabad
23 Dubai, Abu Dhabi
45 New York
46 London

I need to separate this data like this:
ID CITIES
12 Lahore
12 Karachi
12 Islamabad
23 Dubai
23 Abu Dhabi
45 New York
46 London

Please suggest some ways in Data stage
Ahmad
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Welcome.

Normally we'd start by asking things like 'what have you tried?' and 'what issues have you seen?'. Show us that you've at least tried to solve your puzzle before you came here and just posted input and output. In this case though, it's just a one word answer: pivot.

More specifically: a horizontal pivot of columns to rows. Oddly enough, there's a stage for that. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Thomas.B
Participant
Posts: 63
Joined: Thu Apr 09, 2015 6:40 am
Location: France - Nantes

Post by Thomas.B »

I use to have the same issue, i had that input :

FIELD
---------------
AAA;BBB;CCC;DDD
AAA;BBB;CCC;DDD


And i had to get that output :
FIELD
---------------
AAA
BBB
CCC
DDD
AAA
BBB
CCC
DDD

I do it by using a loop on a transformer (i think it's aviable since DataStage 8.5) :

I create a Stage Variable (CommaNum) with the value :
2 + Count(InputLink.FIELD,";")

My loop condition
@ITERATION < CommaNum

And my output field derivation
Field(InputLink.FIELD,";",@ITERATION)
Last edited by Thomas.B on Thu Apr 09, 2015 9:44 am, edited 1 time in total.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Yes, that's a good alternative when you don't know how many columns may need to be pivoted or at least don't know the maximum number. And yes, available since 8.5.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

I would have thought that the Column Import stage could have been involved here, prior to Pivot.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply