tMap Sting Manipulation errors

One Star

tMap Sting Manipulation errors

Hello, Getting my feet wet in TOS, so thanks for any help or pointers. I have successfully connected to several DB's and I am able to define jobs that will move data between DB's as expected. I am now trying to make more use of tMap functions such as StringHandler. Within the tMap editor I have a field called "row1.objek" I want to strip leading zeros off. In the DB's this field is defined as a VARCHAR(18) and in tMap they are defined as Strings in both the input and output. Also, It is not a fixed length padding so there could be 12 leading 0's or 10. The input source is MS SQL Server and the output target is MySQL. If I remove this expression it works fine and will load 46k+ recs into MySQL quickly.
In this case I have the following expression defined for that field.

StringHandling.LEFT(row1.objek, 1).equals("0") 



I have tried this exp on the input schema in tMap editor as well as the output schema. When defined at the input schema row1, the job will run but it will not trim the 0's. On the output schema going into MySQL it will fail at compile time with the following error. I am using the same JRE for everything.

At least job "MM_IMPORT" has a compile errors, please fix and export again.
Error Line: 1064
Detail Message: Type mismatch: cannot convert from boolean to String
There may be some other errors caused by JVM compatibility. Make sure your JVM setup is similar to the studio.


Apologies for mistaken terminology.
Regards,
Pat

Four Stars

Re: tMap Sting Manipulation errors

I think the error is due to the return type of equals() which is a boolean while you want store a string.
One Star

Re: tMap Sting Manipulation errors

Hi,
This expression tells you if row1.objek starts with 0 or not resulting in true or false (boolean).
If you want to remove leading 0, use replaceAll regex on right side of the tMap, such as
row1.objek.replaceAll("^0+", "")

which means "replace starting 0s by nothing".
It should work.
Regards,
TRF
One Star

Re: tMap Sting Manipulation errors

Thanks for the pointers. I will say I tried this a couple different ways, with and without the .equals as well as couple other string functions and each returns the same JVM error.
StringHandling.LEFT(row1.objek, 1).equals("0") 


But I managed to get it working using the TalendString exp as follows

TalendString.talendTrim(row1.OBJEK,'0',0)

My preference is to use regex pattern matching, but I wanted to get a better handle on the builtin exp/functions in Talend. 
Thanks again,
Pat

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