transformer

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
kittu.raja
Premium Member
Premium Member
Posts: 175
Joined: Tue Oct 14, 2008 1:48 pm

transformer

Post by kittu.raja »

Hi Everyone,

My design is

FF -------- XFM-------------FF

In my transformer i am deriving some columns and in one of the column I need the count of the source file.Without using aggragater can i achieve my goal inside the transformer.

Can anybosy help me out in this.

Thanks,
Rajesh Kumar
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Why cant you use aggregator?
You are the creator of your destiny - Swami Vivekananda
chowdhury99
Participant
Posts: 43
Joined: Thu May 29, 2008 8:41 pm

Post by chowdhury99 »

Use Execute Command stage in Sequence and use wc -l filename command to get the total count.

Thanks
vivekgadwal
Premium Member
Premium Member
Posts: 457
Joined: Tue Sep 25, 2007 4:05 pm

Re: transformer

Post by vivekgadwal »

kittu.raja wrote:Hi Everyone,

My design is

FF -------- XFM-------------FF

In my transformer i am deriving some columns and in one of the column I need the count of the source file.Without using aggragater can i achieve my goal inside the transformer.

Can anybosy help me out in this.

Thanks,
Get another Sequential file stage which has two columns defined in it. Let the datatype of one of the fields be Integer/Varchar and the length depends on how big your row count is and the other is Character.

Code: Select all

DmyCol1 - Char(1)
RowCount - Integer or Character.
In the job's before job sub-routine, execute the following command:

Code: Select all

echo "X|`wc -l {file name for which counts are required}`" > {another file to store this result}
Read this file from the second Seq. file stage. In your XFM, generate a dummy column with the value 'X' in it and after this, join it with the second file's data. You job design would look like this:

Code: Select all

Sequential File 1 ----------- XFM ----------- LKUP/JNR ----------- Sequential File output
                                                  |
Sequential File 2 ---------------------------------
Hope this helps...
Vivek Gadwal

Experience is what you get when you didn't get what you wanted
meet_deb85
Premium Member
Premium Member
Posts: 132
Joined: Tue Sep 04, 2007 11:38 am
Location: NOIDA

Re: transformer

Post by meet_deb85 »

Hi
Exact command is

Code: Select all

echo "X|`ls -l {file name for which counts are required}|wc -l|bc`"
vivekgadwal wrote:
kittu.raja wrote:Hi Everyone,

My design is

FF -------- XFM-------------FF

In my transformer i am deriving some columns and in one of the column I need the count of the source file.Without using aggragater can i achieve my goal inside the transformer.

Can anybosy help me out in this.

Thanks,
Get another Sequential file stage which has two columns defined in it. Let the datatype of one of the fields be Integer/Varchar and the length depends on how big your row count is and the other is Character.

Code: Select all

DmyCol1 - Char(1)
RowCount - Integer or Character.
In the job's before job sub-routine, execute the following command:

Code: Select all

echo "X|`wc -l {file name for which counts are required}`" > {another file to store this result}
Read this file from the second Seq. file stage. In your XFM, generate a dummy column with the value 'X' in it and after this, join it with the second file's data. You job design would look like this:

Code: Select all

Sequential File 1 ----------- XFM ----------- LKUP/JNR ----------- Sequential File output
                                                  |
Sequential File 2 ---------------------------------
Hope this helps...
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: transformer

Post by chulett »

meet_deb85 wrote:Exact command is

Code: Select all

echo "X|`ls -l {file name for which counts are required}|wc -l|bc`"
What? There's absolutely no need to "list" anything and I have no idea what role you think the "binary calculator" is playing here. :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
vivekgadwal
Premium Member
Premium Member
Posts: 457
Joined: Tue Sep 25, 2007 4:05 pm

Re: transformer

Post by vivekgadwal »

chulett wrote:
meet_deb85 wrote:Exact command is

Code: Select all

echo "X|`ls -l {file name for which counts are required}|wc -l|bc`"
What? There's absolutely no need to "list" anything and I have no idea what role you think the "binary calculator" is playing here. :?
Very true. The command that I gave should do the trick for the OP.
Vivek Gadwal

Experience is what you get when you didn't get what you wanted
kittu.raja
Premium Member
Premium Member
Posts: 175
Joined: Tue Oct 14, 2008 1:48 pm

Re: transformer

Post by kittu.raja »

[quote="vivekgadwal"][quote="chulett"][quote="meet_deb85"]Exact command is

Code: Select all

Hi Everyone,

Thank you for the response. 

I want it in transformer itself. 
Can I do using stage variables if yes how can I achieve it.

If that it is not possible then I will use before sub routine.

Thanks,
Rajesh Kumar
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

What do you mean by 'count of source file' ?

If you have data from 5 files, will each data record carry 1,2,3,4,5 or will they all have 5 ?
kittu.raja
Premium Member
Premium Member
Posts: 175
Joined: Tue Oct 14, 2008 1:48 pm

Post by kittu.raja »

Sainath.Srinivasan wrote:What do you mean by 'count of source file' ?

If you have data from 5 files, will each data record carry 1,2,3,4,5 or will they all have 5 ?
I have only one file and I want to count the number of records in a file using transformer.

Thanks,
Rajesh Kumar
vivekgadwal
Premium Member
Premium Member
Posts: 457
Joined: Tue Sep 25, 2007 4:05 pm

Post by vivekgadwal »

kittu.raja wrote:
Sainath.Srinivasan wrote:What do you mean by 'count of source file' ?

If you have data from 5 files, will each data record carry 1,2,3,4,5 or will they all have 5 ?
I have only one file and I want to count the number of records in a file using transformer.

Thanks,
Is there a problem creating a dummy file for the duration of the job's run? I guess what Sainath and even I want to know is, "why the insistence in having this within a transformer?" as there are other simple ways - the way I proposed for example - to do this!
Vivek Gadwal

Experience is what you get when you didn't get what you wanted
Post Reply