NULL Handling in transformer

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

NULL Handling in transformer

Post by sam334 »

Hi all,
Have a question. I searched the forum for this but could not find a definite answer. First, I am using ISNULL IF function which is not working. Job is below.

SEQ--Tranformer--SEQ(.csv)

So, there are 20 columns in input. each column can be NULL or there is a value Datatype, varchar, 0:10:15. Now, in output I dont want NULL instead I want 0:00:00. Function I used is,
IF Input.column1=@NULL THEN 0:00:00 ELSE input.colume1
Also, tried, IF ISNULL(Input.column1) THEN 0:00:00 ELSE input.column1.
Neither is working.

The input and out both column data type is VARCHAR

Any thought.

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

Post by chulett »

A couple of things. First, nothing is ever equal to NULL which is why the first check fails. Secondly, there are no true NULL values in a sequential file which is why the second test fails. You should be able to test for an empty string like this assuming we're talking about a delimited file:

IF Input.column1="" THEN "0:00:00" ELSE input.column1

You can also specify the null value property for each field which tells the sequential file reader to substitute a NULL into the column when it sees that null value equivalent. For example, in a fixed-width file if you have an "empty" 8 character field that arrives with 8 spaces in it, specifying 8 spaces as the null value will cause those 8 spaces to be replaced with a NULL during the import.

Edited to add: I'm pretty sure that null value property / attribute is available in Server jobs but it might just be a PX thing.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Post by sam334 »

Thanks Craig.
The input file is actually .csv file. thats why probably "" is not working.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

A ".csv file" is a delimited file. So the test I posted isn't working? If so, can you show us some real example records from the file where you have some empty fields you want to be NULL?
-craig

"You can never have too many knives" -- Logan Nine Fingers
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Post by sam334 »

Ok.Thanks,
Basically I did a pivot on sql and due to some restrictions i have to put the record in a .csv file.(Input)

Input-
column1,column2,column3,column4,column5.
sam334,NULL,NULL,NULL,07:35:00

Output:-(.csv)
column1,column2,column3,column4,column5.
sam334,0:00:00,0:00:00,0:00:00,07:35:00

So, I want those NULL or Space in input csv file to be 0:00:00 if that particular column is NULL or space else it can take the value such as 07:35:00
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Asked for real examples, not really sure that is what we're getting. Are you showing us the fact that the word "NULL" is in the file, those four characters? If not, I'd need to see exactly what the file looks like to provide any more help than I already have.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Post by sam334 »

Craig,
When I view the file, it is showing as NULL not space. I used both IF isnull or column1=" ". so that either one should have taken care of.
I know without seeing the actual file, it is more difficult. Let me try once again.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

ssnegi wrote:... Input.column1=@NULL...
As noted earlier, it is not legal to compare something against NULL.

One should use the IsNull() function to determine whether a field is (contains) null.

In server jobs there exists a system variable (@NULL.STR) that contains a string representation of the internal format of null, which can be used in such comparisons, but best practice is always to use IsNull(), not least because @NULL.STR is not available in parallel jobs.
Last edited by ray.wurlod on Thu May 29, 2014 5:15 pm, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ssnegi
Participant
Posts: 138
Joined: Thu Nov 15, 2007 4:17 am
Location: Sydney, Australia

Post by ssnegi »

sam334 wrote:When I view the file, it is showing as NULL not space. I used both IF isnull or column1=" ". so that either one should have taken care of.

Code: Select all

IF Trim(Input.column1) = '' THEN 0:00:00 ELSE input.column1
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

How is null actually represented in your Sequential File stage (for example the Null Field Value property on the Format tab or in an extended column definition)?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sam334
Premium Member
Premium Member
Posts: 145
Joined: Mon Aug 26, 2013 7:42 pm

Post by sam334 »

All,
Solved the issue. I tried different alternatives. The actual issue was,

As there are NULL values in delimited file.This is not space, it actually WORD "NULL". So, If the function is written as,

IF INPUT.COLUMN1="NULL" THEN "0:00:00" ELSE INPUT.COLUMN1, will solve the issue.


Thanks a lot everyone for the input. Appreciate it.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Interesting. Never had anyone send me a file with null values like that. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

I have found the string "NULL" contained within various source systems (i.e. NAME = "John NULL Doe"). Just one of many surprising data quality issues... :evil:
Choose a job you love, and you will never have to work a day in your life. - Confucius
Post Reply