[resolved] Can I assign a default value to NULL integers without an expression?

Highlighted
One Star

[resolved] Can I assign a default value to NULL integers without an expression?

Hi, here is my scenario (my target table is MySQL):
One of my lookup tables has rows with no value, or NULLs
I'd like to get the value of -1 into these rows in the target table
I can write an expression for this in the tMap, but shouldn't MySQL be able to add the -1s in itself?
Here is what I have tried:
1. The source lookup table schema as not NULLable, as it itself does not have any NULLs in it. This produced 0s in my target table
2. The source lookup table as NULLable; this was necessary to actually get NULLs i.e. non-0 values into the target table, unexpectedly
3. Setting the source to NULLable and the target to not NULLable, hoping to let MySQL do it's thing and insert the default value of -1 when it hits a NULLable field. This produced a java.lang.NullPointerException
Am I thus forced to write an expression such as "row1.column == null ? -1 : row1.column" into my tMap?
Just trying to balance the functions of the different platforms rather than perform redundant actions
Thanks Smiley Happy

Accepted Solutions
Seventeen Stars

Re: [resolved] Can I assign a default value to NULL integers without an expression?

Your 3. solution cannot work, because Java do the an implicit call to e.g. the method intValue() to an Integer to fill the int (none null) output. If the input is null, it fails.
The default values in the database will only be used if you do not fill the column and set null as value is always a attempt to fill the column and prevents the database from setting the default value.
The only way is indeed the expression you already know in the tMap.

All Replies
Seventeen Stars

Re: [resolved] Can I assign a default value to NULL integers without an expression?

Your 3. solution cannot work, because Java do the an implicit call to e.g. the method intValue() to an Integer to fill the int (none null) output. If the input is null, it fails.
The default values in the database will only be used if you do not fill the column and set null as value is always a attempt to fill the column and prevents the database from setting the default value.
The only way is indeed the expression you already know in the tMap.
One Star

Re: [resolved] Can I assign a default value to NULL integers without an expression?

Ok thanks for the explanation Smiley Happy

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch