tSetEnv - 6.1

Talend Open Studio for Big Data Components Reference Guide

EnrichVersion
6.1
EnrichProdName
Talend Open Studio for Big Data
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

tSetEnv Properties

Component family

System

 

Function

tSetEnv adds variables temporarily to system environment during the execution of a Job.

Purpose

tSetEnv allows to create variables and execute a Job script through communicating the information about the newly created variables between subjobs. After job execution, the newly created variables are deleted.

Basic settings

Parameters

Click the plus button to add the variables needed for the job. name: Enter the syntax for the new variable.

value: Enter a parameter value according to the context.

append: Select this check box to add the new variable at the end.

Advanced settings

tStatCatcher Statistics

Select this check box to gather the processing metadata at the Job level as well as at each component level.

Global Variables

ERROR_MESSAGE: the error message generated by the component when an error occurs. This is an After variable and it returns a string. This variable functions only if the Die on error check box is cleared, if the component has this check box.

A Flow variable functions during the execution of a component while an After variable functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl + Space to access the variable list and choose the variable to use from it.

For further information about variables, see Talend Studio User Guide.

Usage

tSetEnv can be used as a start or an intermediate component.

Log4j

If you are using a subscription-based version of the Studio, the activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User Guide.

For more information on the log4j logging levels, see the Apache documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html.

Limitation

n/a

Scenario: Modifying a variable during a Job execution

The following scenario is made of two Jobs parent and child. With the tSetEnv component, you can transfer and modify in a child Job a value created in a parent Job. As part of this Job, the tMsgBox components allow you to display, for information purposes only, that a variable is properly set, via an info-box.

To modify the value of the parent Job by using a variable set in the tSetEnv component, do as described in the following sections:

Drop and link components

  1. Create a first Job named parentJob: right-click on the Job Design node of the Repository, and choose Create a Job.

  2. From the Palette, drop a tSetEnv component, two tMsgBox components, and one tRunJob component onto the design workspace.

  3. Connect the tSetEnv component to a first tMsgBox component with a OnSubjobOk link : right-click on the start component, select Trigger, then OnSubjobOk. Then click on the end component you want to connect.

  4. Connect the first tMsgBox component to the tRunJob with a OnSubjobOk link.

  5. Then connect the tRunJob component to the second tMsgbox with a OnSubjobOk link.

  6. Now create a child Job named ChildJob.

  7. From the Palette, drop a tSetEnv component onto the design workspace.

  8. Connect the tSetEnv component to the tMsgBox with a OnSubjobOk link: right-click on the start component, select Trigger, then OnSubjobOk. Then click on the end component you want to connect.

Set the components

In this example, the value set in the parent Job is transferred to the child Job. There, it is modified and adopts the value of the child Job, and then transferred to the parent Job again.

  1. In parentJob, select the tSetEnv component and click the Component tab. Add a variable row by clicking the [+] button to set the initial value of the variable. Type Variable_1 in the Name field, and Parent job value in the Value field.

  2. Select the first tMsgBox component, and click the Component tab. In the Message field, type the message displayed in the info-box which confirms that your variable has properly been taken into account. For example: "Parent:"+System.getProperty("Variable_1") displays the variable set in the tSetEnv component (here Parent job value).

  3. Select the second tMsgBox component, and click the Component tab. In the Message field, type the "Parent:"+System.getProperty("Variable_1") line again. It makes the variable set in the child Job appear.

  4. Select the tRunJob component and click the Component tab. In the Job field, type the name of your child Job, here ChildJob. This will run the child Job when you run the parent Job.

  5. Now double-click the tRunJob component to open the child Job ChildJob.

  6. Select the tSetEnv component, and click the Component tab. Add a variable row by clicking the [+] button to set the initial value of the variable. Type Variable_1 in the Name field, and Child job value in the Value field.

  7. Select the tMsgBox component and click the Component tab. In the Message field, type the message displayed in the info-box which confirms that your variable has properly been taken into account. For example: "Son:"+System.getProperty("Variable_1") displays the variable set in the tSetEnv component (here Child job value).

  8. Save your Job, go back to parentJob, then run the Job by pressing F6.

Run the Job

Three info-boxes are displayed one after the other:

  • Parent: Parent job value: parent Job's value is Parent job value.

  • Child: Child job value: Child Job's value is Child job value.

  • Parent: Child job value: parent Job's value was modified by the variable set in the tSetEnv of the child Job, then transferred again to the parent Job. parent Job's value is now the one set in the child Job.