Column order logic clarification

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
vamsi.4a6
Participant
Posts: 334
Joined: Sun Jan 22, 2012 7:06 am
Contact:

Column order logic clarification

Post by vamsi.4a6 »

I have a file consists of 3 columns col1,col2,col3 and i want to load this data into a table.I am facing below problem while loading data into table.

Number of columns are fixed in file but the order of columns may vary.i can expect any order in the file
ex:-col1,col2,col3
col3,col2,col1
col2,col3,col1 etc

Not sure how to mention metadata in column tab of sequential file and is there anyway to implement this logic in datastage,if it is not possible to implement in datastage i will look into Unix solution.Any input is really apreciated
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I'd have a serious chat with whomever is generating that file for you, that sounds completely... nonsensical. Can you post a real example of the file so we can get some idea if the contents can be used to determine which target column they belong to?

And no, I don't see RCP as an option here.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DataStage_Sterling
Participant
Posts: 26
Joined: Wed Jul 17, 2013 9:00 am

Re: Column order logic clarification

Post by DataStage_Sterling »

This is a very unusual requirement. How about asking for a schema file for every source file you get? Is it possible? If yes, I believe, you can use schema file for metadata and RCP for column propagation. If not, you do not have a set pattern (consistent) of the problem to resolve. Hence it is not possible to implement in any technology.
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Re: Column order logic clarification

Post by rkashyap »

Can get the file with column headers? If yes, then you can propogate data to the correct destination column for incoming data in a transformer.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I don't see either column headers or a schema file being possible here. I base that on the assumption that they mean the file can contain columns in any order record by record in a single file. This rather than a fixed but 'random' order file by file.

Vamsi, can you clarify please?
-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 »

This problem is most easily remedied by talking with whoever is producing the file. Having some kind of threat available would also help.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
vamsi.4a6
Participant
Posts: 334
Joined: Sun Jan 22, 2012 7:06 am
Contact:

Post by vamsi.4a6 »

I can not post real data due to security issues in my project but following example
will help for better understanding

empid,ename,sal
1,vamsi,10
2,sam,20
3,ram,30

or

ename,sal,empid
vamsi,10,1
sam,20,2
ram,30,3

or

empid,sal,ename
1,10,vamsi
2,20,sam
3,30,ram


I want to load into a table which consists of columns defined in order empid,ename,sal
Thanks and Regards
Vamsi krishna.v
http://datastage-vamsi.blogspot.in/
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

Request file with column headers. Trap column header row in a Transformer's stage variables ... then using stage variable value, propagate data to the correct destination column.
vamsi.4a6
Participant
Posts: 334
Joined: Sun Jan 22, 2012 7:06 am
Contact:

Post by vamsi.4a6 »

@rkashyap

could you please elaborate more what ever u explained?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You need the column headers. The suggestion is to read them in as data, note which one is which and direct the output for the rest of the lines accordingly.
-craig

"You can never have too many knives" -- Logan Nine Fingers
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

As Craig has said read all rows as data, and direct the output for the rest of the lines accordingly. i.e.

1. Execute the transformer in Sequential mode.
2. Read all columns as varchar.
3. Store values from first row (i.e Header row) in Stage variable.
4. In Output add a constraint to skip Header row.
5. In Derivation, populate output columns based on values of input (and if needed. perform Sqltype coversion). eg Populate EName as
If StgVar1 = "ename" then indat.Col1Val else
If StgVar2 = "ename" then indat.Col2Val else
If StgVar3 = "ename" then indat.Col3Val else
@Null
Post Reply