问题
I have an existing job:
tDatabaseInput -> tMap -> tOutputDelimited
For the last component, I'll be needing the filename of the file to be based from one of the columns named TYPE (which is always the same for every row). The value for the column named TYPE is 'A1' which is the same for all the records in the database.
Thanks in advanced
回答1:
There is many ways to do it, but here is the simplest and more readable job :
- tMySqlConnection_1 : Get a connection to the data base server
tMysqlInput_1: Query the table an get only the value like this :
select TYPE from my_table limit 1
tSetGlobalVar_1 : key =
"file_name"
, value =(String)row1.type
- tMysqlInput_2 : uqery the table as required
- tMap_1 : map your data
- tFileOutputDelimited_1 : filename =
"C:\\Users\\KKL\\Desktop\\"+((String)globalMap.get("file_name"))
回答2:
You'll need two subjobs, as having a filename based on a column in your flow implies that this filename is extracted from another subjob.
You should have a first subjob getting the value of your column named TYPE into into a context variable
TDBInput->tJavaRow
TDBInput : just extract distinct TYPE column from your DB with a select query
tJavaRow : as you'll have only one row in the output, you can affect this value to a context variable : context.myVar=input_row.myColumn;
Then connect this first subjob to the second one (tDatabaseInput -> tMap -> tOutputDelimited)
, and use this context variable in your tFileOutputDelimited, in the filename field
"/path/"+context.myVar+".ext"
来源:https://stackoverflow.com/questions/42666094/talend-filename-of-output-from-a-column-value