Create a Global Context Group in Talend

This section shows how to create a global context group in Talend with multiple examples. Talend context groups are of two types: Local and Global. Local context groups belong to the Job that we created. However, global context groups can be used in multiple Jobs. For instance, you can create a Talend context group for storing all the Database connections. Then you can use them in all the jobs that are required to connect with this database.

The Talend Global context group concept is straightforward and most powerful. In real-time, it plays a significant role in Job design because the file paths, Database connections, etc., differ from Development and Production. So, once you move your project to the production environment, you have to change these values within the Job. It is not a viable or advisable option, and if you have the Talend global context group, then you can change it at this place, and it will update all the Jobs.

Creating a Talend Global Context Group Example

In order to create a global one in Talend, right-click on the Context folder and select Create Context group from the menu.

Create Global Context Group 1

Clicking on the Talend Create context group option opens the following window. Please fill in the Name, the purpose of this context group, and a brief description of the context group variables.

Create Global Context Group 2

This Talend page allows you to add the context variables, type, and values. We have added the Login, Password, Server (SQL Server Instance name), Database, and Database Schema from the below screenshot. These variables help to establish a connection with the AdventureWorks 2014 database in a SQL Server Prasad instance.

Create Global Context Group 4

Now you can see the newly created Talend Global Context group. Right-click on it allows you to edit or delete that group.

Create Global Context Group 5

The second approach to Create a Talend Global Context Group

There is another approach to creating a global context group in Talend. When you are creating a connection, you can export that setting as a context group. In this example, we show you the same.

First, right-click on the Db Connections and choose Create a connection from the context menu. We already explained all the options in the Connect Talend to SQL Server article so, please refer to the same.

Create connection 6

The Create Connection option will open the following window. Let me assign the Name as AdventureWorks_Con leave the remaining empty and click the Next button.

Database connection window 7

Within the second page, we are filling in all the details required to connect with AdventureWorksDW 2014.

Before clicking the finish button, click on the Export as context button. This button is available in many places, and wherever you click, it will help you export all the values to a context group.

Fill the Login and password, server, and port number 8

Clicking on the Export as context button opens the following window. Please select Create a new repository context for creating a Talend global context group. You can choose the second option to reuse the existing one.

Create Global Context Group 9

Please assign a unique name for this Talend context group.

Click the finish button 10

From the below screenshot, you can see all the context variables imported. Here, you can change the Default context environment from Default to Production or some other to specify this environment’s settings. 

Click the Finish button to finish creating the Talend Global context group.

Create Global Context Group 11

Click the Finish button to create a database connection.

Click the finish button 12

From the screenshot below, you can see the two context groups that we created in this article and the new Db Connection.

Create Global Context Group 13

Use Global Context Group in a Talend Job

Please drag and drop the tDBInput and select the Database as a Microsoft SQL Server. The following image shows you the options that you have to fill.

Create Global Context Group 14

Next, go to the Context tab to add the context variables or groups. Whatever you add in this tab belongs to this Job, and we call it a local context group. This is the place where we can add the Talend global context groups from the Repository as well. So, let me drag the global context group from Repository to this tab.

From the image below, you can see the context variables required to connect with the Adventure Works Data warehouse.

Create Global Context Group 16

Please type context followed by a dot and click the control + space button to display the suggestions. I suggest you assign the proper values to each property. If you look closely, we have chosen the DimProduct as the Table name by typing that name and writing that select statement to select all the products. Next, we clicked the Guess Schema button to extract the schema.

Check the Component tab 17

The other option is to change the Schema from Built-in type to Repository and select the table Name using the Browse button.

Here, we are using the Built-in Schema, so click the Browse to open the following window to check the schema or columns within that table. Please use this window to alter the position of columns based on your requirements.

Create Global Context Group 18

Let me add tLogRow and please use the Table model and Run the Talend global context group Job. Below, you can see the output of the table.

Create Global Context Group 19