creating file name based on Table name in Database

One Star

creating file name based on Table name in Database

Hi,
I would like to know if Talend can generate File name in CSV format in which the name of the file is based on table name in database.
For Example.
Table Name in databse : FACT_COUNTRY --> FACT_COUNTRY.csv
Is it possible? Can anyone suggest me how it can be done?
Thanks
Fadh
One Star

Re: creating file name based on Table name in Database

HI,
Anyone can help me regarding this issue?
Thank you in advance.
Regards,
fadh
Nine Stars

Re: creating file name based on Table name in Database

Yes it can be done.
I made a job that writes out the DLL for all tables and views in a Teradata database into one file per table and view.
What database are you using?
Five Stars

Re: creating file name based on Table name in Database

The basic principle is that you need to determine how you get your database table names.
For Oracle, this might be "select table_name from user_tables"
You then feed the output to tFlowTowIterate.
You haven't said what you want to write to this file, but for the purposes of an example, you could write some arbitrary data using tFixedFlowInput.
You are then able to specify the file name in your tFileOutputDelimited component.
So...
tOracleInput(row1)->tFlowToIterate(iterate)->tFixedFlowInput(row2)->tFileOutputDelimited
You would set your output file name to: -
((String) globalMap.get("row1.table_name")) + ".csv"
One Star

Re: creating file name based on Table name in Database

Hi,
Thank you for replying my question. may I know, is it possible for me to add current date at the back of the file name?
E.g : ((String) globalMap.get("row1.table_name")) + "_"+ TalendDate.getcurrentDate".csv"

Is my syntax correct?
Five Stars

Re: creating file name based on Table name in Database

You probably want to do something like
TalendDate.formatDate("yyyyMMdd", TalendDate.getCurrentDate())
One Star

Re: creating file name based on Table name in Database

Yes. How am i going to merge  between ((String) globalMap.get("row1.table_name")) + ".csv" and TalendDate.formatDate("yyyyMMdd", TalendDate.getCurrentDate())?

e.g FACT_COUNTRY --> FACT_COUNTRY_20160509.csv

Thanks,
fadh
Nine Stars

Re: creating file name based on Table name in Database

First you need to run a select statement to get the tablename, you set what is returned to a context variable. Then you call the context variable before you concatenate the date timestamp.
One Star

Re: creating file name based on Table name in Database

HI,
Actually I am quite confuse with the select statement.  "select table_name from user_tables"  If I am using MSSQL as my db, and let say my table name is FACT_COUNTRY, hence should I use : select FACT_COUNTRY from FACT_COUNTRY? Its quite weird with my select statement.
Five Stars

Re: creating file name based on Table name in Database

"select table_name from user_tables"
If this statement yields a list of tables names and all you want to do is create a file name for each of those tables, then the actual table FACT_COUNTRY does not come in to it.
tMSSQLInput(row1)->tFlowToIterate(OnComponentOK)->tJava
You can now get your table name in tJava.
((String) globalMap.get("row1.table_name"))
I'm guessing at some point you may want to get data from FACT_COUNTRY; but that is a different question.
On a side note, shouldn't FACT_COUNTRY actually be DIM_COUNTRY?