tAggregateRow - 6.3

Talend Open Studio for Big Data Components Reference Guide

EnrichVersion
6.3
EnrichProdName
Talend Open Studio for Big Data
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

Function

tAggregateRow receives a flow and aggregates it based on one or more columns. For each output line, are provided the aggregation key and the relevant result of set operations (min, max, sum...).

Purpose

Helps to provide a set of metrics based on values or calculations.

tAggregateRow properties

Component family

Processing

 

Basic settings

Schema and Edit Schema

A schema is a row description. It defines the number of fields (columns) to be processed and passed on to the next component. The schema is either Built-In or stored remotely 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.

 

 

Built-In: You create and store the schema 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. You can reuse it in various projects and Job designs. Related topic: see Talend Studio User Guide.

 

Group by

Define the aggregation sets, the values of which will be used for calculations.

 

 

Output Column: Select the column label in the list offered based on the schema structure you defined. You can add as many output columns as you wish to make more precise aggregations.

Ex: Select Country to calculate an average of values for each country of a list or select Country and Region if you want to compare one country's regions with another country' regions.

 

 

Input Column: Match the input column label with your output columns, in case the output label of the aggregation set needs to be different.

 

Operations

Select the type of operation along with the value to use for the calculation and the output field.

 

 

Output Column: Select the destination field in the list.

 

 

Function: Select the operator among: count, min, max, avg, sum, first, last, list, list(objects), count(distinct), standard deviation.

 

 

Input column: Select the input column from which the values are taken to be aggregated.

 

 

Ignore null values: Select the check boxes corresponding to the names of the columns for which you want the NULL value to be ignored.

Advanced settings

Delimiter(only for list operation)

Enter the delimiter you want to use to separate the different operations.

 

Use financial precision, this is the max precision for "sum" and "avg" operations, checked option heaps more memory and slower than unchecked.

Select this check box to use a financial precision. This is a max precision but consumes more memory and slows the processing.

Warning

We advise you to use the BigDecimal type for the output in order to obtain precise results.

 

Check type overflow (slower)

Checks the type of data to ensure that the Job doesn't crash.

 

Check ULP (Unit in the Last Place), ensure that a value will be incremented or decremented correctly, only float and double types. (slower)

Select this check box to ensure the most precise results possible for the Float and Double types.

 

tStatCatcher Statistics

Check this box to collect the log data at component level. Note that this check box is not available in the Map/Reduce version of the component.

Global Variables

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

This component handles flow of data therefore it requires input and output, hence is defined as an intermediary step. Usually the use of tAggregateRow is combined with the tSortRow component.

Log4j

If you are using a subscription-based version of the Studio, the activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User Guide.

For more information on the log4j logging levels, see the Apache documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html.

Limitation

n/a

Aggregating values and sorting data

This example shows you how to use Talend components to aggregate the students' comprehensive scores and then sort the aggregated scores based on the student names.

Creating a Job for aggregating and sorting data

Create a Job to aggregate the students' comprehensive scores using the tAggregateRow component, then sort the aggregated data using the tSortRow component, finally display the aggregated and sorted data on the console.

  1. Create a new Job and add a tFixedFlowInput component, a tAggregateRow component, a tSortRow component, and a tLogRow component by typing their names in the design workspace or dropping them from the Palette.

  2. Link the tFixedFlowInput component to the tAggregateRow component using a Row > Main connection.

  3. Do the same to link the tAggregateRow component to the tSortRow component, and the tSortRow component to the tLogRow component.

Configuring the Job for aggregating and sorting data

Configure the Job to aggregate the students' comprehensive scores using the tAggregateRow component and then sort the aggregated data using the tSortRow component.

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

  2. Click the button next to Edit schema to open the schema dialog box and define the schema by adding two columns, name of String type and score of Double type. When done, click OK to save the changes and close the schema dialog box.

  3. In the Mode area, select Use Inline Content (delimited file) and in the Content field displayed, enter the following input data:

    Peter;92
    James;93
    Thomas;91
    Peter;94
    James;96
    Thomas;95
    Peter;96
    James;92
    Thomas;98
    Peter;95
    James;96
    Thomas;93
    Peter;98
    James;97
    Thomas;95
  4. Double-click the tAggregateRow component to open its Basic settings view.

  5. Click the button next to Edit schema to open the schema dialog box and define the schema by adding five columns, name of String type, and sum, average, max, and min of Double type.

    When done, click OK to save the changes and close the schema dialog box.

  6. Add one row in the Group by table by clicking the button below it, and select name from both the Output column and Input column position column fields to group the input data by the name column.

  7. Add four rows in the Operations table and define the operations to be carried out. In this example, the operations are sum, average, max, and min. Then select score from all four Input column position column fields to aggregate the input data based on it.

  8. Double-click the tSortRow component to open its Basic settings view.

  9. Add one row in the Criteria table and specify the column based on which the sort operation is performed. In this example, it is the name column. Then select alpha from the sort num or alpha? column field and asc from the Order asc or desc? column field to sort the aggregated data in ascending alphabetical order.

  10. Double-click the tLogRow component to open its Basic settings view, and then select Table (print values in cells of a table) in the Mode area for better readability of the result.

Executing the Job to aggregate and sort data

After setting up the Job and configuring the components used in the Job for aggregating and sorting data, you can then execute the Job and verify the Job execution result.

  1. Press Ctrl + S to save the Job.

  2. Press F6 to execute the Job.

    As shown above, the students' comprehensive scores are aggregated and then sorted in ascending alphabetical order based on the student names.