Search code examples
talend

talend - filename of output from a column value


I have an existing job:

tDatabaseInput -> tMap -> tOutputDelimited

For the last component, I need 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.


Solution

  • There is many ways to do it, but here is the simplest and more readable job :

    talend job big data hadoop

    • 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"))