String to BigDecimal conversion issue

Six Stars

String to BigDecimal conversion issue

I am having a common and simple issue with String to BigDecimal conversion. 

 

Input: string

Output: BigDecimal

column name: Id

Inside t-map I am putting the below code in One2One mapping.

 

(Id.isEmpty() || Id.equals("")) ? null : new BigDecimal(Id)

 

I don't see any error in Code view but after running I am seeing the error. I have also tried

(Id.isEmpty() || Id.equals("")) ? null : java.math.BigDecimal(Id)

 

 

Execution Error

[statistics] connected
[FATAL]: talend_default.Ex_Job- tMap_2 null
Exception in component tMap_2
java.lang.NumberFormatException
at java.math.BigDecimal.<init>(Unknown Source)
at java.math.BigDecimal.<init>(Unknown Source)
at java.math.BigDecimal.<init>(Unknown Source)
at Ex_Job.tMSSqlInput_1Process(Ex_Job.java:2923)
at Ex_Job.tMSSqlConnection_1Process(Ex_Job.java:1011)
at Ex_Job.tMSSqlConnection_3Process(Ex_Job.java:781)
at Ex_Job.runJobInTOS(Ex_Job.java:4806)
at Ex_Job.main(Ex_Job.java:4585)

 

 

 

 


Accepted Solutions
Nine Stars

Re: String to BigDecimal conversion issue

May be you are getting non numeric values in ID from source like space or alpha numeric.

 

Regards,

Veeru Boppudi

View solution in original post

Forteen Stars

Re: String to BigDecimal conversion issue

@Tasfiahm,can you try to run with Debug mode and see the data,which is failing in tMap? 

use the below expression should work as default if there is no data issue

 

Id== null || "".equals(Id)?null : new BigDecimal(Id)

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.

View solution in original post

Tags (1)
Highlighted
Forteen Stars

Re: String to BigDecimal conversion issue

@Tasfiahm. please accept the solution,which one is right.

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.

View solution in original post


All Replies
Nine Stars

Re: String to BigDecimal conversion issue

May be you are getting non numeric values in ID from source like space or alpha numeric.

 

Regards,

Veeru Boppudi

View solution in original post

Forteen Stars

Re: String to BigDecimal conversion issue

@Tasfiahm,can you try to run with Debug mode and see the data,which is failing in tMap? 

use the below expression should work as default if there is no data issue

 

Id== null || "".equals(Id)?null : new BigDecimal(Id)

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.

View solution in original post

Tags (1)
Six Stars

Re: String to BigDecimal conversion issue

You are exactly right. As the data was coming as a string, it was also coming with space, so I have to trim the row before applying the BigInt conversation.

Highlighted
Forteen Stars

Re: String to BigDecimal conversion issue

@Tasfiahm. please accept the solution,which one is right.

Manohar B
Don't forget to give kudos/accept the solution when a replay is helpful.

View solution in original post

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 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog