passing null value to integer column

One Star

passing null value to integer column

Hello All,
I need help on how to pass a null value to an integer column.
i have an IF-THEN-ELSE statement to pass value to the integer column like following, but it keeps prompt me error
row4.status=="LIQ"?0Smiley Sadrow4.status=="CUR"?1Smiley Sadrow4.status=="MAT"?2:null))
the output column i've set it nullable.
Please help!
One Star

Re: passing null value to integer column

Hi
First, the data type of status column is String.
You'd better use equals() method.
For example, row4.status.equals("LIQ").
Besides, the expression you use will cause NullPointerException.

Regards,
Pedro
Two Stars

Re: passing null value to integer column

Hi Pedro,
Thanks for prompt reply!
Im new to Talend, can you please help to interpret my syntax with tJavaRow which will be applicable in the Expression Builder?
Much Appreciated!
Thanks
One Star

Re: passing null value to integer column

Hi
You might code as follow on tJavaRow.
if(input_row.status.equals("MAT"))
output_row.newColumn = 2;
else if(input_row.status.equals("CUR"))
output_row.newColumn = 1;
else if(input_row.status.equals("LIQ"))
output_row.newColumn = 0;
else
output_row.newColumn = null;

Regards,
Pedro
Two Stars

Re: passing null value to integer column

Hi Pedro,
I've add in the component tJavaRow to my flow but the subsequent column from my row1 is not bringing to my last output.
how do i get the value from my first table?
One Star

Re: passing null value to integer column

Hi
That's because you forget to add some code.
output_row.ColmunNam = input_row.ColumnName;
Regards,
Pedro
One Star

Re: passing null value to integer column

Oh! Now i got it!
Thank You so Much!
One Star

Re: passing null value to integer column

Hi,
Just to add to this:
When using the equals method I'd prefer to change the code a little to be like this:
if("MAT".equals(input_row.status))
output_row.newColumn = 2;
else if("CUR".equals(input_row.status))
output_row.newColumn = 1;
else if("LIQ".equals(input_row.status))
output_row.newColumn = 0;
else
output_row.newColumn = null;

This way you can never get a NPE because input_row is empty or input_row.status is null and thus is not a String object (which obviously doesn't have an equals method)
Hope this helps!
Best regards,
Arno
One Star

Re: passing null value to integer column

Hi,
This seems like a code lookup that can be done with a spreadsheet and a tMap. The benefit of using the spreadsheet (or delimited file) is that it's easier to view and manage the data. For example, if you export the job, you won't be able to see the MAT/2, CUR/1, LIQ/0 mappings.
If the logic or comparisons are more sophisticated and you have a lot of codes to map, take a look at this post.
http://bekwam.blogspot.com/2011/03/regex-lookup-table-with-talend-open.html