Unique requirement to combine two files

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
reddy
Premium Member
Premium Member
Posts: 168
Joined: Tue Dec 07, 2004 12:54 pm

Unique requirement to combine two files

Post by reddy »

Hi,
I have a requirement to combine records from two input files, none of which is a Master. I want records from both merged, but on the same line.

Input file 1
53,red
53,blue
55,black
57,orange
57,violet


Input file 2
53,boy
53,cat
53,dog
54,pig
55,rat
56,girl


Expected Output is
53, red, boy
53, blue, cat
53, ,dog
54, , pig
55,black,rat
56, , girl
57, orange,
57, violet,

Any help is appreciated. Thanks.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Why not use an inner join in a join stage or a lookup stage (choose either link as a master) and have both Col2's go to the output?
hiral.chauhan
Premium Member
Premium Member
Posts: 45
Joined: Fri Nov 07, 2008 12:22 pm

Post by hiral.chauhan »

You might want to use a Look up stage like ArndW said, choose either link as a Master, Store the output of both the links, and concatenate them on their way to the target table/file. Does that make sense?
Thanks,
Hiral Chauhan
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

ArndW wrote:Why not use an inner join in a join stage or a lookup stage (choose either link as a master) and have both Col2's go to the output?
A full outer join would be needed to achieve all of the output specified. Other than that quibble I, too, would recommend using a Join stage.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
RAJARP
Participant
Posts: 147
Joined: Thu Dec 06, 2007 6:46 am
Location: Chennai

Post by RAJARP »

Hi Reddy,

I/P file 2------- >Join Stage--------->Target

I/P file1-------->(connect this link to Join Stage)

Set the properties of Join stage as follows:

Key:column containing value 53,54 etc
Join Type:left outer join

Link ordering:
---------------
Left:Link from I/p file 2
Right:Link from I/p file1

Try this.

Regards,
Raja R P
dxk9
Participant
Posts: 105
Joined: Wed Aug 19, 2009 12:46 am
Location: Chennai, Tamil Nadu

Post by dxk9 »

Just join the Key column with full outer join.This will give the desired output.

a. Input1 (fa,fb)
b. Input2 (fc,fd)
c. Join fa,fc (full outer join)
d. Pull fk(fa,fb),fc,fd to target.


Regards,
Divya
Last edited by dxk9 on Fri Sep 04, 2009 2:32 am, edited 1 time in total.
laknar
Participant
Posts: 162
Joined: Thu Apr 26, 2007 5:59 am
Location: Chennai

Post by laknar »

why don't use the funnel stage
give union option there
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

You cannot directly use a join stage as you have duplicate values which will result in cartesian join.

You need to add another a running sequence number and include it in your join.
RohitNara
Participant
Posts: 3
Joined: Wed Jan 07, 2009 2:22 am

Re: Unique requirement to combine two files

Post by RohitNara »

reddy wrote:Hi,
I have a requirement to combine records from two input files, none of which is a Master. I want records from both merged, but on the same line.

Input file 1
53,red
53,blue
55,black
57,orange
57,violet


Input file 2
53,boy
53,cat
53,dog
54,pig
55,rat
56,girl


Expected Output is
53, red, boy
53, blue, cat
53, ,dog
54, , pig
55,black,rat
56, , girl
57, orange,
57, violet,

Any help is appreciated. Thanks.

You can add the column say "Srno" to both the table in the transformer prior to the Join Stage. Data from both the table will look like
srno Column1 colum2
1,53,red
2,53,blue
1,55,black
1,57,orange
2,57,violet

and for second table
srno Column1 Column2
1,53,boy
2,53,cat
3,53,dog
1,54,pig
1,155,rat
1,56,girl

Logic to assign the values to "Srno" column as shown above is already posted on the forum.

You can use "FULL OUTER JOIN" in the join stage with key fields as "Srno" and column contains 53,54 ...

I hope this will give you the desired output.
RohitN
keshav0307
Premium Member
Premium Member
Posts: 783
Joined: Mon Jan 16, 2006 10:17 pm
Location: Sydney, Australia

Post by keshav0307 »

i implememnted the same requirement, using oracle rank function and full outer join
Post Reply