Introduction

Here’s the third instalment in the Talend ‘Tips and Tricks’ series. Click here to read ‘Tips and Tricks (Part 1)‘ and ‘Tips and Tricks (Part 2)‘. In this particular edition, I decided to share a couple of ways you can mimic functionality that is not found in Java/Talend by default, but require some coding. I’ll specifically demonstrate two examples of SAS SQL using standard Java libraries.

SAS Tip Number 1

INDEXC – Searches for all occurrences of the given expression in the string. If found, returns an int value that represents the index position. If nothing found, then 0 is returned. So if your SAS job has an expression INDEXC(row.SOMEROW, ‘abcdefg’) <>0 (or is equal to some other value besides 0) you can use the code below: 

2016-04 Blog - Talend Tips and Tricks Part 3 - Image 2

Also, make sure that you import the lib’s in the tJavaRow component’s Advanced settings, as can be seen below:

2016-04 Blog - Talend Tips and Tricks Part 3 - Image 3

The code will return the index position and you will be able to make the comparison, however if the expression is INDEXC(row.SOMEROW, ‘abcdefg’) = 0, then you can do a matches() function in java and using regex return a Boolean. Obviously you can tweak the code to your needs, but with this simple pattern Match you can mimic the INDEXC functionality.

SAS Tip Number 2

PROPCASE – (or proper case) is a function that uppercases each word in a string. Java does not have a function for that; you can only uppercase the entire String. However there are several methods to achieve this. The one below is just one of many:

2016-04 Blog - Talend Tips and Tricks Part 3 - Image 5

As with the previous example, this code sample can be used in tJavaRow on any number of String columns. You could also use a split based on whitespaces and go from there, but I think that it is a bit more complicated. Also there are Java libraries that can perform a proper case of a string, but you would need to load them with a “tLibraryLoad” component and the obvious downside to that approach is the awkwardness of sharing the code, as you would also need to share the external libs you used. The bonus, however, is that you can easily use the imported libs in components such as tMap. Obviously, you can use the code examples I provided and create Talend routines. 

This is it for this particular ‘Tips and Tricks’ blog post! If you found this helpful then great. If, perhaps, you have suggestions for another tips or tricks blog post or you have a question about Talend functionality, please leave a comment below or contact us.

 

 

Send this to a friend