Hurry! 20% Off Ends SoonRegister Now
  • Home
  • Blog
  • Talend
  • Using tContextLoad and Implicit Context Loading in Talend

Using tContextLoad and Implicit Context Loading in Talend

Using contexts and variables

Variables represent values which change throughout the execution of a program. A global variable is a system variable which can be accessed by any module or function. It retains its value after the function or program using it, has completed execution. A context variable is a variable which is defined by the user for a particular context.

Depending on the circumstances the Job is being used in, you might want to manage it differently for various execution types, known as contexts (Prod and Test in the example given below). For instance, there might be various testing stages you want to perform and validate before a Job is ready to go live for production use.

A context is characterized by parameters. These parameters are mostly context-sensitive variables which will be added to the list of variables for reuse in the component-specific properties on the Component view through the Ctrl+Space keystrokes.

Talend Studio offers you the possibility to create multiple context data sets. Furthermore, 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, or load your context parameters dynamically, either explicitly using the tContextLoad component or implicitly using the Implicit Context Load feature, when your Jobs are executed.

This section describes how to create contexts and variables and define context parameter values.

If you would like to Enrich your career with a Talend certified professional, then visit Mindmajix - A Global online training platform: “Talend Certification Training”  Course.  This course will help you to achieve excellence in this domain.

Using tContextLoad to load contexts

Function tContextLoad modifies dynamically the values of the active context.

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

This component performs also two controls. It warns when the parameters defined in the incoming flow are not defined in the context, and the other way around, it also warns when a context value is not initialized in the incoming flow.

-------     Related Page: Creating and Adding a Context Group to Your Job     -------

But note that this does not block the processing.

A second method for defining context variables in a different environment is to store them in a file or database external to Talend, and then load them as part of a job.

MindMajix Youtube Channel

Getting ready

Open the jo_cook_ch06_0020_loadContextData job.

How to achieve it…

The steps for using TCONTEXTLOAD to load contexts are as follows:

  • Open the tFileInputDelimited component and change the delimiter to, so that it matches the format in the file.
  • Drag a tContextLoad component onto the canvas and link it to tFileInputDelimited.
  • Open tContextLoad, and click on the option Print operations.
  • Unclick Disable warnings.
  • Run the job.

How it works…

The context file contains name/value pairs in the form of key=value, so setting the delimiter to = means that we can identify each column in the Talend schema.

When we click on the print operations, it causes Talend to print out what is happening with the context.

------        Check Out Talend Tutorials        ------

There’s more…

The tContextLoad does have some additional features that you may wish to use. They are described in the following sections.

Print operations

It is usually only necessary to set print operations when debugging code, since it isn’t usually good practice to print the values of say passwords in a log file. It is better, if you wish to log the values, to use the tContextDump component.

Warnings

The tContextLoad component allows different variations of warnings and error conditions to be specified, depending upon your requirements. It is therefore possible to check for context variables being correctly set, prior to a job running, and to fail the job if they are not.

Tip

However, you have to take care with this approach, because job-specific context variables can cause errors and warnings if you do not set them in the file, despite the fact that they may not need a value to be set at the start of the job.

Context file location

The downside of this method as shown is that the context file must reside in the same location on every machine.

Frequently Asked TALEND Interview Questions & Answers

Using the implicit context loading to load contexts

This method is very similar to the one discussed previously, that the context data is external to Talend, but differs in the fact that the context data is loaded automatically for every job in a project.

Getting ready

Open the jo_cook_ch06_0030_implicitContextLoad job.

How to achieve it…

The steps for using implicit context load to load contexts are as follows:

  • Click on File, then Edit project properties.
  • From the dialogue box, expand Job Settings and select the option for Implicit context load.
  • Check the option for Implicit tContextLoad.
  • Check the option From File.
  • Set the From File name to
C:/cookbookData/chapter6/chapter6_jo_0020_cookbookContextFile.txt.
  • Set the Field Separator to =.
  • Click on the Print operations.
  • Click on Ok to finish.
  • Run the job, and you will see the context data being loaded and the warnings being produced.

How it works…

The implicit context load functionality reproduces the code in the previous exercise for all jobs in the project.

As with the previous exercise, the context file, the delimiter, and the actions to be taken while loading the contexts are all specified, just that with this method, it is global for every job.

There’s more…

This method suffers from the same shortcomings as the method in the previous exercise, but is easier to maintain and implement, because the values are set centrally.

Tip

Remember to set the project properties back to normal, once you have completed this exercise, unless you plan to perform the next one.

Explore TALEND Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

Job Support Program

Online Work Support for your on-job roles.

jobservice

Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:

  • Pay Per Hour
  • Pay Per Week
  • Monthly
Learn MoreGet Job Support
Course Schedule
NameDates
Talend TrainingDec 24 to Jan 08View Details
Talend TrainingDec 28 to Jan 12View Details
Talend TrainingDec 31 to Jan 15View Details
Talend TrainingJan 04 to Jan 19View Details
Last updated: 03 Apr 2023
About Author

Ravindra Savaram is a Technical Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.

read less