Compare String using tMap - talend

I am using Talend to prepare dataware.
I want to compare the string with the contents of a column using the tMap component and create a variable to store in the DB. The problem is that the == operator does not give the right result (Example: row2.recipient == "text"?"text":"" I always get "") and if I use .equals I get errors when executing.

You will get error if row2.recipient is null, and "==" should not be used when comparing strings.
Correct syntax would be :
"text".equals(row2.recipient)?"text":""
Then you will prevent NullPointerExceptions.

Related

Filtering column strings that contain substring

I am working on an if else in the Tmap, and one of the conditions is if a column contains a substring.
I am unsure exactly how to go about this being fairly new to talend.
This is the current syntax that I am using.
row16.Location.contains("clos")?"Pending":""
I have not been able to find any good examples of the correct way to go about this, other than the one above.
Talend uses Java as an underlying language, so you need to use the ternary operator of Java:
row16.Location.contains("clos") ? "Pending" : ""
But make sure you first check row16.Location for null, otherwise you'll get a NullPointerException if Location is null :
row16.Location != null && row16.Location.contains("clos") ? "Pending" : ""

XML Expression Binding - Proceed Code in conditional operator

I am currently working on a Fiori app. At the moment I try to set a title depending on the value of a property I get from my OData service. Therefore I want to use expression binding with the conditional operator.
So when ${PROPERTIY} has the value "EXAMPLE", it should print the value of OUTPUT_PROPERTY_1. Otherwise, it should print the value of OUTPUT_PROPERTY_2.
XML:
<ObjectListItem title="{= ${PROPERTIY} === 'EXAMPLE' ? '${OUTPUT_PROPERTY_1}' : '${OUTPUT_PROPERTY_2}'}">
Unfortunately, it just prints ${OUTPUT_PROPERTY_1} or ${OUTPUT_PROPERTY_2}, and does not proceed the code to get the actual value of the properties.
Is there any chance to solve this problem or even a good workaround in order to print the actual value of the related property?
Remove the apostrophes around the expression binding syntax:
title="{= ${PROPERTIY} === 'EXAMPLE' ? ${OUTPUT_PROPERTY_1} : ${OUTPUT_PROPERTY_2}}"
Otherwise, '${OUTPUT_PROPERTY_x}' will be treated as a string literal.

tPostgresqlInput - How to convert input to Null-if-empty?

I want to trim each column value to null if they are empty.
Is there a way to attach an inbuilt talend function to those column values? I think informatica has something like that.
PS: I need to do that in talend, not in sql level.
The rows goes to another table in another db:
I like to solve this with Java, I'm sure there are other more graphical ways to do this.
If we put a tJavaRow inbetween, then press generate code it would result in:
output_row.plateid = input_row.plateid;
If we change this to:
output_row.plateid = (input_row.plateid == null || input_row.plateid.length() == 0) ? null : input_row.plateid ;
Then we get the desired results. null stays null, empty string also becomes null.
In most t***Input components you have trim all columns option. Look for it in advanced settings.

Parse setting explicit type using REST

I know you can set a Date field explicitly like so:
"date_brewed":{
"__type":"Date",
"iso":"2009-10-15T00:00:00.000Z"
}
But is there anyway to explicitly set the column type of 'Number' using REST? For instance, I'd like to set the column 'batch_size' to a Number instead of a string but when POST'ing via rest it keeps getting created as a string type column.
Meh, this was more of a Perl issue than a Parse issue.
What I had to do to tell Perl to treat the number like an actual number was to add a zero to the value. :/

Display blank value ("") as date in SSRS

I have the column DiscontinuedDate with either a datetime or a blank value. I used the expression
FormatDateTime(Fields!DiscontinuedDate.Value, DateFormat.ShortDate)
To show the date time as just a date but then when the value is blank it shows as an error with the following message "Conversion from string "" to type 'Date' is not valid."
So i've been trying to use an IIF expression like the below:
=IIF(Fields!DiscontinuedDate.Value is "", "", FormatDateTime(Fields!DiscontinuedDate.Value, DateFormat.ShortDate))
I've tried a few variations but they all bring back the same error. Any ideas?
Thanks,
Adam
Your issue is that SSRS IIf expressions do not short circuit, so whenever you have a blank string your code will still be trying the FormatDateTime conversion, so you get this error even with your check.
You can add some logic to stop the empty string being evaluated in the FormatDateTime expression by using another IIf to change it to a NULL value, which won't fail:
=IIF(Fields!DiscontinuedDate.Value = ""
, ""
, FormatDateTime(IIf(Fields!DiscontinuedDate.Value = ""
, Nothing
, Fields!DiscontinuedDate.Value)
, DateFormat.ShortDate))
That solves your immediate issue, but assuming the underlying data is text based, I would also recommend looking at your underlying data and using explicit DateTime type data types instead of strings to prevent these at the lowest possible level.