compare values in transformer stage

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

chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You've got all the logic you need right here. :?

One issue could be your incoming data is not sorted properly. Another consideration could be the number of nodes this job is running on, if it is running on more than one node you'd need make sure you hash partition properly on the value(s) you are using to check for duplicates.

So... what exactly about this doesn't seem to be working for you?
-craig

"You can never have too many knives" -- Logan Nine Fingers
vbarca
Premium Member
Premium Member
Posts: 35
Joined: Tue Sep 09, 2008 6:23 am
Location: Chapel Hill, NC

Post by vbarca »

You need two stage variables

IsDup - set initial value to 0 and set the derivation as:
IF DSLink2.deptno = LastValue THEN 1 ELSE 0

LastValue - set initial value to 0 (or any value that will not match anything coming in from the source) and set the derivation as: DSLink2.deptno

Then in your output link you need a constraint: IsDup = 0

That should do it.
Computer analyst to programmer: "You start coding. I'll go find out what they want."
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So... in other words, exactly what's already ready been posted as being used. :wink:

Me, personally, I would rely on the expression automatically assigning the proper values, there's no need to do it "manually". Then treat the result as the Boolean it is.

IsDup: DSLink2.deptno = LastValue

Constraint: Not(IsDup)
-craig

"You can never have too many knives" -- Logan Nine Fingers
ravi7487
Premium Member
Premium Member
Posts: 25
Joined: Sat Feb 05, 2011 10:03 pm

Post by ravi7487 »

Thanks for the reply.

I got the output correct with the below formula.

Intial value = 0 for IsDup
Initial value =0 for currentvalue ( which is different from firstvalue in source)

If DSLink2.deptno = currentvalue then 1 else 0 = IsDup
DSLink2.deptno= currentvalue.

but, i do not want to initialize currentvalue as manually. any alternative mthod? pelase let me know
Vidyut
Participant
Posts: 24
Joined: Wed Oct 13, 2010 12:45 am

Post by Vidyut »

The logic seems fine....jst make sure ur data is sorted
vikasjawa
Participant
Posts: 13
Joined: Tue Aug 29, 2006 3:20 am
Location: Gurgaon

Post by vikasjawa »

Ravi,
The logic provided above is fine. It seems the issue is with the way you are partitioning the data. Try doing a hash partition on deptno.
Vikas Jawa
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

ravi7487 wrote:I got the output correct ... but, i do not want to initialize currentvalue as manually. any alternative mthod? pelase let me know
Is there any particular reason WHY you don't want to initialize currentvalue "manually"? It's both perfectly acceptable and is the correct method per standard programming practices in almost any programming language. There is no need or reason to use any alternative methods to accomplish this job.
- james wiles


All generalizations are false, including this one - Mark Twain.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

As noted, you are not "manually" initializing them, you are properly initializing them using the mechanism provided for exactly that purpose. Make sure you understand, however, that it doesn't need to be a hard-coded value there, you can use an expression or function or job parameter there for example.

ps. There's no need to initialize IsDup since it is set before ever being tested. Doesn't hurt, of course, but serves no purpose.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ravi7487
Premium Member
Premium Member
Posts: 25
Joined: Sat Feb 05, 2011 10:03 pm

Post by ravi7487 »

Thank you all for replying,
so, when comparing the values in transoformer,
for the first incoming row to transformer, the initial value for the "previousvalue" should be assigned something that will not match with the first incoming row.

Am i correct? Please let me know. Thanks.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

ravi7487 wrote:Thank you for clarifying, But what initial value should I put in for the previous value?
chulett wrote:Whatever non-null value will not match with anything that might come in on the first record.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ravi7487
Premium Member
Premium Member
Posts: 25
Joined: Sat Feb 05, 2011 10:03 pm

Post by ravi7487 »

Thanks Chulett,

how will i know what the first record is, so i can have a different value for previousvalue? is there any technique? please let me know
vbarca
Premium Member
Premium Member
Posts: 35
Joined: Tue Sep 09, 2008 6:23 am
Location: Chapel Hill, NC

Post by vbarca »

You have to know your data. Whatever valid valid values your company uses for deptno you don't want to use for your initial value. Use something else.
Computer analyst to programmer: "You start coding. I'll go find out what they want."
ravi7487
Premium Member
Premium Member
Posts: 25
Joined: Sat Feb 05, 2011 10:03 pm

Post by ravi7487 »

Thank you very much, Thanks a ton

DSXchange members helped me a lot.

Thanks again.
Post Reply