Dynamically populate filename in tFileTouch/tFileInput/other component in Talend

Dynamically populate filename in tFileTouch/tFileInput/other component in Talend

Summary

In this post i will discuss on how we can dynamically provide filenames to file related components.
This is something which you would definitely need in your talend jobs as you would like to avoid hardcoded file names and path in your file related components. This also enables you to deploy your jobs easily without any changes from dev,qa to prod as file name/path is not hardcoded.

 

Details

We can use talend context parameters or global variables to store filenames and use these in tFile related components. Global variables and context parameters are very useful in talend and you will end up using them in your jobs too. You can set and get values from global variables in your job. You can use tSetGlobalVar to define the global variables, though its not a mandate. using globalMap.get(), globalMap.set() you get the values stored in global variable and set it.

Above is easy to implement and very useful.

Using talend context

1) let’s define talend context variables for file name (param_filename) and file path (param_filepath). You can also create a context group if you want to do that in your repository and then use that context group in your job contexts.
2) We can use them to generate filename dynamically in tFileTouch component. tFileTouch component is equivalent to linux touch command – which checks the presence of a file and if not find, it creates an empty file.

 

Using global variable

1) let’s define talend context variables for file name (param_filename) and file path (param_filepath)
2) let’s store the values of above context parameters into global variable using tSetGlobalVar component.
here key is name of our global variable and value is the value it stores.
3) We can use globalMap.get() to retrieve value of global variable for filename and fileparth. We use globalMap.set(“globalvariablename”,value) to set the value in existing global variable or create a new global variable and store the value in it.

 

 

 

 

 

For more info, please contact us below :