tCreateTemporaryFile
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 |
Use default temporary system directory |
Select this check box to create the file in the default system |
Directory |
Specify the directory under which the temporary file will be This field is available only when the Use |
Template |
Enter the temporary file name which should contain the characters |
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
ERROR_MESSAGE: the error message generated by the A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see |
Usage
Usage rule |
This component can be used as a standalone component of a Job or |
Connections |
Outgoing links (from this component to another):
Trigger: On Subjob Ok; On Subjob Incoming links (from one component to this one): Row: Iterate.
Trigger: Run if; On Subjob Ok; On For further information regarding connections, see |
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
-
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. -
Connect tRowGenerator to tFileOutputDelimited using a Row > Main
connection. - Do the same to connect tFileInputDelimited to tLogRow.
-
Connect tCreateTemporaryFile to tJava using a Trigger > OnSubjobOk
connection. - Do the same to connect tJava to tRowGenerator and connect tRowGenerator to tFileInputDelimited.
Configuring the components
Creating the temporary file
-
Double-click tCreateTemporaryFile to open
its Basic settings view. -
Select the Remove file when execution is
over check box to delete the created temporary file after the
Job execution. -
Select the Use default temporary system
directory check box to create the file in the default system
temporary directory. -
In the Template field, enter the
temporary file name which should contain the characters XXXX. In this example, it is talend_XXXX. -
In the Suffix field, enter the filename
extension of the temporary file. In this example, it is dat. -
Double-click tJava to open its Basic settings view.
-
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:1234System.out.println("The default system temporary directory is:" + (String)System.getProperty("java.io.tmpdir"));System.out.println("The path to the temporary file is:" + (String)globalMap.get("tCreateTemporaryFile_1_FILEPATH"));
Writing the data into the file
-
Double-click tRowGenerator to open its
RowGenerator Editor. -
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. -
In the Number of Rows for RowGenerator
field, enter 5 to generate five
rows. -
Click OK to validate the changes and
accept the propagation prompted by the pop-up dialog box. -
Double-click tFileOutputDelimited to open
its Basic settings view. -
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
-
Double-click tFileInputDelimited to open
its Basic settings view. -
In the File name/Stream field, press
Ctrl+Space and from the global variable
list displayed select ((String)globalMap.get(“tCreateTemporaryFile_1_FILEPATH”)). -
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. -
Click OK to validate the changes and
accept the propagation prompted by the pop-up dialog box. -
Double-click tLogRow to open its
Basic settings view. -
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
- Press Ctrl+S to save the Job.
-
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: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.