[resolved] Adding expressions to tMap component

One Star

[resolved] Adding expressions to tMap component

Hello, I'm new with Talend an also Java, so I think my problem must be very easy to solve..
I'm using a tMap component to Map two fields from two different files (Price1 and Price2), these fields are BigDecimal (they are Prices, I think this is correct).
I need to generate an output file with all data from the first file and a new field Price3 with the sum of Price1 and Price2, but if I define a expression like Price1+Price2 to define Price3 field, it says me that the operator + cannot be used with BigDecimal data types. So, how can I define a expression to add two fields if they are BigDecimals?

Regards.

Accepted Solutions
Community Manager

Re: [resolved] Adding expressions to tMap component

Hello
You should filter null row on price2 column. eg:
row2.Price2==null?row1.Price1:row1.Price1.add(row2.Price2)
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

All Replies
Community Manager

Re: [resolved] Adding expressions to tMap component

Hello
try
row1.Price1.add(row2.Price2)

Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Adding expressions to tMap component

Hello Shong, thank yo for your response, but I have used it before and the result is this NullPointer exception:
Exception in component tMap_2
java.lang.NullPointerException
at java.math.BigDecimal.matchScale(Unknown Source)
at java.math.BigDecimal.add(Unknown Source)

Regards
Community Manager

Re: [resolved] Adding expressions to tMap component

Hello
You should filter null row on price2 column. eg:
row2.Price2==null?row1.Price1:row1.Price1.add(row2.Price2)
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Adding expressions to tMap component

Hello Shong, now all is fine!!
Thank you for your responses.
Regards