Tmap and string contains

Highlighted
Three Stars

Tmap and string contains

Hi,

I have a column which contains text string (IDs). There is some logic in our text strings which I would like to use for mapping purposes.
The IDs can be like H123A, H123B or H123C. I am looking to map the data to different columns based on the last character of the text string (A,B or C).

 

For Example:

If ID is H123A it should go to Column1.

If ID is H123B it should go to Column2.

IF ID is H123C then it should go to Column3.

 

Can anyone please help me out on this?


Thanks in advance.

Kind Regards,
Arjun 


Accepted Solutions
Nine Stars

Re: Tmap and string contains

try this it will work as per your requirement

row1.Source.toLowerCase().contains("a") ?  row1.Source : ""  at column1 on tMap

row1.Source.toLowerCase().contains("b") ?  row1.Source : ""  at column2 on tMap

row1.Source.toLowerCase().contains("c") ? row1.Source : ""at column3 on tMap

 

By assuming we only get either a or b or c not a and b or b and c both at a time in a string.

at the end of function i written string with no spaces.

View solution in original post


All Replies
Nine Stars

Re: Tmap and string contains

Hello @arjunvigneshwar 

am assuming you have 3 columns in the output side in tMap

row1.Source.toLowerCase().contains("ID") ? "H123A" : row1.Source  at column1 on tMap

row1.Source.toLowerCase().contains("ID") ? "H123B" : row1.Source  at column2 on tMap

row1.Source.toLowerCase().contains("ID") ? "H123C" : row1.Source  at column3 on tMap

 

Please write in all three columns, i just written lower case to avoid some case, some id may not be in Caps

Three Stars

Re: Tmap and string contains

@manishchokkaram 

 

Hi Manish,

 

Will the below commands work when ever the fields contains the string "A" "B" or "C".

If the string contains the alphabet A it should go t Column 1, if B then to Column2 or else to column 3.

 

Thanks in advance.

Kind Regards,

Arjun Rathinam

Twelve Stars

Re: Tmap and string contains

add this on the output filter of a tmap row.IDs.substring(4).equals("A")

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Three Stars

Re: Tmap and string contains

Hi Francois,

 

It is not necessary that the A or B or C should be the 5 character of the string. It can be anywhere. Basically if the string contains the Aplhabet A it should be in column1 or if it contains B anywhere then it should be in Column2 or else it should be in Column3.

 

But when I tried your solution I am getting the attached error.

 

Thanks in advance.

Kind Regards,

Arjun

Nine Stars

Re: Tmap and string contains

@arjunvigneshwar  did you tried the function i mentioned earlier?

Three Stars

Re: Tmap and string contains

@manishchokkaram  Yes, I did. I am getting the attached output.

 

In am currently getting the output which highlighted in yellow. But I am expecting the output to be like the one highlighted in green.

 

PFA,.. 

 

Kind Regards,

Arjun

Nine Stars

Re: Tmap and string contains

try this it will work as per your requirement

row1.Source.toLowerCase().contains("a") ?  row1.Source : ""  at column1 on tMap

row1.Source.toLowerCase().contains("b") ?  row1.Source : ""  at column2 on tMap

row1.Source.toLowerCase().contains("c") ? row1.Source : ""at column3 on tMap

 

By assuming we only get either a or b or c not a and b or b and c both at a time in a string.

at the end of function i written string with no spaces.

View solution in original post

Three Stars

Re: Tmap and string contains

Yes, this works perfect! 

 

Thanks a lot.

Kind Regards,

Arjun

Nine Stars

Re: Tmap and string contains

@arjunvigneshwar okay thanks, thanks for sharing the example screenshot, so i figured it out easily

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

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog