August 17, 2023

tCombinedSQLAggregate – Docs for ESB 5.x

tCombinedSQLAggregate

tCombinedSQLAggregate_icon32_white.png

tCombinedSQLAggregate properties

Component family

ELT/CombinedSQL

 

Function

tCombinedSQLAggregate collects
data values from one or more columns of a table for statistical
purposes. This component has real-time capabilities since it runs
the data transformation on the DBMS itself.

Purpose

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

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.

Since version 5.6, both the Built-In mode and the Repository mode are
available in any of the Talend solutions.

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: 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 Jobs. 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 according to the schema structure you
defined. You can add as many output columns as you wish to make more
precise aggregations.

 

 

Input Column: Select the input
column label to match the output column’s expected content, 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 any of the
following operations to perform on data: count, min,
max, avg, sum, first, last, distinct and
count
(distinct)
.

 

 

Input column: Select the input
column from which you want to collect the values to be
aggregated.

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

NB_LINE: the number of rows read by an input component or
transferred to an output component. This is a Flow variable and it returns an
integer.

QUERY: the SQL query statement being processed. This is a
Flow variable and it returns a string.

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 is an intermediary component. The use of the
corresponding connection and commit components is recommended when
using this component to allow a unique connection to be open and
then closed during the Job execution.

Limitation

n/a

Scenario: Filtering and aggregating table columns directly on the DBMS

The following scenario creates a Job that opens a connection to a MySQL database
and:

  • instantiates the schema from a database table in part (for column
    filtering),

  • filters two columns in the same table to get only the data that meets two
    filtering conditions,

  • collects data from the filtered column(s), grouped by specific value(s) and
    writes aggregated data in a target database table.

To filter and aggregate database table columns:

  • Drop the following components from the Palette onto the design workspace: tMysqlConnection, tCombinedSQLInput, tCombinedSQLFilter, tCombinedSQLAggregate, tCombinedSQLOutput and tMysqlCommit.

  • Connect tMysqlConnection, tCombinedSQLInput and tMysqlCommit using OnSubjobOk
    links.

  • Connect tCombinedSQLInput, tCombinedSQLFilter, tCombinedSQLAggregate and tCombinedSQLOutput using a Combine link.

Use_Case_tCombinedSQLAggregate_1.png
  • In the design workspace, select tMysqlConnection and click the Component tab to define its basic settings.

  • In the Basic settings view, set the database
    connection details manually or select Repository from the Property Type list and select your DB connection if it has
    already been defined and stored in the Metadata area of the Repository tree view
    .

For more information on centralizing DB connection details in
the Repository, see Talend Studio User
Guide
.

Use_Case_tCombinedSQLAggregate_2.png
  • In the design workspace, select tCombinedSQLInput and click the Component tab to access the configuration panel.

Use_Case_tCombinedSQLAggregate_3.png
  • Enter the source table name in the Table
    field, and click the three-dot button next to Edit
    schema
    to define the data structure.

Note

The schema defined through tCombinedSQLInput can
be different from that of the source table as you can just instantiate the desired
columns of the source table. Therefore, tCombinedSQLInput also plays a role of column filtering.

In this scenario, the source database table has seven columns: id,
first_name, last_name, city, state, date_of_birth,
and
salary while tCombinedSQLInput
only instantiates four columns that are needed for the aggregation: id, state,
date_of_birth,
and salary from the source
table.

Use_Case_tCombinedSQLAggregate_8.png
  • In the design workspace, select tCombinedSQLFilter and click the Component tab to access the configuration panel.

Use_Case_tCombinedSQLAggregate_4.png
  • Click the Sync columns button to retrieve the
    schema from the previous component, or configure the schema manually by
    selecting Built-in from the Schema list and clicking the […] button next to Edit
    schema
    .

Note

When you define the data structure for tCombinedSQLFilter, column names automatically appear in the
Input column list in the Conditions table.

In this scenario, the tCombinedSQLFilter component
instantiates four columns: id, state, date_of_birth, and
salary.

  • In the Conditions table, set input
    parameters, operators and expected values in order to only extract the records
    that fulfill these criteria.

In this scenario, the tCombinedSQLFilter component
filters the state and date_of_birth columns in
the source table to extract the employees who were born after Oct. 19, 1960 and who live
in the states Utah, Ohio and
Iowa.

  • Select And in the Logical operator between conditions list to apply the two
    conditions at the same time. You can also customize the conditions by selecting
    the Use custom SQL box and editing the
    conditions in the code box.

  • In the design workspace, select tCombinedSQLAggregate and click the Component tab to access the configuration panel.

  • Click the Sync columns button to retrieve the
    schema from the previous component, or configure the schema manually by
    selecting Built-in from the Schema list and clicking on the […] button.

The tCombinedSQLAggregate component instantiates four
columns: id, state, date_of_birth, and salary,
coming from the previous component.

Use_Case_tCombinedSQLAggregate_5.png

The Group by table helps you define the data sets to
be processed based on a defined column. In this example:
State.

  • In the Group by table, click the [+] button to add one line.

  • In the Output column drop-down list, select
    State. This column will be used to hold the data
    filtered on State.

The Operations table helps you define the type of
aggregation operations to be performed. The Output
column
list available depends on the schema you want to output (through
the tCombinedSQLOutput component). In this scenario, we
want to group employees based on the state they live. We want then count the number of
employees per state, calculate the average/lowest/highest salaries as well as the
oldest/youngest employees for each state.

  • In the Operations table, click the [+] button to add one line and then click in the
    Output column list to select the output
    column that will hold the computed data.

  • In the Function field, select the relevant
    operation to be carried out.

  • In the design workspace, select tCombinedSQLOutput and click the Component tab to access the configuration panel.

Use_Case_tCombinedSQLAggregate_6.png
  • On the Database type list, select the
    relevant database.

  • On the Component list, select the relevant
    database connection component if more than one connection is used.

  • In the Table field, enter the name of the
    target table which will store the results of the aggregation operations.

Note

In this example, the Schema field doesn’t need to
be filled out as the database is not Oracle.

  • Click the three-dot button next to Edit
    schema
    to define the data structure of the target table.

In this scenario, tCombinedSQLOutput instantiates
seven columns coming from the previous component in the Job design (tCombinedSQLAggregate): state, empl_count,
avg_salary, min_salary, max_salary, oldest_empl
and
youngest_empl.

  • In the design workspace, select tCombinedSQLCommit and click the Component tab to access the configuration panel.

  • On the Component list, select the relevant
    database connection component if more than one connection is used.

  • Save your Job and press F6 to execute
    it.

Rows are inserted into a seven-column table empl_by_state in the
database. The table shows, per defined state, the number of employees, the average
salary, the lowest and highest salaries as well as the oldest and youngest
employees.

Use_Case_tCombinedSQLAggregate_7.png

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