August 15, 2023

tCreateTemporaryFile – Docs for ESB 6.x

tCreateTemporaryFile

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

tCreateTemporaryFile Standard properties

These properties are used to configure tCreateTemporaryFile running in the Standard Job framework.

The Standard
tCreateTemporaryFile component belongs to the File family.

The component in this framework is generally available.

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.

Advanced settings

tStatCatcher Statistics

Select this check box to collect log data at the component level.

Global Variables

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.

Usage

Usage rule

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

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
.

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.

Use_Case_tCreateTemporaryFile.png

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.

    Use_Case_tCreateTemporaryFile1.png

  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.

    Use_Case_tCreateTemporaryFile2.png

  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:

Writing the data into the file

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

    Use_Case_tCreateTemporaryFile3.png

  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.

    Use_Case_tCreateTemporaryFile4.png

  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.

    Use_Case_tCreateTemporaryFile5.png

  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.

    Use_Case_tCreateTemporaryFile6.png

  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.

    Use_Case_tCreateTemporaryFile7.png

  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.

    Use_Case_tCreateTemporaryFile8.png

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

Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x