Reader small image

You're reading from  Talend Open Studio Cookbook

Product typeBook
Published inOct 2013
Reading LevelIntermediate
PublisherPackt
ISBN-139781782167266
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Rick Barton
Rick Barton
author image
Rick Barton

Rick Barton is a freelance consultant who has specialized in data integration and ETL for the last 13 years as part of an IT career spanning over 25 years. After gaining a degree in Computer Systems from Cardiff University, he began his career as a firmware programmer before moving into Mainframe data processing and then into ETL tools in 1999. He has provided technical consultancy to some of the UKs largest companies, including banks and telecommunications companies, and was a founding partner of a Big Data integration consultancy. Four years ago he moved back into freelance development and has been working almost exclusively with Talend Open Studio and Talend Integration Suite, on multiple projects, of various sizes, in UK. It is on these projects that he has learned many of the lessons that can be found in this, his first book.
Read more about Rick Barton

Right arrow

Chapter 6. Managing Context Variables

This chapter contains exercises that illustrate some of the methods for managing context variables within projects and jobs.

  • Creating a context group

  • Adding a context group to your job

  • Adding contexts to a context group

  • Using tContextLoad to load contexts

  • Using implicit context load to load contexts

  • Turning implicit context load on and off in a job

  • Setting the context file location in the operating system

Introduction


In this chapter, we will perform fairly simple tasks for performing basic operations on context variables, but do not take this as a reflection of the unimportance of context variables.

The use of context variables is a fundamental requirement for creating production quality Talend applications. Appendix B, Management of Contexts, deals with some of the implications of the different methods of managing context variables within a project.

Transportable code

For code to be of production quality, it must be transportable between environments. This means that, when we move code from the development environment to the test environment, it should execute properly even if we are using different file paths, file names, database names, database user IDs, and so on.

Context variables

Context variables are parameters that Talend uses, that can be set to different values in different environments.

Assuming that the Talend code has been built to use these parameters and they have been set correctly...

Creating a context group


A context group is a set of (usually) related context variables for use within a project. This recipe shows how to create a new context group.

How to do it...

The steps for creating a context group are as follows:

  1. Open the metadata panel, and right-click on the context section.

  2. Select the Create context group option.

  3. Name the new group cookbookGeneral.

  4. Click on the Next button, and you will see the main context variable panel.

  5. Click on + to add a new variable and type in cookbookDirectory.

  6. Set the type to Directory.

  7. Now, click on the Values as a table tab, and click on the Default column for cookbookDirectory. Click on the icon.

  8. This will open a directory navigation window, so navigate to the cookbook data directory, and click on Finish.

How it works...

The context group is created in the metadata panel, and the individual context variables can then be added, along with their default values. Because we chose the type as Directory, Talend gives us the option of using a windows...

Adding a context group to your job


A job will not automatically use a context group. This exercise shows how to add a context group to a job.

Getting ready

Open the jo_cook_ch06_0010_addContextGroup job.

How to do it...

The steps for adding a context group to your job are as follows:

  1. Open the context panel, and click on the context icon shown as follows:

  2. You will then be presented with the list of available context groups.

  3. Select cookbookDB, and then Ok.

  4. You will now see that the cookbookDB context variables have been added as read-only variables into the job.

How it works…

The context dialogue within a job allows single (in job) contexts, as well as context groups, to be added to a job.

There’s more…

The preceding method shows how to add all context variables into a job. There is also an option to add only a subset of the variables within the group, if you drill down into the context group when selecting, demonstrated as follows:

Tip

Another method of adding the context to the job from the metadata is...

Adding contexts to a context group


Talend provides a means for defining multiple different sets of values for the parameters in a group, one for each environment (or context).

Getting ready

Open the jo_cook_ch06_0010_addContextGroup job, and open the context group cookbookGeneral.

How to do it...

The steps for adding contexts to a context group are as follows:

  1. Open the context panel, and click on the context icon shown as follows:

  2. Click on Default, click on the Edit button, and then change the name to development.

  3. Click on the New button, and add a context named test.

  4. Click on the New button, and add a context named production.

  5. Click on Ok to exit the dialogue.

  6. Now you will see that there are now additional columns for the new contexts.

There’s more…

The additional columns will define the values of a context variable in each context, and these will most likely contain different values, depending upon the environment illustrated as follows:

These contexts can then be selected at runtime via the shell...

Using tContextLoad to load contexts


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

Getting ready

Open the jo_cook_ch06_0020_loadContextData job.

How to do it...

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

  1. Open the tFileInputDelimited component and change the delimiter to, so that it matches the format in the file.

  2. Drag a tContextLoad component onto the canvas and link it to tFileInputDelimited.

  3. Open tContextLoad, and click on the option Print operations.

  4. Unclick Disable warnings.

  5. 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 as columns in the Talend schema.

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

There’s more…

The tContextLoad does have some additional features that you may wish to use...

Using 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 do it...

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

  1. Click on File then Edit project properties.

  2. From the dialogue box, expand Job Settings and select the option for Implicit context load.

  3. Check the option for Implicit tContextLoad.

  4. Check the option From File.

  5. Set the From File name to C:/cookbookData/chapter6/chapter6_jo_0020_cookbookContextFile.txt.

  6. Set the Field Separator to =.

  7. Click on the Print operations box.

  8. Click on Ok to finish.

  9. 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...

Turning implicit context loading on and off in a job


Implicit context load can sometimes be annoying, especially when you have many variables, and you are running test jobs. It can sometimes be hard to see the wood from the trees. This exercise show how you can turn off implicit context load if you wish to do so.

Getting ready

Open the jo_cook_ch06_0040_turnOffImplicit job.

How to do it...

The steps for turning implicit context load on and off in a job are as follows:

  1. Open the Job tab.

  2. Select the Extra tab.

  3. Uncheck Use Project Settings.

  4. Uncheck Implicit tContextLoad. Your Job tab should look like the one shown as follows:

  5. Run the job, and you will see that the initial context load is no longer performed.

How it works...

Talend allows the option to perform an implicit tContextLoad to be turned off for individual jobs within a project.

Setting the context file location in the operating system


The initial context load method and the tContextLoad methods do suffer from having to use a predetermined file location. This exercise shows how it is possible to overcome this via the use of system variables.

Note that this exercise is demonstrated on Microsoft Windows 7; however, it is possible to set and use global environment variables in Talend in any version of Windows, Linux, or Mac OS.

Getting ready

Copy the systemValueContext.txt file from the cookbook directory/chapter6 to C:\TalendContextDirectory.

How to do it...

The steps for setting the context file location in the operating system are as follows:

  1. Run the job, and you will notice that the value of the context variable is set to In the job.

  2. Go to Start | Control Panel | System and Security.

  3. Select System, then click the right-hand side Advanced system settings.

  4. Click on the Environment Variables button.

  5. Under the System variables, click on New.

  6. Enter Variable name as TALEND_CONTEXT_DIRECTORY...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Talend Open Studio Cookbook
Published in: Oct 2013Publisher: PacktISBN-13: 9781782167266
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Rick Barton

Rick Barton is a freelance consultant who has specialized in data integration and ETL for the last 13 years as part of an IT career spanning over 25 years. After gaining a degree in Computer Systems from Cardiff University, he began his career as a firmware programmer before moving into Mainframe data processing and then into ETL tools in 1999. He has provided technical consultancy to some of the UKs largest companies, including banks and telecommunications companies, and was a founding partner of a Big Data integration consultancy. Four years ago he moved back into freelance development and has been working almost exclusively with Talend Open Studio and Talend Integration Suite, on multiple projects, of various sizes, in UK. It is on these projects that he has learned many of the lessons that can be found in this, his first book.
Read more about Rick Barton