TMap convert variable if not null

One Star

TMap convert variable if not null

TMap & Variable conversion.
- When I map a nullable variable to a nullable variable, everything works
Scenario:
TMap input:
- var = rating; type = short
TMap output:
- var = y; type = double
Normally I use the middle part to convert Variables, what works fine. Except for this statement where I want to do this:
Relational.ISNULL(row2.rating) ? null : (new Short(row2.rating)).doubleValue()
Since I am in the "conversion step" in the middle of TMAP, TMAP expects me to give back a "not null" value. For example:
Relational.ISNULL(row2.rating) ? -1 : (new Short(row2.rating)).doubleValue()
works fine, but also
Relational.ISNULL(row2.rating) ? row2.rating : (new Short(row2.rating)).doubleValue()
doesnt work. So my question is now:
How do I convert the variable JUST when its not null and, if it's null, how can I manage to return from the middle part a null ( since I don't want to write some arbitrary value there )
Thx
Community Manager

Re: TMap convert variable if not null

Hi
Check the nullable box of the column on the schema if you want to compare the object is null or not. (see my screenshot) and the expression can be:
row2.rating ==null?null:new Double(row2.rating)

Let me know if it does't work, and show us the error message.
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: TMap convert variable if not null

Hi,
I tried your suggesstion
- As said: both variables are nullable
- Error:
Exception in component tMap_2
java.lang.NullPointerException
at sync.de_orders_0_1.DE_Orders.tPostgresqlInput_2Process(DE_Orders.java:1360)
at sync.de_orders_0_1.DE_Orders.runJobInTOS(DE_Orders.java:1965)
at sync.de_orders_0_1.DE_Orders.main(DE_Orders.java:1833)

I believe: When you are in the middle of the Tmap, your not able to return "null" to the "new assigned variable" , can that be the case?
Community Manager

Re: TMap convert variable if not null

Hi
The error might come from another column, i can confirm the expression I gave in my previous post is correct. Can you upload a screenshot of tMap? It will be helpful for us to locate the problem.
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: TMap convert variable if not null

I found my mistake, I forgot to also set my return value of the expression to nullable -.-
Thanks a lot for your help!
One Star

Re: TMap convert variable if not null

Hi,
I tried your suggesstion
- As said: both variables are nullable
- Error:
Exception in component tMap_2
java.lang.NullPointerException
at sync.de_orders_0_1.DE_Orders.tPostgresqlInput_2Process(DE_Orders.java:1360)
at sync.de_orders_0_1.DE_Orders.runJobInTOS(DE_Orders.java:1965)
at sync.de_orders_0_1.DE_Orders.main(DE_Orders.java:1833)

I believe: When you are in the middle of the Tmap, your not able to return "null" to the "new assigned variable" , can that be the case?

It is usefull for me. Thank you for your sharing.