tCreateTemporaryFile - 6.1

Talend Components Reference Guide

EnrichVersion
6.1
EnrichProdName
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

tCreateTemporaryFile properties

Component family

File/Management

Function

tCreateTemporaryFile creates and manages temporary files.

Purpose

tCreateTemporaryFile helps to create a temporary file in a specified directory. This component allows you to either keep the temporary file or delete it after the Job execution.

Basic settings

Remove file when execution is over

Select this check box to delete the temporary file after the Job execution.

 

Use default temporary system directory

Select this check box to create the file in the default system temporary directory.

 

Directory

Specify the directory under which the temporary file will be created.

This field is available only when the Use default temporary system directory check box is cleared.

 

Template

Enter the temporary file name which should contain the characters XXXX, such as talend_XXXX.

 

Suffix

Enter the filename extension of the temporary file.

Usage

This component can be used as a standalone component of a Job or Subjob.

Global Variables

FILEPATH: the path where the file was created. This is an After variable and it returns a string.

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.

Connections

Outgoing links (from this component to another):

Trigger: On Subjob Ok; On Subjob Error; Run if; On Component Ok; On Component Error.

Incoming links (from one component to this one):

Row: Iterate.

Trigger: Run if; On Subjob Ok; On Subjob Error; On component Ok; On Component Error; Synchronize; Parallelize.

For further information regarding connections, see Talend Studio User Guide.

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: Creating a temporary file and writing data into it

This scenario describes a Job that creates a temporary file in the default system temporary directory, writes data into the file, and finally displays the data in the file on the console.

Adding and linking the components

  1. Create a new Job and add the following components by typing their names in the design workspace or dropping them from the Palette: a tCreateTemporaryFile component, a tJava component, a tRowGenerator component, a tFileOutputDelimited component, a tFileInputDelimited component, and a tLogRow component.

  2. Connect tRowGenerator to tFileOutputDelimited using a Row > Main connection.

  3. Do the same to connect tFileInputDelimited to tLogRow.

  4. Connect tCreateTemporaryFile to tJava using a Trigger > OnSubjobOk connection.

  5. Do the same to connect tJava to tRowGenerator and connect tRowGenerator to tFileInputDelimited.

Configuring the components

Creating the temporary file

  1. Double-click tCreateTemporaryFile to open its Basic settings view.

  2. Select the Remove file when execution is over check box to delete the created temporary file after the Job execution.

  3. Select the Use default temporary system directory check box to create the file in the default system temporary directory.

  4. In the Template field, enter the temporary file name which should contain the characters XXXX. In this example, it is talend_XXXX.

  5. In the Suffix field, enter the filename extension of the temporary file. In this example, it is dat.

  6. Double-click tJava to open its Basic settings view.

  7. In the Code field, enter the following code to display the default system temporary directory and the path to the temporary file that will be created on the console:

    System.out.println("The default system temporary directory is:\r" + (String)System.getProperty("java.io.tmpdir"));
    System.out.println("The path to the temporary file is:\r" + (String)globalMap.get("tCreateTemporaryFile_1_FILEPATH"));

Writing the data into the file

  1. Double-click tRowGenerator to open its RowGenerator Editor.

  2. Click the [+] button to add two columns: id of Integer type and name of String type. Then in the Functions column, select the predefined function Numeric.sequence(String,int,int) for id and TalendDataGenerator.getFirstName() for name.

  3. In the Number of Rows for RowGenerator field, enter 5 to generate five rows.

  4. Click OK to validate the changes and accept the propagation prompted by the pop-up dialog box.

  5. Double-click tFileOutputDelimited to open its Basic settings view.

  6. In the File Name field, press Ctrl+Space and from the global variable list displayed select ((String)globalMap.get("tCreateTemporaryFile_1_FILEPATH")).

Reading the data from the file

  1. Double-click tFileInputDelimited to open its Basic settings view.

  2. In the File name/Stream field, press Ctrl+Space and from the global variable list displayed select ((String)globalMap.get("tCreateTemporaryFile_1_FILEPATH")).

  3. Click the [...] button next to Edit schema and in the dialog box displayed define the schema by adding two columns: id of Integer type and name of String type.

  4. Click OK to validate the changes and accept the propagation prompted by the pop-up dialog box.

  5. Double-click tLogRow to open its Basic settings view.

  6. In the Mode area, select Table (print values in cells of a table) to display the output data in a better way.

Saving and executing the Job

  1. Press Ctrl+S to save the Job.

  2. Press F6 or click Run on the Run tab to run the Job.

    The file talend_MHTI.dat is created under the default system temporary directory C:\Users\lena_li\AppData\Local\Temp\ during the Job execution, the five generated rows of data is written into it, then the file is deleted after the Job execution.