One Star

How to use input_row.Name to set for each row a new fileName output?

I read rows from a data source1. (schema DS1.Name, DS1.data, ...)
I wish to change fileName output with DS1.Name value. How can I do it?.
DS1 -> FileOutDS1.Name
a tJavaRow component enables to get/set a new context var value. but if this var is used in the fileName settings of the output file, it is first set to null (initial context val) and the new context value is not refreshed before the subjob execution ends (data source1 reading).
12 REPLIES
One Star

Re: How to use input_row.Name to set for each row a new fileName output?

Hi,
to get a new filename for each row you need a new iteration. You could use tFlowToIteration and then initialize the file output component with the filename you get from your flow. To set the filename you should use the following code:
(String)globalMap.get("DS1.Name")

.
DS1 should be the name of the flow, name the name of the attribute.
Bye
Volker
One Star

Re: How to use input_row.Name to set for each row a new fileName output?

Hi,
with the flowToIterate component we can set globalMap var but it is not possible to set the FileName output with this globalMap var.
It seems that the fileName is set before iteration flow starts!
The first fileName value is null, the second file name gets the first value...
the tJava component is only used for iterate purpose or custom code. //globalMap.put("XMLFileName", row3.Name);
tJavaRow: globalMap.put("XMLFileName", row3.Name);
output_row.XMLTexte = ...;
fileOutput: "C:/..."+ (String)globalMap.get("XMLFileName")+".xml"
thanks in advance for your help.
Kind regards,
jn
One Star

Re: How to use input_row.Name to set for each row a new fileName output?

Maybe you shall change your jobb like this:
GP2_PROJET---row1--->tlogRow
\
--iterate-->tfileOutputdelimited with (String)globalMap.get("row1.Name") as filename
One Star

Re: How to use input_row.Name to set for each row a new fileName output?

that doesn't work.
Any other idea to set fileName dynamically while flow iterates?
One Star

Re: How to use input_row.Name to set for each row a new fileName output?

Which version of TOS do you use? I'll try to create a example.
One Star

Re: How to use input_row.Name to set for each row a new fileName output?

Hi,
I'm using TOS 2.4.1, but I can upgrade to TOS 3.0 if needed.
Thanks for your help.
One Star

Re: How to use input_row.Name to set for each row a new fileName output?

try using this
GP2_PROJET---row1--->tlogRow
\
--iterate-->tfileOutputdelimited with row1.Name as filename
One Star

Re: How to use input_row.Name to set for each row a new fileName output?

Hi,
the designer does'nt allow to put an iterate link between my dataSource (Database Table or Excel File) and the tFileOutPutDelimited. I can only use the "main" link: row. It seems OK as the each row of the dataSource will be processed with this link.
The iterate link can be put with the tFlowIterate component as shown on the picture enclosed first, but the outputFileName is set before the iterate link starts. As a consequence, the first fileName value is set the initial value(null); just before iteration starts!
One Star

Re: How to use input_row.Name to set for each row a new fileName output?

Let me show you what I did:
- DataflowKO_FileNameOK_0.1
- DataFlowOk_FileNameKO_0.1
either I managed to get fileName from Datasource but no data in the flow or I get data but not the fileName set from dataSource.

Could you explain me why and tell me more about the way I can get both?
One Star

Re: How to use input_row.Name to set for each row a new fileName output?

Hi,
I created a example based on 3.0.0. But this should work in 2.4.x too. I hope it will make it clearer.
The input file is:
fileA.txt;1,2,3,4,5
fileB.txt;a,b,c,d,e
fileC.txt;q,w,e,r,t,z,u,i,o
fileD.txt;A,1,B,2

One output example (fileD.txt):
A
1
B
2

This examples uses a file as input. But with a database it should be the same.
Bye
Volker
One Star

Re: How to use input_row.Name to set for each row a new fileName output?

Hi,
great! thanks a lot!!
That works exactly as I wished. (with TOS 2.4, the flowToIterate icon changes)
The tFixedFlowInput component was the one I missed!!
The tNormalize doesn't seem to be useful for my needs as I can have several columns from the tFixedFlow. I only have to care about data conversion to String.
Integer.toString(row1.Id)
(String)globalMap.get("row1.Libelle")
I could also add a tJavaRow for intern data manipulation.
output_row.Id=input_row.Id;
output_row.Libelle= "<Hello>" + input_row.Libelle + "</Hello>";
If I could, I would just ask for another exemple when you have time: how can I use technical components tArray and tArryIn to deal with data storage for further purpose. I didn't manage to use tArrayIn to get back initial data stored in tArray.

Kind regards,
jnb
One Star

Re: How to use input_row.Name to set for each row a new fileName output?

Hi jnb,
I'm glad that I could help you. Concerning tArray I've to pass on that. I didn't used them before.
Bye
Volker