This section shows how to create a global context group in Talend with multiple examples. Talend context groups are of two types: Local context and Global context groups. Local context groups belong to the Job that we created. However, Talend global context groups can use 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 Talend 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 global context group, then you can change at this place, and it will update all the Jobs.
Creating a Talend Global Context Group Example
In order to create global context groups in Talend, right-click on the Context folder and select Create context group from the context menu.
Clicking on the Talend Create context group option opens the following window. Please fill the Context group Name, the purpose of this context group, and the brief description of the context group variables.
This Talend page allows you to add the context variables, type, and their 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.
Now you can see the newly created Talend Global Context group. Right-click on it allows you to edit or delete that group.
The second approach to Create a Talend Global Context Group
There is another approach to create 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 the Create connection from the context menu. We already explained all the options in Connect Talend to SQL Server article so, please refer to the same.
The Create connection option will open the following window. Let me assign the Name as AdventureWorks_Con and leave the remaining empty and click the Next button.
Within the second page, we are filling 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.
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.
Please assign a unique name for this Talend context group.
From the below screenshot, you can see all the context variables imported by the Talend. 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 Talend Global context group.
Click the Finish button to create a database connection.
From the screenshot below, you can see the two context groups that we create in this article and the new Db Connection.
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.
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. And this is the place 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.
Please type context followed by a dot and click 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.
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.
Let me add tLogRow and used the Table model and Run the Talend global context group Job. From below, you can see the output of the table.