String Handling in Tmap??????

Nine Stars

String Handling in Tmap??????

Hi,

i was trying out a scenario of splitting of name into first,middle and last name accordingly... 

as per my testcase... it worked perfectly with "hello world abc!".

but when i try with any other testcast it fails... 

for example :

"Sudhansu Sekhar Dash" or "Amiya Prasad Mishra"

the result i get is 

"har Dash" or "ishra"

the method used in tmap is ->

StringHandling.RIGHT(row1.ename,StringHandling.INDEX(row1.ename," "))... Pls can anyone help on this....

 

job_view.PNGJob_Viewtmap_view.PNGTmap_viewfirst_name_view.PNGCapturing first_name from emp nameabc_testcase_lastname.PNGCapturing last name using "hello world abc!"last_name_view.PNGCapturing last name from emp nameresult-all_names.PNGend result of all names...but issue with capturing last name.


Accepted Solutions
Employee

Re: String Handling in Tmap??????

Hi,

 

    I have given a solution for a similar query in another post. Could you please check it and try in your use case with necessary changes?

 

https://community.talend.com/t5/Design-and-Development/Split-columns-into-multiple-columns/m-p/14082...

 

If the answer has helped you, could you please mark the topic as resolved? Kudos are also welcome :-)

 

Warm Regards,

 

Nikhil Thampi

Fifteen Stars TRF
Fifteen Stars

Re: String Handling in Tmap??????

This is what your tMap should look like:

capture.png

Based on this data sample:

Sudhansu Sekhar Dash
Amiya Prasad Mishra
Sudhansu Sekhar
Amiya

This is the result:

[statistics] connecting to socket on port 3740
[statistics] connected
.--------------------+---------+----------+--------.
|                    tLogRow_6                     |
|=-------------------+---------+----------+-------=|
|fullName            |firstname|middlename|lastname|
|=-------------------+---------+----------+-------=|
|Sudhansu Sekhar Dash|Sudhansu |Sekhar    |Dash    |
|Amiya Prasad Mishra |Amiya    |Prasad    |Mishra  |
|Sudhansu Sekhar     |Sudhansu |Sekhar    |null    |
|Amiya               |Amiya    |null      |null    |
'--------------------+---------+----------+--------'
[statistics] disconnected

TRF

All Replies
Employee

Re: String Handling in Tmap??????

Hi,

 

    I have given a solution for a similar query in another post. Could you please check it and try in your use case with necessary changes?

 

https://community.talend.com/t5/Design-and-Development/Split-columns-into-multiple-columns/m-p/14082...

 

If the answer has helped you, could you please mark the topic as resolved? Kudos are also welcome :-)

 

Warm Regards,

 

Nikhil Thampi

Highlighted
Nine Stars

Re: String Handling in Tmap??????

hi @nikhilthampi,

greetings of the day,

i have tried the one you have suggested... and it is also giving me the same  output... 

so can you gimme any other method... for which i might be able to achieve.. 

thanks in advance

 

Fifteen Stars TRF
Fifteen Stars

Re: String Handling in Tmap??????

You should try using String.split() method instead

TRF
Nine Stars

Re: String Handling in Tmap??????

hi @TRF,

greetings of the day,

i have tried giving split method,... but i see there are some issues... 

i shall share a screenshot of it.. 

for example my testcase is 

"hello world abc!" -> how would the split method work.... i have considered the case where the method takes single and 2 different arguments.. in single argument method.. i have passed the delimiter by which the name must be split. Note: Should i consider String[](String array), if yes how??

on passing the 2 argument method.... String delimiter and integer.. but this as welll.. failed... 

can you pls help.. or suggest something.. 

thanks in advance

split.PNG

Fifteen Stars TRF
Fifteen Stars

Re: String Handling in Tmap??????

This is what your tMap should look like:

capture.png

Based on this data sample:

Sudhansu Sekhar Dash
Amiya Prasad Mishra
Sudhansu Sekhar
Amiya

This is the result:

[statistics] connecting to socket on port 3740
[statistics] connected
.--------------------+---------+----------+--------.
|                    tLogRow_6                     |
|=-------------------+---------+----------+-------=|
|fullName            |firstname|middlename|lastname|
|=-------------------+---------+----------+-------=|
|Sudhansu Sekhar Dash|Sudhansu |Sekhar    |Dash    |
|Amiya Prasad Mishra |Amiya    |Prasad    |Mishra  |
|Sudhansu Sekhar     |Sudhansu |Sekhar    |null    |
|Amiya               |Amiya    |null      |null    |
'--------------------+---------+----------+--------'
[statistics] disconnected

TRF
Nine Stars

Re: String Handling in Tmap??????

hi @TRF,

thanks for your in-detail solution... 

but i have one final query -> as we are using split method.... is it always necessary for me to define an  object and then the respective indexes of 0,1 and so on must be given across the columns

thanks again....

Fifteen Stars TRF
Fifteen Stars

Re: String Handling in Tmap??????

The Object is here to avoid to have as many String.split() as substrings you have to extract.

I used an Object because it's not possible to declare a variable as a String array.

And finally, yes, you must use indices to get each part of the fullname.

Also, if you have a fullname composed of 2 parts and you want to consider this case as firstName and lastName but not middleName, you must have a double space in the middle (for example, "Sudhansu  Dash").

In this case the middleName will contains an empty string, not a null value but it is not difficult to deal with this situation.


TRF
Four Stars

How to create a generic job in talend

 
Hi,
Could you please confirm if we can create a generic job in talend which performs different operations on different sets of data.
Basically, we want to process multiple source files (having different schema) with different transformations but the overall processing flow in the job is same for all source files. (Eg a simple Job Flow : FileInputDelimited -> TMap -> tFileOutputDelimited).
If we can create such a generic job, then please help on below points : 
1) How to save and pass different schema definition  for different source files via parameter/file
2) How to pass key field via parameter/file
3) How to save and pass different transformations  via parameter/file

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 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog