How to handle division by zero error in tmap.

Seven Stars

How to handle division by zero error in tmap.

Hi Team,

 

How to handle division by zero error in tmap.

 

src_cols

 

col1  integer

col2  integer

 

target_cols

col integer

 

after applying col1/col2 in tmap i am getting below error.

 

Exception in component tMap_1
java.lang.ArithmeticException: / by zero

 

Note: col1 and col2 we have 0(Zero) values.

 

Thanks

shree


Accepted Solutions
Community Manager

Re: How to handle division by zero error in tmap.

Great, would you accept the solution please? 


All Replies
Community Manager

Re: How to handle division by zero error in tmap.

Assuming your expression is .....

row1.col1/row1.col2

...and assuming that if it is divided by 0 you want to return 0 (you can change this to whatever suits you), you can do this....

row1.col1==null || row1.col2==null || row1.col2.equals(0) ? 0 : row1.col1/row1.col2

I am also checking for nulls here, just in case.

Seven Stars

Re: How to handle division by zero error in tmap.

Hi @rhall_2_0,

 

I am tried below code,

 

row1.col1==null || row1.col2==null || row1.col2==0 ? 0 : row1.col1/row1.col2

because both are integer column type is integer.

 

It's worked for me.

 

thanks

Shree 

Community Manager

Re: How to handle division by zero error in tmap.

Great, would you accept the solution please? 

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

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

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download