You are not logged in.
Announcement
Unanswered posts
|
Pages: 1
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,
Offline

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

row3.TYPETEXT == null ? null : row3.TYPETEXT || "Text"
Offline
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.
Offline
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”
Offline

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/tutor … s/op2.html
http://www.devdaily.com/java/edu/pj/pj010018
Offline
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
Offline
Pages: 1