Reading or writing the last record to a Sequential File

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
durgaps
Participant
Posts: 74
Joined: Sat Jul 08, 2006 4:09 am
Location: Melbourne, Australia
Contact:

Reading or writing the last record to a Sequential File

Post by durgaps »

Hi,

I have a source text file which has 10 recs and I am having a few transformations in the middle and putting the output to a sequential file again having 10 recs. Is there any way I can write only the last record i.e. the 10th record to the file.

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

Post by ray.wurlod »

Aggregator stage. Set the aggregation function to Last for every column.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
prabu
Participant
Posts: 146
Joined: Fri Oct 22, 2004 9:12 am

Re: Reading or writing the last record to a Sequential File

Post by prabu »

durgaps wrote:Hi,

I have a source text file which has 10 recs and I am having a few transformations in the middle and putting the output to a sequential file again having 10 recs. Is there any way I can write only the last record i.e. the 10th record to the file.

Thanks,
check for @OUTROWNUM and mod function. But please beware, when you use parallel jobs, then your definition of 10th record is no more valid.

example:-
Select the 10th record from a given table.
10th record can be the physical location, the 10th record from your data buffer, or may be the 10th record after sorting by date

you may also want to try @PARTITIONNUM and @NUMPARTITIONS to define your 10th record
durgaps
Participant
Posts: 74
Joined: Sat Jul 08, 2006 4:09 am
Location: Melbourne, Australia
Contact:

Re: Reading or writing the last record to a Sequential File

Post by durgaps »

prabu wrote:
durgaps wrote:Hi,

I have a source text file which has 10 recs and I am having a few transformations in the middle and putting the output to a sequential file again having 10 recs. Is there any way I can write only the last record i.e. the 10th record to the file.

Thanks,
check for @OUTROWNUM and mod function. But please beware, when you use parallel jobs, then your definition of 10th record is no more valid.

example:-
Select the 10th record from a given table.
10th record can be the physical location, the 10th record from your data buffer, or may be the 10th record after sorting by date

you may also want to try @PARTITIONNUM and @NUMPARTITIONS to define your 10th record
Hi Ray,

Thanks for the reply. I am using parallel extender and I dont find the LAST function in AGGREGATOR stage
Durga Prasad
m_keerthi2005
Participant
Posts: 22
Joined: Thu Jun 02, 2005 5:12 am

Post by m_keerthi2005 »

The last option may also be available in PX. when you use group by on any column then you may have to use last option.

If you are doing any group by, then other option could be use the MAX(Column) in the derivation column. this should solve your problem.
keshav0307
Premium Member
Premium Member
Posts: 783
Joined: Mon Jan 16, 2006 10:17 pm
Location: Sydney, Australia

Post by keshav0307 »

you can have a Trail stage to get the last N records.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

@OUTROWNUM can be used only if the number of records are predefined. Tail stage can be possible used based on your requirement.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
talk2shaanc
Charter Member
Charter Member
Posts: 199
Joined: Tue Jan 18, 2005 2:50 am
Location: India

Post by talk2shaanc »

if you want to read the last rows from the source file, you can use "external source" stage and then use unix command to get the last row.
tail -1 /#path#/filename.dat
Shantanu Choudhary
Post Reply