Division operation string values using tmap

Seven Stars

Division operation string values using tmap

Hi Team,

 

I have two columns which values contains 0(ZERO) both columns are string.

 

Expression: col1/col2

datatype should be float or decimal and load into redshift table(numeric data type)

 

Note: col1 and col2 either or both contains 0 values col1 and col2.

 

How to achieve above scenario.

 

Thanks

shree

 

Twelve Stars

Re: Division operation string values using tmap

(col2!=0)?col1/col2:0

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Twelve Stars

Re: Division operation string values using tmap

http://www.cafeaulait.org/course/week2/43.html

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Sixteen Stars TRF
Sixteen Stars

Re: Division operation string values using tmap

You need to use equals method to compare string variables, then you can use Float.parseFloat to convert both strings to Float before the division:

 

(row1.col2.equals("0")) ? 0 : Float.parseFloat(row1.col1) / Float.parseFloat(row1.col2)

TRF
Sixteen Stars TRF
Sixteen Stars

Re: Division operation string values using tmap

@bshree88did this help you? If so, thank's to mark you case as Solved (Kudos also accepted)


TRF

2019 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

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