Aggregate

Available in Community Designer

Short Description
Ports
Metadata
Aggregate Attributes
Details
Examples
See also

Short Description

Aggregate computes statistical information about input data records.

Component Same input metadata Sorted inputs Inputs Outputs Java CTL Auto-propagated metadata
Aggregate-
no
11-n
no
no
no

Icon

Ports

Port typeNumberRequiredDescriptionMetadata
Input0
yes
For input data recordsAny1
Output0-n
yes
For statistical informationAny2

This component has one input port and one or more output ports.

Metadata

Aggregate does not propagate metadata.

Aggregate has no metadata template.

Metadata on the output ports must be same.

Aggregate Attributes

AttributeReqDescriptionPossible values
Basic
Aggregate key  Key according to which the records are grouped. See Group Key for more information. E.g. first_name;
Aggregation mapping Sequence of individual mappings for output field names separated from each other by semicolon. Each mapping can have the following form: $outputField:=constant or $outputField:=$inputField (this must be a field name from the Aggregate key) or $outputField:=somefunction($inputField). Semicolon after the last mapping is optional and may be omitted.  
Charset Encoding of incoming data records.UTF-8 | other encoding
Sorted input By default, input data records are supposed to be sorted according to Aggregate key. If they are not sorted as specified, switch this value to false. true (default) | false
Equal NULL By default, records with null values are considered to be different. If set to true, records with null values are considered to be equal. false (default) | true
Deprecated
Old aggregation mapping Mapping that was used in older versions of CloverETL, its use is deprecated now. 

Details

Aggregate receives data records through single input port, computes statistical information about input data records and sends them to all output ports.

Aggregation Mapping

Aggregate mapping requires metadata on input and output edges of the component. Assign metadata to the component input and output first. Only then you can create the transformation.

Define Aggregate key. The key field is necessary for grouping.

Click the Aggregation mapping attribute row to open Aggregation mapping dialog. In it, you can define both the mapping and the aggregation.

The dialog consists of two panes. You can see the Input field pane on the left and the Aggregation mapping pane on the right.

  1. Each Aggregate key field can be mapped to the output. Drag the input field and drop it to the Mapping column in the right pane at the row of the desired output field name. After that, the selected input field appears in the Mapping column.

    The following mapping can only be done for key fields: $outField=$keyField.

  2. Fields that are not part of Aggregate key can be used in aggregation functions and the result of the aggregation function is mapped to the output.

    To define a function for a field (contained in the key or not-contained in it), click the row in the Function column and select a function from the combo list. After you select the desired function, click Enter.

    Aggregation function count() has no parameter, therefore it requires no input field.

  3. For each output field, a constant may also be assigned to it.

    $outputField:="Clover"

Aggregate Functions

Table 55.2. List of Aggregate Functions

Function nameDescriptionInput data typeOutput data typeInput can be list
avg Returns average value of numbers. Null values are ignored. If all aggregated values are null, returns null. numeric data typenumeric data typeno
countCount records, null values are counted as well as other values.-numeric data typeyes
countnotnullCounts records, if the field contains null, it is not counted in.anynumeric data typeyes
countuniqueCounts unique values. null is unique value. The function assumes 1, 2, 2, 2, null, 1, null as 3 unique values.anynumeric data typeyes
crc32Calculates crc32 checksum. crc of null is null.anylongno
firstReturns the first value of group. If the first value is null, returns null.anyanyyes
firstnotnullReturns first value, which is not null. If all received values were null, returns null.anyanyyes
lastReturns last value of the group. If last value is null, returns null. anyanyyes
lastnotnullReturns last not-null value. If all values are null, returns null. anyanyyes
maxReturns maximum value. If all values are null returns null.numeric data typenumeric data typeyes
md5

If group contains one record, returns base64-encoded md5 checksum. If group contains more records, the particular input records are concatenated together before the calculation of md5 checksum.

If input is string, it is converted to sequence of bytes using encoding set up in the component first. If input is integer or long, it is printed to the string first. If input is null, returns null. Use md5sum instead of md5.

anystringno
md5sumIf group contains one record, return md5sum of the field. If group contains more records, the field values are concatenated first. If input is null, returns null.bytestringno
medianReturns median value. Null values are not counted in. If all input values are null, returns null.numeric data typenumeric data typeno
minReturns minimum value. If all input values are null, returns null.numeric data typenumeric data typeyes
modusReturns most frequently used value (null values are not counted in). If there are more candidates, the first one is returned. If all input values are null, returns null.anyanyyes
sha1sumIf group contains one record, returns sha1sum of the field. If group contains more records, the field values are concatenated first. If input field is null, returns null.bytestringno
sha256sumIf input group contains one record, returns sha256sum of the field. If group contains more records, the field values are concatenated first. If all input values are null, returns null.bytestringno
stddevReturns standard deviation. Null values are not counted in. If all input values are null, returns null.numeric data typenumeric data typeno
sumReturns sum of input values. If all input values are null, returns null. numeric data typenumeric data typenol

You can calculate md5sum, sha1sum and sha256sum checksums incrementally: the group of records corresponds to the whole file whereas particular records contain blocks of the file.

For example there are 3 records grouped together by value in field f1. The field f2 contains particular blocks: a, b and c (as bytes). Each value is in the different record. The sha1sum applied on field f2 returns sha1sum("abc").

Examples

Basic Usage

Input metadata contains fields Weight and ProductType.

Output fields are: ProductType, Count, TotalWeight, AverageWeight, and Date. Output metadata can also have other fields.

Aggregate records of same ProductType. Set Date to 2015-08-20.

Solution

Set Aggregate key to ProductType.

Set Aggregate mapping:

  • Map ProductType to ProductType.

  • Use count() aggregation function to count records with same key.

  • Use sum() and avg() functions to calculate total and average weight of grouped items. Both functions require input field as an argument. Drag input field weight to Mapping column.

  • Set Mapping field of Date to 2015-08-20.

The Aggregate mapping is $ProductType:=$ProductType;$Count:=count();$TotalWeight:=sum($weight);$AverageWeight:=avg($weight);Date:=2015-08-20;.

See also

Common Properties of Components
Specific Attribute Types
Common Properties of Transformers
Transformers Comparison