Max of Two Columns

Six Stars

Max of Two Columns

Hello,

 

I am looking to get max of two column values as below. I have tried tjavarow and used the below syntax but it is throwing a null pointer exception. Any help will be appreciated.

 

output_row.MAX = Math.max(input_row.Col1,input_row.Col2);

<Col1><Col2>
19.25 
8.85 
12.43 
17.36 
17.36 
8.85 
11.9710.35
11 

Accepted Solutions
Eleven Stars

Re: Max of Two Columns

Sorry it should be like this ( 3rd condition should be 1st)

input_row.Col2 == null && input_row.Col1 ==  null ? 0 :

input_row.Col1 ==  null ? input_row.Col2 :

input_row.Col2 == null ? input_row.Col1 :

input_row.Col1 >= input_row.Col2 ? input_row.Col1 : input_row.Col2

Regards
Abhishek KUMAR

View solution in original post


All Replies
Eleven Stars

Re: Max of Two Columns

 

input_row.Col1 >= input_row.Col2 ? input_row.Col1 : input_row.Col2

Regards
Abhishek KUMAR
Six Stars

Re: Max of Two Columns

Hi Abhilash Kumar,

 

I have tried this and I am still getting NullPointerException. any other work around ?

Eleven Stars

Re: Max of Two Columns

you could simply add null checks

 

input_row.Col1 ==  null ? input_row.Col2 :

input_row.Col2 == null ? input_row.Col1 :

input_row.Col2 == null && input_row.Col1 ==  null ? 0 :

input_row.Col1 >= input_row.Col2 ? input_row.Col1 : input_row.Col2

Regards
Abhishek KUMAR
Eleven Stars

Re: Max of Two Columns

Sorry it should be like this ( 3rd condition should be 1st)

input_row.Col2 == null && input_row.Col1 ==  null ? 0 :

input_row.Col1 ==  null ? input_row.Col2 :

input_row.Col2 == null ? input_row.Col1 :

input_row.Col1 >= input_row.Col2 ? input_row.Col1 : input_row.Col2

Regards
Abhishek KUMAR

View solution in original post

Six Stars

Re: Max of Two Columns

Thank you so much Abhishek. It has worked. 

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