One Star

spliting files an renaming files

Hi,
I'm new on Talend.
I'm trying to create a file for each row I have in my database and want to rename each file whith a unique variable I have in the row.
My input file is a mysql database, I use a tmap before spliting in multiples files using xmloutput composant.
I try to put a variable in the "+("row1.id")+".xml", I have a null1, null2, null3 ....
Thanks for help
Sorry for my english
20 REPLIES
One Star

Re: spliting files an renaming files

Hello,
I still need help
Thanks
Community Manager

Re: spliting files an renaming files

Hello
tMysqlInput---row1-->tFlowToIterate---iterate-->tAdvancedOutputXML
on tFlowToIterate, generate each row.
set the file as:
"..."+row1.id+".xml"
If you still have any trouble, please give us an example of your request.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: spliting files an renaming files

hello
Thanks for your help.
I can't see how I can change my job with your solution
Here is my flow
One Star

Re: spliting files an renaming files

hello,
I still need help
I'm not the only one with this issue
http://www.talendforge.org/forum/viewtopic.php?id=12543
Thanks

Re: spliting files an renaming files

I see your issue. you cannot connect an iterate link to a tFileOutputXML. To make this work, use a tJavaFlex to read from the iterate link one row at a time.

dbInput --> tMap --> tFlowToIterate --> tJavaFlex --> tFileOutputXML
in your tJavaFlex, propogate the data with this code in the MAIN section:
BEGIN SECTION: 
<empty>
MAIN SECTION:
row2.newColumn = globalMap.get("row1.newColumn").toString();
END SECTION:
<empty>

in my example row2 is the output row of the tJavaFlex and row1 is the input row to my tFlowToIterate. you will need to replace that with what your output/input rows are.
in the tFileOutputXML use this code in the File Name field:
/file_example/file_header_" + globalMap.get("row1.newColumn").toString() + ".xml"
One Star

Re: spliting files an renaming files

hello,
thanks for your help !
I followed your solution, I made some screenshot.
I have an error on the tjavaflex, don't know why

Thanks
The error :
connecting to socket on port 3561
connected
Exception in component tJavaFlex_1
java.lang.NullPointerException
at webedition.test_0_1.test.tMysqlInput_2Process(test.java:8742)
at webedition.test_0_1.test.runJobInTOS(test.java:10732)
at webedition.test_0_1.test.main(test.java:10593)
disconnected
Job test terminé à 14:02 08/10/2010.

Re: spliting files an renaming files

It looks like you are referencing the wrong row varibles in the tJava flex. The input to your tFlowToIterate is row11, the output of the java flex is row10.
change your code from this:
row11.EAN = globalMap.get("row6.gdl_ean").toString();
to this:
row10.EAN = globalMap.get("row11.gdl_ean").toString();
One Star

Re: spliting files an renaming files

thanks but it doesn't work
I haven't go any row10 in my tmap. Is it normal ?
And row11 is before row 10 in the flow, is it a problem ?

Re: spliting files an renaming files

it dosnt matter what the input and output are called, just that they are referenced correctly. I've uploaded your screenshot with input and output highlighted.
<OUTPUT_ROW_VAR>.<OUTPUT_COLUMN_NAME> = globalMap.get("<INPUT_ROW_VAR>.<INPUT_COLUMN_NAME>").toString();
One Star

Re: spliting files an renaming files

Hello,
Thanks very much for your help !
It works now ! I have all my files with the right name but XML fields are now empty except for the EAN.
Do I have to set global var for each field ? Where ?
One Star

Re: spliting files an renaming files

I try to set all vars in the tjavaflex ! It works for row11
row10.SERIEL=globalMap.get("row11.SERIEL").toString(); WORK
row10.ISBN=globalMap.get("row11.ISBN").toString(); WORK
row10.EAN=globalMap.get("row11.EAN").toString(); WORK
row10.AGEDEB=globalMap.get("row9.cum_age").toString(); DOESN'T WORK
Any help please ?

Re: spliting files an renaming files

the tFlowToIterate is what is putting the row values into the global map. row9 is not being processed by the flowToIterate-- so its values will not be put into the global map.
looking at your screenshots, all you would need to do is include the "cum_age" column in your row11 output table in the tMap, then you will be able to pull it out of the global map like all the other row11 values.
One Star

Re: spliting files an renaming files

I put the row9.cum_age in row11.AGEDEB in the TMAP but when I do a row10.AGEDEB =globalMap.get("row11.AGEDEB ").toString(); in the tjava flex it doesn't work
error
Exception in component tJavaFlex_1
java.lang.NullPointerException
at webedition.test_0_1.test.tMysqlInput_2Process(test.java:3428)
at webedition.test_0_1.test.runJobInTOS(test.java:5371)
at webedition.test_0_1.test.main(test.java:5243)

Re: spliting files an renaming files

are you still refering to it with this?
row10.EAN=globalMap.get("row9.cum_age").toString();
if so, change it to:
row10.EAN=globalMap.get("row11.AGEDB").toString();
One Star

Re: spliting files an renaming files

I made an error sorry it's not
row10.EAN=globalMap.get("row9.cum_age").toString();
but
row10.AGEDB=globalMap.get("row9.cum_age").toString();
I tried both, they don't work.
row10.AGEDB=globalMap.get("row11.AGEDB").toString();
row10.AGEDB=globalMap.get("row9.cum_age").toString();
One Star

Re: spliting files an renaming files

Just a little help for this please ! Smiley Happy

Re: spliting files an renaming files

Can you post a few more screenshots of what you're working with? Please include the inside of the tMap and tJavaFlex.
One Star

Re: spliting files an renaming files

Now I manage to get the row11.ean name for filename and i can set globalvar for every row11 that came from the row6 but
it doesn't work for those which came from row8 or row9 so I can fill my xml file with all fields.
The line row10.AGEDEB=globalMap.get("row11.AGEDEB").toString(); in the tjavaflex doesn't work
Maybe I have to make a join in the tjavaflex but how ?

Here is the flow, the tmap and the tJavaFlex

Thanks
One Star

Re: spliting files an renaming files

Hello
I still can't make it work,
Thanks

Re: spliting files an renaming files

Your code looks correct. What could be happening is that some rows of your input are not joining to the main flow-- leaving the value in the global map for that row as NULL. When you attempt to call .toString() on that null value, you will get a null pointer exception. If you expect some rows to not have lookup values, you can protect your call in the tJavaFlex by checking if the value is null before calling toString() on it:
globalMap.get("row11.AGEDEB") == null ? "" : row10.AGEDEB=globalMap.get("row11.AGEDEB").toString();