Top values in desc order based on key column

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

nani0907
Participant
Posts: 155
Joined: Wed Apr 18, 2007 10:30 am

Top values in desc order based on key column

Post by nani0907 »

Hi all,

My requirement is to pull top 3 values based on Key column A.
my input data is like:

ColumnA ColumnB
A 90.1
B 80.4
A 70.3
C 30.0
A 10.1
A 50.4
B 20.5
B 03.5

Required output:top 3 values of column B and columnA should also be in asc order

A 90.1
A 70.3
A 50.4
B 80.4
B 20.5
B 03.5

Please guide me how to get this

Thanks in advance.
thanks n regards
nani
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

WHat have you tried? It should be a straightforward sorting and filtering specification.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
nani0907
Participant
Posts: 155
Joined: Wed Apr 18, 2007 10:30 am

Post by nani0907 »

Hi Ray,

I have done by using sort stage and in transformer i have limited the output to 3 rows . but i need to get 3 records for each key column.
thanks n regards
nani
nani0907
Participant
Posts: 155
Joined: Wed Apr 18, 2007 10:30 am

Post by nani0907 »

I have used sort stage and limited the output to 3 rows.

But i need to get top 3 columnB values based on each key values
thanks n regards
nani
bi_fujitsu
Premium Member
Premium Member
Posts: 46
Joined: Tue Mar 20, 2007 3:30 am
Location: India

Post by bi_fujitsu »

Source--->SortStage(Sort Column A Ascending and ColumnB Descending and Partition on Column A)-->HeadStage (No. of rows per partition=3, partitioning Same)-->Target
nani0907
Participant
Posts: 155
Joined: Wed Apr 18, 2007 10:30 am

Post by nani0907 »

Given in sort stage Column A as ASC and ColumnB DESC,then you have mentioned about Partitioning and head stage.Could you please elobarate on this.
thanks n regards
nani
bi_fujitsu
Premium Member
Premium Member
Posts: 46
Joined: Tue Mar 20, 2007 3:30 am
Location: India

Post by bi_fujitsu »

Theres not much to elaborate, but let me give it a try.

In the Sort Stage Hash Partition the data on Column A. In the HeadStage keep partitioning as Same. The head stage asks you for the no. of rows you require per partition, mention 3 there.
nani0907
Participant
Posts: 155
Joined: Wed Apr 18, 2007 10:30 am

Post by nani0907 »

Thanks a lot .
Its working Fine.
thanks n regards
nani
nani0907
Participant
Posts: 155
Joined: Wed Apr 18, 2007 10:30 am

Post by nani0907 »

hi,

iam unable get 3 records for each key column.
Its showing only for some key values.
Please guide me.
thanks n regards
nani
bi_fujitsu
Premium Member
Premium Member
Posts: 46
Joined: Tue Mar 20, 2007 3:30 am
Location: India

Post by bi_fujitsu »

nani0907 wrote:hi,

iam unable get 3 records for each key column.
Its showing only for some key values.
Please guide me.
Ensure that you have partitioned the data "only" on Column A in the Sort Stage and have kept the partitoning "Same" in the Head Stage.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

nani0907 wrote:hi,

iam unable get 3 records for each key column.
Its showing only for some key values.
Please guide me.
use transformer then and using stage variables restrict the count to 3.

assign a count to each row after sorting and hash partitioning the input. and inly pass top 3 values using constraints.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
nani0907
Participant
Posts: 155
Joined: Wed Apr 18, 2007 10:30 am

Post by nani0907 »

Ater Sort stage ,i have transformer and used the partioning method same and then head stage with same partion. still the same issue.
thanks n regards
nani
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

nani0907 wrote:Ater Sort stage ,i have transformer and used the partioning method same and then head stage with same partion. still the same issue.

I am not talking about head stage. It returns 3 records per partition,

If my concepts are correct there may be more than one key value present in one partition. But hash partiotioning ensures that records with same key value goes to one partition. Remove head stage and use transformer. as explained earlier.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
nani0907
Participant
Posts: 155
Joined: Wed Apr 18, 2007 10:30 am

Post by nani0907 »

Though i have used transformer, getting the same results.Not populating for all the key values.

please help me out.
thanks n regards
nani
srinivas.g
Participant
Posts: 251
Joined: Mon Jun 09, 2008 5:52 am

Post by srinivas.g »

Sequential file --> copy--> copy--->transformer-->aggregator
| |

Join <--- filter
|
output
Srinu Gadipudi
Post Reply