Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Lara_Zuern
Contributor III
Contributor III

How to split a String into two columns

Hello,

I'm from Germany and a real newbie on Talend.

For my bachelor thesis I am supposed to test the tool Talend Open Studio for Big Data. Part of my data is stored in a MongoDB. I want to split the string of the attribute machineTime into one column with Date and one with Time. For example, a string looks like this: machineTime: "14.05.2018 : 12:35". How can I implement this?

Thanx for your help.

Lara

Labels (2)
1 Solution

Accepted Solutions
Prakhar1
Creator III
Creator III

So you have to write a code like this in tJavaFlex ( main code )

 

index = machineTime.indexOf(":");

machineDate = machineTime.substring(0,index);

machineNewTime  = machineTime .substring(index+1,machineTime.length());

 

Now you can create two columns in tJavaFlex schema like machineDate and machineNewTime or whatever you like

 

and then whatever the output link name is the code will be like this

 

row2.machineDate = machineTime.substring(0,index);

row2.machineNewTime  = machineTime .substring(index+1,machineTime.length());

 

Let me know in case you need more help

View solution in original post

8 Replies
Prakhar1
Creator III
Creator III

So you have to write a code like this in tJavaFlex ( main code )

 

index = machineTime.indexOf(":");

machineDate = machineTime.substring(0,index);

machineNewTime  = machineTime .substring(index+1,machineTime.length());

 

Now you can create two columns in tJavaFlex schema like machineDate and machineNewTime or whatever you like

 

and then whatever the output link name is the code will be like this

 

row2.machineDate = machineTime.substring(0,index);

row2.machineNewTime  = machineTime .substring(index+1,machineTime.length());

 

Let me know in case you need more help

Lara_Zuern
Contributor III
Contributor III
Author

Hello Prakhar,

 

Thank you very much for your help. I have now tried the code and every time I get the message that the series machineTime can not be resolved. Any suggestions on this?

Anonymous
Not applicable

Please upload some screenshots to show us where you write the code and which components the job contains.

 

Lara_Zuern
Contributor III
Contributor III
Author

0695b00000F97iXAAR.png This is where I wrote the code. I've also tried to write it at the end but it doesn't work.

Anonymous
Not applicable

See below screenshots, here are the Java codes on tJavaFlex.

index = row1.machineTime.indexOf(":");

row2.machineDate = row1.machineTime.substring(0,index);

 

row2.machineNewTime = row1.machineTime .substring(index+1,row1.machineTime.length());

0695b00000F9KsGAAV.png0695b00000F9KsQAAV.png0695b00000F9KqLAAV.png 

 

Lara_Zuern
Contributor III
Contributor III
Author

Hello again,

 

I tried it the way you said.

With your setup, it worked. Then I tried it with my data from MongoDB (screenshots follow). First I only read the variable machineTime from MongoDB. Now I always get the following error message after running the job:Here is the complete structure of my job:

Anonymous
Not applicable

What is the error message? You forgot to upload the screenshots.

Lara_Zuern
Contributor III
Contributor III
Author

Thank you, I had not even noticed.

Here we go.0695b00000F9ejOAAR.png0695b00000F9eTTAAZ.png0695b00000F9ejYAAR.png0695b00000F9ejsAAB.png