talend - filename of output from a column value

时光毁灭记忆、已成空白 提交于 2020-01-06 16:24:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!