Loading Context Parameters Dynamically From an External File

Posted on by By admin, in Talend | 0

A context variable is a variable which is defined by the user for a particular context.

Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.

Grab The 30 Days Free Trail

For creating contexts, you can either create context data sets on a one-shot basis from the context tab of a Job, or you can centralize the context data sets in the Contexts node of the Repository tree view in order to reuse them in different Jobs.

You can define the values of your context variables when creating them. But, if the values are frequently subjected to change, then, modifying the values in the job every-time can become a tedious task, or an end user cannot open the application to change the parameters.

In such scenarios, the contexts parameters can be loaded dynamically either explicitly using the tContextLoad component or implicitly using the Implicit Context Load feature.

This blog describes how to fetch the context values from an external file and load them in the talend job explicitly.

tContextLoad can be used to load a context value from a flow.

Consider an example where the configuration of a PostgreSQL database is fetched from a file.

STEP1: Set up the context

In the context tab, add variables which will be loaded and required in the job.

context parameters

STEP2: Configure input file

Drag tFileInputDelimited component into the canvas and set the properties of the component, to fetch the text file which holds the values to be loaded.

Configure input file

STEP3: Load context

By connecting tContextLoad component to the input file, the values from the flow will be loaded into contexts and can be fetched throughout the job.

Load context

STEP4: Connect to the main job

The main job which fetches data from a postgresql database and dumps values into a file is connected to context load subjob using OnSubjobOk trigger. Hence the configuration values from the file is loaded into the database using tContextLoad component.

Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.

Click Here to Free Download

Connect to the main job

In tPostgresqlInput component, set the configuration variables with the contexts as follows.

configuration variables

After executing the job, a file(output.txt) is created which holds values from the database table.

file output.txt

 

Changing the context values dynamically

After exporting the job, the values in the file holding the context values can be changed before execution. For this, copy the file and place it in the folder which holds .sh and .bat files.

The file path in the tFileInputDelimited has to be set to a relative path.

Relative Path

Export the job by clicking on the build job option of the job in the job design.

build job option

In the exported job folder which has .sh and .bat files place the file with context values.

Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.

Click Here to Free Download

context-values

context-values1

Hence, the modifications in the values can be made in this file, if there are any changes required to be made in context values.

logo

Best Open Source Business Intelligence Software Helical Insight is Here

logo

A Business Intelligence Framework

If you have any queries please get us at support@helicaltech.com

Thank You

Rajitha

Helical IT Solutions Pvt Ltd

5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments