Extract fields in tmap

Six Stars

Extract fields in tmap

Hi All,

 

We have a requirement as below.

 

We have a file(a|b|c|d|e|f), which has 6 columns all are pipe("|") delimited, but when in 5th column, if we have a value "R", then 6 column is like "R(0.89:yes:voice:MEANING=YES)" and here I want to separate this field into 4 fields like first_column would be 0.89, second_column would be yes,third_column would be voice and fourth_column would be YES(not MEANING=YES). All I want to do in tmap component, like I have filtered the source data and fetched the 6th column as "0.89:yes:voice:MEANING=YES", but now I am stucking in further splitting these columns in tmap, Is there any function for this or I can assign these values in array and assign the values, but don't know how ?

Eleven Stars

Re: Extract fields in tmap

NO OF FIELDS SEPARATED BY COLON IS ALWAYS FIX ?
Regards
Abhishek KUMAR
Six Stars

Re: Extract fields in tmap

yes, no of fields are same but not length of every field.

Highlighted
Eleven Stars

Re: Extract fields in tmap

1st use tFileInputdelimiter with field delimiter |

 

then in tJava

 

 

output_row.newColumn = input_row.newColumn;
output_row.newColumn1 = input_row.newColumn1;
output_row.newColumn2 = input_row.newColumn2;
output_row.newColumn3 = input_row.newColumn3;
output_row.newColumn4 = input_row.newColumn4;
output_row.newColumn6 = input_row.newColumn5.split(":|\\(|\\)").length > 1?
 input_row.newColumn5.split(":|\\(|\\)")[1] : input_row.newColumn5;
output_row.newColumn7 = input_row.newColumn5.split(":|\\(|\\)").length > 1?
 input_row.newColumn5.split(":|\\(|\\)")[2] : "";
output_row.newColumn8 = input_row.newColumn5.split(":|\\(|\\)").length > 1?
 input_row.newColumn5.split(":|\\(|\\)")[3] : "";
output_row.newColumn9 = input_row.newColumn5.split(":|\\(|\\)").length > 1?
 input_row.newColumn5.split(":|\\(|\\)")[4] : "";

 

 

Regards
Abhishek KUMAR
Six Stars

Re: Extract fields in tmap

Thanks buddy, I am not pro in this kind of coding, can u elaborate this piece of code, it seems u r separating sixth column as this is having colon, pipe and open bracket, checking length>1 and assigning "" if condition doesn't satisfy but sixth column only has colon as delimiter for the four fields and I don't want null or anything, it should have that column only and also 4th column is full value, here again one more delimiter as "=" and I am only looking for the string after =, as in example it is YES only.
May be I am getting it wrong, if u can explain and let me know how to learn this.
I did this after using textractdelimitedfields component twice, first for ":" , got 4 columns from that, then the 4th column again got separated on "=", but want to do all in one component.
Six Stars

Re: Extract fields in tmap

input_row.split(":") worked, don't know why it was not working earlier.
4 columns further separated like below in tmap.
first_row: input_row.split (":")[0];
Second_row: input_row.split (":")[1];
third_row: input_row.split (":")[2];
fourth_row: input_row.split (":")[3].split("=")[1];

But I want to learn how u did this or is there any way to do this in any other component less expensive than tmap?

Calling Talend Open Studio Users

The first 100 community members completing the Open Studio survey win a $10 gift voucher.

Start the survey

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

APIs for Dummies

View this on-demand webinar about APIs....

Watch Now

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

Why Companies Move to the Cloud: 7 Success Stories

Learn how and why companies are moving to the Cloud

Read Now