tFileRowCount
inside.
tFileRowCount Standard properties
These properties are used to configure tFileRowCount running in the Standard Job framework.
The Standard
tFileRowCount component belongs to the File family.
The component in this framework is available in all Talend
products.
Basic settings
File Name |
Name or path to the file to be processed and/or the variable to be For further information about how to define and use a variable in Warning: Use absolute path (instead of relative path) for
this field to avoid possible errors. |
Row separator |
String (ex: ” |
Ignore empty rows |
Select this check box to ignore the empty rows while the component |
Encoding |
Select the encoding type from the list or select Custom and define it manually. This field |
Advanced settings
tStatCatcher Statistics |
Select this check box to gather the processing metadata at the Job |
Global Variables
Global Variables |
COUNT: the number of rows in a file. This is a Flow
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 |
tFileRowCount is a standalone |
Connections |
Outgoing links (from this component to another): Row: Main; Iterate.
Trigger: On Subjob Ok; On Subjob Incoming links (from one component to this one): Row: Main; Reject; Iterate.
Trigger: On Subjob Ok; On Subjob For further information regarding connections, see |
Limitation |
Due to license incompatibility, one or more JARs required to use |
Writing a file to MySQL if the number of its records matches a reference
value
In this scenario, tFileRowCount counts the number of
records in a .txt file, which is compared against a reference value through tJava. Once the two values match, the .txt file will be
written to a MySQL table.
The .txt file has two records:
1 2 |
1;andy 2;mike |
Linking the components
-
Drop tFileRowCount, tJava, tFlieInputDelimited,
and tMysqlOutput from the Palette onto the design workspace. - Link tFileRowCount to tJava using an OnSubjobOk trigger.
-
Link tJava to tFlieInputDelimited using a Run
if trigger. -
Link tFlieInputDelimited to tMysqlOutput using a Row > Main
connection.
Configuring the components
-
Double-click tFileRowCount to open its
Basic settings view. -
In the File Name field, type in the full
path of the .txt file. You can also click the […] button to browse for this file.Select the Ignore empty rows check
box. -
Double-click tJava to open its Basic settings view.
In the Code box, enter the function to
print out the number of rows in the file:1System.out.println(globalMap.get("tFileRowCount_1_COUNT")); -
Click the if trigger connection to open
its Basic settings view.In the Condition box, enter the statement
to judge if the number of rows is 2:1((Integer)globalMap.get("tFileRowCount_1_COUNT"))==2This if trigger means that if the row
count equals 2, the rows of the .txt file
will be written to MySQL. -
Double-click tFlieInputDelimited to open
its Basic settings view.In the File name/Stream field, type in
the full path of the .txt file. You can also click the […] button to browse for this file. -
Click the Edit schema button open the
schema editor. -
Click the [+] button to add two columns,
namely id and name, respectively of the integer and string
type. -
Click the Yes button in the pop-up box to
propagate the schema setup to the following component. -
Double-click tMysqlOutput open its
Basic settings view. -
In the Host and Port fields, enter the connection details.
In the Database field, enter the database
name.In the Username and Password fields, enter the authentication details.In the Table field, enter the table name,
for instance “staff”. -
In the Action on table list, select
Create table if not exists.In the Action on data list, select
Insert.
Executing the Job
- Press Ctrl+S to save the Job.
-
Press F6 to run the Job.
As shown above, the Job has been executed successfully and the number of
rows in the .txt file has been printed out. -
Go to the MySQL GUI and open the table staff.
As shown above, the table has been created with the two records
inserted.