Filter stage and dynamic file creation

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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

I don't believe it can be done using dynamically generated file names without creating some code. I would be happy to be corrected.

What's the basis of the Filter stage? You can't have a dynamic number of output links! What's your strategy for separating the countries? About the only strategy with a Filter stage would be to have an output link for every possible country. Some output links will receive zero rows. These can be detected subsequently.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Ultramundane
Participant
Posts: 407
Joined: Mon Jun 27, 2005 8:54 am
Location: Walker, Michigan
Contact:

Post by Ultramundane »

Could you use an external target stage for your job? You could create a shell script similar to the one below. It will create a file for each distinct value of $1 (the first field), named $1.file.

Code: Select all

#!/bin/ksh

AFS="${1}"
DIR="${2}"

awk -vAFS="${AFS}" -vDIR="${DIR}" 'BEGIN {FS=AFS;OFS=AFS;} 
{
  ## CTRY FILE NAME
  FNAME=$1".file";
  print $0 >DIR""FNAME;
}'

exit 0
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Nice technique. Maybe >> would be better in the print command. This would not overwrite the file for each new record from that country.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Ultramundane
Participant
Posts: 407
Joined: Mon Jun 27, 2005 8:54 am
Location: Walker, Michigan
Contact:

Post by Ultramundane »

awk will keep track of what files it has used/opened. Once awk is stated, any new file used/opened will be overwritten the first time. Any file re-used after that will be appended.

Basically, > is the same thing as
>
followed by
>>

in a normal shell script.

Thanks,
Ryan
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

My bad. Failed to take into account that the print was an awk print - that is, in an awk block. Come's from replying after my bed time.
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