Saturday, May 10, 2014

DataStage Scenario on Finding Unique Distance from Source and Destination

Posted by Venkat ♥ Duvvuri 2:46 AM, under | 1 comment

Source,Destination,Distance
hyd,bang,1000
delhi,chennai,1500
chennai,bang,600
bang,hyd,1000
bombay,pune,1000
bang,chennai,600

**Sorted on Distance**

Source,Destination,Distance
bang,chennai,600
chennai,bang,600
bang,hyd,1000
bombay,pune,1000
hyd,bang,1000
delhi,chennai,1500

**Stg Variables**
PrevActualStr: ActualStr
ActualStr: inp.Src:inp.Dest
RevStr: inp.Dest:inp.Src
isDup: if PrevActualStr = RevStr then 1 else 0

**Constraint**
isDup = 0 [Constraint]

The below steps will explain you, How the records will be processed to o/p based on the above criteria.

Rec-1:

PrevActualStr: Garbage value
ActualStr: bangchennai
RevStr: chennaibang
isDup: 0 [if PrevActualStr = RevStr then 1 else 0]

isDup = 0 [Rec will be processed to o/p as per our constraint isDup=0]

O/P
Src Dest Distance
bang chennai 600


Rec-2:

PrevActualStr: bangchennai
ActualStr: chennaibang
RevStr: bangchennai
isDup: 1 [if PrevActualStr = RevStr then 1 else 0]

isDup = 1 [Rec willn't be processed to o/p as our constraint isDup=0]

O/P
Src Dest Distance
bang chennai 600

Rec-3

PrevActualStr: chennaibang
ActualStr: banghyd
RevStr: hydbang
isDup: 0 [if PrevActualStr = RevStr then 1 else 0]

isDup = 0

O/P
Src Dest Distance
bang chennai 600
bang hyd 1000
---------------------
====================