Order the records based on Date Value

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
Magesh_bala
Participant
Posts: 86
Joined: Mon Nov 27, 2006 3:42 am
Location: Wilmington

Order the records based on Date Value

Post by Magesh_bala »

Hi All,

I have a scenario where I need to group the records based on the Order...

Input Records

ITM_INST Start Ts PTY_ID End Ts

123 1/1/2008 456 12/31/2008
123 1/1/2009 456 12/31/2009
123 1/1/2010 456 12/31/2010
123 1/1/2011 567 12/31/2011
123 1/1/2012 456 12/31/9999

In the above Input records I need to get three rows as Output...

I need to group rows 1 to 3 Since its same ITM_INST and PTY_ID...
and then row 4, 5 as as separate rec..

Output Should be

ITM_INST Start Ts PTY_ID End Ts

123 1/1/2008 456 12/31/2010
123 1/1/2011 567 12/31/2011
123 1/1/2012 456 9999

Please let me know how can I implement in Datastage.

Note: I'm using Datastage version 8.5
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

OK, I'll start... what have you tried? Anything involving an Aggregator perhaps?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Magesh_bala
Participant
Posts: 86
Joined: Mon Nov 27, 2006 3:42 am
Location: Wilmington

Post by Magesh_bala »

Thanks Craig...
First I tried with Aggregator Stage using Min(Start date) and max(end date)
But it doesn't return correct values... I have a over lap

Second option using Stage Variable in Transformer by comparing prev row and current row I have rows
0
1
1
0
0
I'm not sure how to to split the records...
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

For the sample data you posted, the aggregation approach you mentioned is what I was going to suggest and should work fine... again, for the example you chose to post. Can you show us the input and output data that shows the "overlap"?

Show us your problem child. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Magesh_bala
Participant
Posts: 86
Joined: Mon Nov 27, 2006 3:42 am
Location: Wilmington

Post by Magesh_bala »

Hi Criag,

Please find the output from Aggregator Stage...

ITM_INST Start Ts PTY_ID End Ts

123 1/1/2008 456 12/31/9999
123 1/1/2011 567 12/31/2011

When I group by ITM_INST and PTY_ID first 3 records and last records is considered as one group and 4th records as separate record....

I have overlap...
ntr
Participant
Posts: 110
Joined: Fri Dec 18, 2009 10:30 am
Location: pune

Post by ntr »

can you post what Exact input and what exact output do you want
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You're right, didn't notice that the last group was the same as the first group so that aggregation while correct is not what you want.

For your stage variables, 0 means the record is the first record of a new group, the 1 means it is another record in the same/current group. If you have the 8.5+ version, you could use transformer looping to take information from both the 'first' and 'last' record in each group, understanding that they could be the same record.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

ntr wrote:can you post what Exact input and what exact output do you want
They did, the first post shows that. The second example shows what they got instead of what they need when taking the aggregation route.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Magesh_bala
Participant
Posts: 86
Joined: Mon Nov 27, 2006 3:42 am
Location: Wilmington

Post by Magesh_bala »

So We need to get the
0
1
1
Using the transformer stage by comparing the prev and Curr record and then do the Looping?

yes I have Datastage 8.5 Version...
Magesh_bala
Participant
Posts: 86
Joined: Mon Nov 27, 2006 3:42 am
Location: Wilmington

Post by Magesh_bala »

I got the Logic to fix the issue...

PrevVal CurrVal
CurrVal 123:456

PrevAct CurrAct
CurrAct If Currval=PrevVal Then PrevAct Else PrevAct+1


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

Post by ray.wurlod »

If you want to use Min and Max on dates in the Aggregator stage you have to set the Preserve Type property.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Magesh_bala
Participant
Posts: 86
Joined: Mon Nov 27, 2006 3:42 am
Location: Wilmington

Post by Magesh_bala »

Thanks Ray!!!
Post Reply