You are not logged in.
Announcement
Unanswered posts
|
Pages: 1
Hi Experts,
In my job, I have a tBufferOutput with two columns (ID and comments). For each row in this buffer, I would like to create (under a known folder) one file named with the ID value and containing the huge text of Comment column.
Which component can I use to do this job?
Thank you
Philippe
Offline
Thank for your sugest Vaiko but No, It doesn't
Let me explain my resquest more in detail in an example
Input Row:
ID|Comment
001|text with lf and cr
002|text2
etc..
Expected result:
Folder
|--- File 001.txt containing the text "text with lf and cr"
|--- File 002.txt containing the text "text2"
|--- etc..
Offline

You can setup a couple of context variables, one for the row you want as file name and another for the actual values. So you would take the main row from your database output, and feed it into a tJavaRow. In the tJavaRow you would then set the context variables to the values from the database. Use the main link on that and put it into a flowToIterateLink. From the flowToIterate link create a link to a fixedFlowInput object. In that object setup a single column and set the value of that column to be the value of your context variable for the data. Then feed that flow using a main link into your output. Im not sure if this is the best way to do it, but it will work. See the attached screen shots.
To remove a lot of the components you could simply do everything in the tJava component. So rather than passing that through just write out to the file in java. Something like:
java.io.BufferedWriter out; out = new java.io.BufferedWriter(new java.io.FileWriter( "C:/Talend2.4.1/workspace/TEST/Work/" + input_row.val1 + ".txt")); out.write(input_row.val2); out.close();
This is of course if you are using java, if youre using perl then you can do essentially the same, the syntax would just be simpler.
As I said I dont know if either of these solutions would be considered the best way to do what you want to, but they both will accomplish what you are looking for.
Offline
Thank you pozunmv!
It works fine. Component tJavaRow was effectively the right one to perform such job.
Offline
Pages: 1