July 30, 2023

tMemorizeRows – Docs for ESB 7.x

tMemorizeRows

Memorizes a sequence of rows that passes through and allows the following
component(s) to perform operations of your choice on the memorized rows.

tMemorizeRows temporarily
memorizes an array of incoming data in a row by row sequence and instantiates this array
by indexing each of the memorized rows from 0. The maximum number of rows to be
memorized at any given time is defined in the Basic
settings
view.

tMemorizeRows Standard properties

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

The Standard
tMemorizeRows component belongs to the Misc family.

The component in this framework is available in all Talend
products
.

Basic settings

Schema and Edit schema

A schema is a row description, it defines the number of fields that will be
processed and passed on to the next component. The schema is either built-in or
remote in the Repository.

Click Edit
schema
to make changes to the schema. If the current schema is of the Repository type, three options are available:

  • View schema: choose this
    option to view the schema only.

  • Change to built-in property:
    choose this option to change the schema to Built-in for local changes.

  • Update repository connection:
    choose this option to change the schema stored in the repository and decide whether
    to propagate the changes to all the Jobs upon completion. If you just want to
    propagate the changes to the current Job, you can select No upon completion and choose this schema metadata
    again in the Repository Content
    window.

Click Sync columns to retrieve the schema from
the previous component connected in the Job.

 

Built-in: The schema will be created and stored
locally for this component only. Related topic: see
Talend Studio User
Guide
.

 

Repository: You have already created the schema
and stored it in the Repository, hence can be reused in various projects and job
designs. Related topic: see
Talend Studio User
Guide
.

Row count to memorize

Define the row count to be memorized.

Columns to memorize

Select the columns to be memorized from the incoming data schema.

Advanced settings

tStatCatcher Statistics

Select this check box to gather the Job processing metadata at a Job level as
well as at each component level.

Global Variables

Global Variables

NB_LINE_ROWS: the number of rows memorized. This is an
After 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

This component can be used as intermediate step in a data flow or the last step
before beginning a subJob.

Note: You can use the global variable NB_LINE_ROWS to retrieve the value of the
Row count to memorize field of the tMemorizeRows component.

Connections

Outgoing links (from this component to another):

Row: Main

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

Incoming links (from one component to this one):

Row: Main;

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

Retrieving the different ages and lowest age data

This scenario displays the number of occurrences of different ages and the lowest age
within a group of customers. In this scenario, the customer data is entered manually.

You will see two ways to handle this data with the tMemorizeRows:

  • Inside the same subJob (with the tJavaFlex)

  • Outside the tMemorizeRows subJob (with the tJava)

tMemorizeRows_1.png

This Job uses five components:

  • tFixedFlowInput: it contains rows of customer data such
    as IDs, names and ages of the customers.

  • tSortRow: it sorts the rows according to the age
    data.

  • tMemorizeRows: it temporarily memorizes a specific
    number of incoming data rows at any given time and indexes the memorized data rows.

  • tJavaFlex: it compares the age values of the data
    memorized by the preceding component, counts the occurrences of different ages and displays
    these ages in the Run view.

  • tJava: it displays the number of occurrences of
    different ages and the lowest age.

To replicate this scenario, proceed as follows:

Dropping and linking the components

  1. Drop a tFixedFlowInput, a tSortRow, a tMemorizeRows, a tJavaFlex and a tJava component
    by typing their names in the design workspace or dropping them from the Palette.
  2. Connect the tFixedFlowInput component to the
    tSortRow component using a Row > Main connection.
  3. Do the same to link the tSortRow component to the
    tMemorizeRows component and the tMemorizeRows component to the tJavaFlex
    component.
  4. Connect the tFixedFlowInput component to the
    tJava component using the Trigger > OnSubjobOk connection.

Configuring the components

Configuring the tFixedFlowInput component

  1. Double-click the tFixedFlowInput component to open
    its Basic settings view on the Component tab.

    tMemorizeRows_2.png

  2. Click the […] button next to Edit schema to open the Schema dialog box
    and define the data structure of the input data.

    tMemorizeRows_3.png

  3. In this editor, click the [+] button three times to
    add three columns and name them id, name and age.
  4. In the Type column, select Integer for id and age.
  5. Click OK to close the editor, then click Yes to validate these changes and accept the propagation prompted
    by the dialog box that pops up.
  6. Select Use Inline Content (delimited file) in the
    Mode area.

    In the Content field, enter the following customer
    data:

Configuring the tSortRow component

  1. Double-click the tSortRow to open its Basic settings view on the Component tab.

    tMemorizeRows_4.png

  2. In the Criteria table, click the [+] button to add one row.
  3. In the Schema column column, select the data column
    on which the sorting operation is based. In this example, select age as it is the ages that should be compared and counted.
  4. In the sort num or alpha? column, select the type of
    sorting operation to perform. In this example, select num, which means numerical, as age contains
    integer data.
  5. In the Order asc or desc? column, select desc to display data on the console in descending order.

Configuring the tMemorizeRows component

  1. Double-click the tMemorizeRows component to open its
    Basic settings view on the Component tab.

    tMemorizeRows_5.png

  2. In the Row count to memorize field, type in the
    maximum number of rows to be memorized at any given time. As in this example you need to
    compare ages of two customers for each time, enter 2. This component
    memorizes two rows at maximum at any given moment and always indexes the new incoming row
    as 0 and the previous incoming row as 1.
  3. In the Memorize column of the Columns to memorize table, select the check box(es) to determine the
    column(s) to be memorized. In this example, select the check box corresponding to
    age.

Configuring the tJavaFlex and tJava components

  1. Double-click the tJavaFlex component to open its
    Basic settings view on the Component tab.

    tMemorizeRows_6.png

  2. In the Start code area, enter the Java code that will
    be called during the initialization phase. In this example, type in int
    count=0;
    in order to declare a variable count and assign the
    value 0 to it.
  3. In the Main code area, enter the Java code to be
    applied to each row in the data flow. In this scenario, type
    in:if(!age_tMemorizeRows_1[0].equals(age_tMemorizeRows_1[1]))
    {
    count++;
    }
    System.out.println(age_tMemorizeRows_1[0]);
    This
    code compares two ages memorized by the tMemorizeRows
    component each time and counts one change every time the ages are found to be different.
    This code then displays the age that has been indexed as 0 by the tMemorizeRows component. When the tJavaFlex
    component is in the same flow of the tMemorizeRows
    component, the variable format is ColumnName_ComponentName[index].
  4. In the End code area, enter the Java code that will
    be called during the closing phase. In this example, type in globalMap.put("number",
    count);
    to initialize the global variable number with the value of the count
    variable.
  5. Double-click the tJava component to open its
    Basic settings view on the Component tab.

    tMemorizeRows_7.png

  6. In the Code area, enter the flollowing code to
    display the number of occurrences of different ages and the lowest age within the
    customers on the
    console:System.out.println("Different ages:
    "+globalMap.get("number"));

    System.out.println("Lowest age: " + ((Integer[])globalMap.get("tMemorizeRows_1_age"))[0]);

    The method globalMap.get() is used by the tJava to retrieve the array values. Note that here, the tJava is used outside the subJob tMemorizeRows so the variable format should be
    ComponentName_ColumnName, which is different from the variable format used
    by a component placed in the same flow.

Saving and executing the Job

  1. Press Ctrl+S to save your Job.
  2. Press F6, or click Run on the Run console to execute the
    Job.

    tMemorizeRows_8.png

In the console, you can read that there are four different ages and that the lowest age is
27 within the group of customers.


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