Handling Nulls

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
kalpanam
Participant
Posts: 39
Joined: Sat Apr 19, 2008 6:14 am

Handling Nulls

Post by kalpanam »

HI all,

I have issue in handling NULLS..here is the problem description:

I'm having input data as:

SHOP_ID,SHOP_DESC,DEPT_ID,DEPT_DESC
123,asdf,456,lkjh
234,lkjhg,NULL,NULL
NULL,NULL,NULL,NULL
NULL,NULL,987,mnbv
NULL,NULL,NULL,NULL

I need to filter out all the null values records and only need to output the records with all columns with values and any single column with value.

please suggest me how to do it or let me know if you did not get the question correct.

Thanks & Regards,
Kalpana.
Kalpana Marupudi
ramsubbiah
Participant
Posts: 40
Joined: Tue Nov 11, 2008 5:49 am

Re: Handling Nulls

Post by ramsubbiah »

Hi kalpana,

use the following the derivation in the transformer constraint

CAPTURING THE VALID RECORDS

ISNOTNULL(SHOP_ID) AND ISNOTNULL(SHOP_DESC) AND ISNOTNULL(DEPT_ID) AND ISNOTNULL(DEPT_DESC)

CAPTURING THE INVALID RECORDS:

ISNULL(SHOP_ID) OR ISNULL(SHOP_DESC) OR ISNULL(DEPT_ID) OR ISNULL(DEPT_DESC)


other way is create stage variable and include the above conditions and use the stage variable in the constraints


Thanks,
Ram.S
Knowledge is Fair,execution is matter!
kalpanam
Participant
Posts: 39
Joined: Sat Apr 19, 2008 6:14 am

Re: Handling Nulls

Post by kalpanam »

First Thanks for your quick response...

I'm not getting what u said...

I need the output as

123,asdf,456,lkjh
234,lkjhg,NULL,NULL
NULL,NULL,987,mnbv to one output and

NULL,NULL,NULL,NULL
NULL,NULL,NULL,NULL to another dataset.How can i perform this by using transformer stage?

Thanks & Regards,
kalpana.
Kalpana Marupudi
ramsubbiah
Participant
Posts: 40
Joined: Tue Nov 11, 2008 5:49 am

Re: Handling Nulls

Post by ramsubbiah »

In transformer create two output links for two datasets, inside transformer in the output link include the above two transformation

link1 ---> ISNOTNULL(SHOP_ID) AND ISNOTNULL(SHOP_DESC) AND ISNOTNULL(DEPT_ID) AND ISNOTNULL(DEPT_DESC) for getting the below output
NULL,NULL,NULL,NULL
NULL,NULL,NULL,NULL

link2 --> ISNULL(SHOP_ID) OR ISNULL(SHOP_DESC) OR ISNULL(DEPT_ID) OR ISNULL(DEPT_DESC) for getting the below output 123,asdf,456,lkjh
234,lkjhg,NULL,NULL
NULL,NULL,987,mnbv

i hope you know how to add a constraint in the transformer output link


Thanks,
Ram.S
Knowledge is Fair,execution is matter!
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Your specification is hard to understand. Presumably you must always output four fields. So what do you want to use to replace NULL where it occurs? Also is your source a text file or something else?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:!: You two - ramsubbiah & kalpanam - need to stop quoting everything when you reply. There is a perfectly lovely Reply to topic button down there, please use that unless there is a burning need to quote something.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ThilSe
Participant
Posts: 80
Joined: Thu Jun 09, 2005 7:45 am

Post by ThilSe »

If I understand your question correctly, set a variable with the count of number of nulls and output records that has count value of 1 or 4.

Eg A = IsNotNull(Col1)+...+IsNotNull(Coln)

Output record if A=1 or 4 (since you need to output if any one column or all four column has values)

Regards,
Senthil
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

One item that would help you (and anyone else attempting to develop code/jobs/etc) is to first work out the logic of what you're trying to accomplish.

Using your original problem as the base, the logic essentially comes down to this:

Code: Select all

If any input column is Non-NULL, then
     keep the record
else ## all columns are NULL
     reject the record
From this basic logic (the above is called pseudo-logic), you can then proceed to how to accomplish that in DataStage or any other tool you happen to be using.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
Ravi.K
Participant
Posts: 209
Joined: Sat Nov 20, 2010 11:33 pm
Location: Bangalore

Post by Ravi.K »

Write the below condition at Constraint for good records otherwise reject the records to a seperate stream.

(IsNotNull(SHOP_ID) Or IsNotNull(SHOP_DESC) Or IsNotNull(DEPT_ID) Or IsNotNull(DEPT_DESC))
Cheers
Ravi K
Post Reply