Need help with tMap Expression

One Star

Need help with tMap Expression

I am new to Talend and have a requirement as follows that evaluate the Booloean value of each of the following columns and then writes a value into one output column in the Output table:

Condition 1: If TYPETEXT is true, then Row1.Output = "Text".
Condition 2: If TYPESUPPS is true, then Row1.Output "Supplement".
Condition 3: If TYPEMEDIA is true, then Row1.Output "Media"

When more than one or all the conditions are TRUE, the desired result is to have a result like this below in the output column by appending the values.

"Text","Supplement"
"Text","Supplement","Media"

And so on.

I therefore wrote the following expression below:

row3.TYPETEXT == null || row3.TYPETEXT.compareTo(BigDecimal.ZERO) == 0 ? null : row3.TYPETEXT.compareTo(BigDecimal.ONE) == 0 ? "Text" :
row3.TYPESUPPS == null || row3.TYPESUPPS.compareTo(BigDecimal.ZERO) == 0 ? null : row3.TYPESUPPS.compareTo(BigDecimal.ONE) == 0 ? "Supplement" :
row3.TYPEMEDIA == null || row3.TYPEMEDIA.compareTo(BigDecimal.ZERO) == 0 ? null : row3.TYPEMEDIA.compareTo(BigDecimal.ONE) == 0 ? "Media" :
null

However this is not giving the desired result.
Please do you have any suggestion on how to achieve this?
Thanks in advance for your help.

Regards,

Re: Need help with tMap Expression

if your input columns are 1/0 boolean values, set your schema types to Boolean.

then the expression would be something like:

for output column TYPETEXT: row3.TYPETEXT || "Text"
for output column TYPEUPPS: row3.TYPEUPPS || "Supplement"
for output column TYPEMEDIA: row3.TYPEMEDIA || "Media"
Highlighted
One Star

Re: Need help with tMap Expression

Thanks for your input. The input columns are 1/0 boolean values but there are also several null values, how do I handle those?

Regards,


JohnGarrettMartin wrote:
if your input columns are 1/0 boolean values, set your schema types to Boolean.

then the expression would be something like:

for output column TYPETEXT: row3.TYPETEXT || "Text"
for output column TYPEUPPS: row3.TYPEUPPS || "Supplement"
for output column TYPEMEDIA: row3.TYPEMEDIA || "Media"

Re: Need help with tMap Expression

row3.TYPETEXT == null ? null : row3.TYPETEXT || "Text"
One Star

Re: Need help with tMap Expression

JohnGarrettMartin wrote:
row3.TYPETEXT == null ? null : row3.TYPETEXT || "Text"

Thanks John. Unfortunately I still get error messages and I was wondering if it is due to the fact that the input columns are Boolean. Based on what you wrote, this is the expression I now built. Bear in mind that I want to append if more than one condition is TRUE.

row3.TYPETEXT == null? null: row3.TYPETEXT || "Text"
row3.TYPESUPPS == null? null: row3.TYPESUPPS || "Supplement"
row3.TYPEMEDIA == null? null: row3.TYPEMEDIA || "Media"

I get "TYPESUPPS cannot be resolved or is not a field" and also "TYPEMEDIA cannot be resolved or is not a field"

Thanks.
One Star

Re: Need help with tMap Expression

Here is a second scenario I am also faced with. Again I have to evaluate the values of five input columns (String and date fields) however in this case, only one column value can be TRUE for any given row, hence if that value is not null, write a string value to the one output column. This is what I wrote and it is also not working.

row2.DATEIDEASUBMITTED != null ? ?Idea?
||row2.DATENOTESSUBMITTED!= null ? ?Notes?
||row2.DATEPROPOSALSUBMITTED != null ? ?Proposal/TOC?
||row2.DATECHAPTERSSUBMITTED!= null ? ?Chapters?
||row2.TARGETMARKETAPPRAISALBYUSER != null ? ?Manuscript?

Re: Need help with tMap Expression

the "cannot be resolved" error is because you are referencing a variable that does not exist (or is out of scope) if you are doing this in a tMap, make sure that you do in fact have a row3.TYPEUPPS in your input table.

It looks like you're struggling with basic java and ternary syntax. Please take a look at these pages to help you debug your statements:
http://download.oracle.com/javase/tutorial/java/nutsandbolts/op2.html
http://www.devdaily.com/java/edu/pj/pj010018
One Star

Re: Need help with tMap Expression

Thanks John, I will review the references.

JohnGarrettMartin wrote:
the "cannot be resolved" error is because you are referencing a variable that does not exist (or is out of scope) if you are doing this in a tMap, make sure that you do in fact have a row3.TYPEUPPS in your input table.

It looks like you're struggling with basic java and ternary syntax. Please take a look at these pages to help you debug your statements:
http://download.oracle.com/javase/tutorial/java/nutsandbolts/op2.html
http://www.devdaily.com/java/edu/pj/pj010018

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

Have you checked out Talend’s 2019 Summer release yet?

Find out about Talend's 2019 Summer release

Blog

Talend Summer 2019 – What’s New?

Talend continues to revolutionize how businesses leverage speed and manage scale

Watch Now

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog