• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » Which component should be used to create a file for each row?

#1 2008-08-26 17:21:59

pberenguer
New member
Registered: 2008-03-25
Posts: 8

Which component should be used to create a file for each row?

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

#2 2008-08-26 19:26:42

Vaiko
Member
Registered: 2008-01-16
Posts: 125

Re: Which component should be used to create a file for each row?

There is an option to split the file after a specified number of rows in the advanced option of the component. Would that help you with your problem?

Offline

#3 2008-08-26 21:22:17

pberenguer
New member
Registered: 2008-03-25
Posts: 8

Re: Which component should be used to create a file for each row?

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

#4 2008-08-26 23:14:18

pozunmv
Member
Registered: 2008-06-06
Posts: 36

Re: Which component should be used to create a file for each row?

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:

Code:

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.


Uploaded Images

Offline

#5 2008-08-29 09:26:46

pberenguer
New member
Registered: 2008-03-25
Posts: 8

Re: Which component should be used to create a file for each row?

Thank you pozunmv!

It works fine. Component tJavaRow was effectively the right one to perform such job.

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » Which component should be used to create a file for each row?

Board footer

Powered by FluxBB