Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
Labels (2)
9 Replies
Anonymous
Not applicable
Author

HI,
Anyone can help me regarding this issue?
Thank you in advance.
Regards,
fadh
talendtester
Creator III
Creator III

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?
Anonymous
Not applicable
Author

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"
Anonymous
Not applicable
Author

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?
Anonymous
Not applicable
Author

You probably want to do something like
TalendDate.formatDate("yyyyMMdd", TalendDate.getCurrentDate())
Anonymous
Not applicable
Author

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
talendtester
Creator III
Creator III

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.
Anonymous
Not applicable
Author

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.
Anonymous
Not applicable
Author

"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?