tCombinedSQLAggregate
Provides a set of matrix based on values or calculations.
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.
tCombinedSQLAggregate Standard properties
These properties are used to configure tCombinedSQLAggregate running in the Standard Job framework.
The Standard
tCombinedSQLAggregate component belongs to the ELT family.
The component in this framework is available in all Talend
products.
Basic settings
Schema and Edit |
A schema is a row description, it defines the number of fields that will be processed Click Edit
Click Sync columns to retrieve |
 |
Built-in: You create and store |
 |
Repository: You have already |
Group by |
Define the aggregation sets, the values of which will be used for |
 |
Output Column: Select the column |
 |
Input Column: Select the input |
Operations |
Select the type of operation along with the value to use for the |
 |
Output Column: Select the |
 |
Function: Select any of the |
 |
Input column: Select the input |
Advanced settings
tStatCatcher Statistics |
Select this check box to gather the Job processing metadata at a |
Global Variables
Global Variables |
NB_LINE: the number of rows read by an input component or
QUERY: the query statement being processed. This is a Flow
ERROR_MESSAGE: the error message generated by the A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see |
Usage
Usage rule |
This component is an intermediary component. The use of the |
Filtering and aggregating table columns directly on the DBMS
The following scenario creates a Job that opens a connection to a MySQL database
and:
-
populates a database table with the input data,
-
creates the output table for the filtered data,
-
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.
Adding and linking the components
-
Drop the following components from the Palette onto the design workspace: tMysqlConnection, tFixedFlowInput, tMysqlOutput,
tCreateTable, tCombinedSQLInput, tCombinedSQLFilter, tCombinedSQLAggregate, tCombinedSQLOutput, tMysqlCommit, tMysqlInput and
tLogRow. -
Connect tMysqlConnection to tFixedFlowInput using a Trigger > On Subjob Ok link
-
Do the same to connect tFixedFlowInput to
tCreateTable, tCreateTable to tCombinedSQLInput, tCombinedSQLInput to tMysqlCommit, and tMysqlCommit
to tMysqlInput. - Connect tFixedFlowInput and tMysqlOutput using a Row > Main link.
- Connect tCombinedSQLInput to tCombinedSQLFilter using a Row > Combine link.
-
Do the same to connect tCombinedSQLFilter to
tCombinedSQLAggregate, and tCombinedSQLAggregate to tCombinedSQLOutput
-
Connect tMysqlInput and tLogRow using a Row >
Main link.
Configuring the components
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.
Opening a MySQL connection
-
Launch MySQL Workbench and start a local
connection on port 3306. - Create a new schema and name it test.
- Back 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.
Populating the database table with input data
-
In the design workspace, select tFixedFlowInput and click the Component tab to define its basic settings
-
In the Basic settings view, in the Number of rows field, enter
500
. -
In this scenario, the source database table has seven columns: id, first_name, last_name, city, state, date_of_birth,
and salary
Click the […] button next to Edit schema to define the following data
structure. -
Click the floppy disk icon to save the schema as a generic schema for later
reuse. - In the Select folder window, select default and click OK.
- Choose a name for your generic schema and click Finish.
- Click OK.
-
The first column of the Values table
automatically reflects the data structure you entered previously. -
In the Values table, enter a value for each
column. -
In the design workspace, select tMysqlOutput
and click the Component tab to define its basic
settings.The output schema will automatically be the same as the previous component, in
this case tFixedFlowInput.
Creating the target database table
-
In the design workspace, select tCreateTable
and click the Component tab to define its basic
settings. -
Click the […] button next to Edit schema to define the following data
structure.The schema you enter at this step must reflect the the differents aggregation
operations you want to perform on the input data.
Extracting and filtering data
-
In the design workspace, select tCombinedSQLInput and click the Component tab to access the configuration panel.
-
Enter the source table name, in this case employees in
the Table field. -
In the Schema field, select Repository from the list and click the […] button right to the empty field to load the
schema you saved.while configuring the settings for tFixedFlowInput. -
In the Repository Content window, expand
Generic schemas and select your
schema. - Click the […] button right to Edit schema.
-
Select View schema, and in the first column
of the table, clear the check boxes for first_name,
last_name and city.
Filtering and aggregating the input data
-
In the design workspace, select tCombinedSQLFilter 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 the […] button next to Edit
schema.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.Click two times on the [+] button under the
Conditions table, and in Input column, select state and
date_of_birth from the drop-down list.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. -
For the column state, select IN as operator from the drop-down list, and enter
(‘Utah’,’Ohia’,’Iowa’) as value. -
For the column date_of_birth, select > as operator from the drop-down list, and enter
(‘1960-10-19’) as value. -
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 on the […] button.next to Edit schema to enter the following configuration:
The tCombinedSQLAggregate component
instantiates four columns: id, state, date_of_birth, and
salary, coming from the previous component. -
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 in. Then
we want to 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 a 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.
Writing the output data into MySQL
-
In the design workspace, select tCombinedSQLOutput and click the Component tab to access the configuration panel.
-
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,
empl_by_state in this caseThe tCombinedSQLOutput component requires
that an output table already exists in the database to work. That is why the
empl_by_state table was created earlier in the
scenario.In this example, the Schema field doesn’t
need to be filled out as the database is not Oracle. -
Click the Sync columns button to retrieve the
schema from the previous component.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.
Committing the data into the database
- 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. - Clear the check box Close Connection.
Retrieving the filtered and aggregated data
-
In the design workspace, select tMysqlIntput
and click the Component tab to define its basic
settings. -
Select the check box Use an existing
connection ans choose tMysqlConnection_1 from the list. -
Click on the […] button.next to Edit schema to enter the following schema:
-
In the field Table Name, enter
empl_by_state and in the Query field, enter select * from
empl_by_state. -
In the design workspace, select tLogRow and
click the Component tab to define its basic
settings. -
Click the Sync columns button to retrieve the
schema from the previous component and select the Table
(print values in cells of a table) mode.
Saving and executing the Job
-
Save your Job and press F6 to execute
it. -
The Run tab opens, where you can observe the
result of the Job execution. -
The output data retrieved by the tLogRow is
visible in a table.
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.