July 30, 2023

tFileRowCount – Docs for ESB 7.x

tFileRowCount

Opens a file and reads it row by row in order to determine the number of rows
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
used.

For further information about how to define and use a variable in
a Job, see
Talend Studio

User Guide.

Warning: Use absolute path (instead of relative path) for
this field to avoid possible errors.

Row separator

String (ex: ”
“on Unix) to distinguish rows in the output
file.

Ignore empty rows

Select this check box to ignore the empty rows while the component
is counting the rows in the file.

Encoding

Select the encoding type from the list or select Custom and define it manually. This field
is compulsory for DB data handling.

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

Global Variables

COUNT: the number of rows in a file. This is a Flow
variable and it returns an integer.

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

tFileRowCount is a standalone
component, it must be used with a OnSubjobOk
connection to tJava.

Connections

Outgoing links (from this component to another):

Row: Main; Iterate.

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

Incoming links (from one component to this one):

Row: Main; Reject; Iterate.

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

For further information regarding connections, see

Talend Studio User
Guide
.

Limitation

Due to license incompatibility, one or more JARs required to use
this component are not provided. You can install the missing JARs for this particular
component by clicking the Install button
on the Component tab view. You can also
find out and add all missing JARs easily on the Modules tab in the
Integration
perspective of your studio. You can find more details about how to install external modules in
Talend Help Center (https://help.talend.com)
.

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:

Linking the components

  1. Drop tFileRowCount, tJava, tFlieInputDelimited,
    and tMysqlOutput from the Palette onto the design workspace.
  2. Link tFileRowCount to tJava using an OnSubjobOk trigger.
  3. Link tJava to tFlieInputDelimited using a Run
    if
    trigger.
  4. Link tFlieInputDelimited to tMysqlOutput using a Row > Main
    connection.

    tFileRowCount_1.png

Configuring the components

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

    tFileRowCount_2.png

  2. 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.
  3. Double-click tJava to open its Basic settings view.

    tFileRowCount_3.png

    In the Code box, enter the function to
    print out the number of rows in the file:
  4. Click the if trigger connection to open
    its Basic settings view.

    tFileRowCount_4.png

    In the Condition box, enter the statement
    to judge if the number of rows is 2:
    This if trigger means that if the row
    count equals 2, the rows of the .txt file
    will be written to MySQL.
  5. Double-click tFlieInputDelimited to open
    its Basic settings view.

    tFileRowCount_5.png

    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.
  6. Click the Edit schema button open the
    schema editor.

    tFileRowCount_6.png

  7. Click the [+] button to add two columns,
    namely id and name, respectively of the integer and string
    type.
  8. Click the Yes button in the pop-up box to
    propagate the schema setup to the following component.

    tFileRowCount_7.png

  9. Double-click tMysqlOutput open its
    Basic settings view.

    tFileRowCount_8.png

  10. 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”.
  11. In the Action on table list, select
    Create table if not exists.

    In the Action on data list, select
    Insert.

Executing the Job

  1. Press Ctrl+S to save the Job.
  2. Press F6 to run the Job.

    tFileRowCount_9.png

    As shown above, the Job has been executed successfully and the number of
    rows in the .txt file has been printed out.
  3. Go to the MySQL GUI and open the table staff.

    tFileRowCount_10.png

    As shown above, the table has been created with the two records
    inserted.

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