append column

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
DSkkk
Charter Member
Charter Member
Posts: 70
Joined: Fri Nov 05, 2004 1:10 pm

append column

Post by DSkkk »

hi all,
i want to append a new column from a file which has only 1 row to another file which has three other columns. i do not have any common columns. but the output file should have all the rows of the second file populated with the same data of the only row in the first file.
for example:
**first file**
date
2004-01-19

**second file**
no code perm
1 A y
2 B n
3 C y

**output file**
date no code perm
2004-01-19 1 A y
2004-01-19 2 B n
2004-01-19 3 C y

i tried using a merge stage and a transformer, but did not get the required output.
can anyone suggest?
thanks.
g.kiran
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Put the first file's single record into a hash file with a hard-coded key value - like a '1'. Then stream in your second file, do the lookup and add the column to the output.

Easy Peasy. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

You could also open file 1 using a routine and retrieve the value. Pass this value into your job as a job parameters. Use the job to retrieve the contents of file 2 and output the job parameter with each row of file 2.

It is quite easy in a Sequence job to set a job parameter by calling a routine. In your job stage set the Value Expression to the name and input arguments of your routine.

Name Value Expression
INPUTDATE rGetInputDate(FilePath:InputFileName)

The routine opens the file and returns the date to the Value Expression.
chucksmith
Premium Member
Premium Member
Posts: 385
Joined: Wed Jun 16, 2004 12:43 pm
Location: Virginia, USA
Contact:

Post by chucksmith »

On Craig's hashed file design, enable the Pre-load file to memory option in the Hashed File stage.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

True. Shouldn't be any problem loading the entire hash file into memory. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Try this command

for i in `cut -f1 -d" " t2`
do
cat t1 >> /tmp/testfile
done

paste /tmp/testfile t2

Where t1 is the first file with the date and t2 is the second file with multiple rows
Post Reply