Talend Aggregate Sorted row(tAggregateSortedRow)字段与tAggregateRow相同。然而,它对已排序的数据执行聚合并返回输出。如果我们知道源数据已排序,就可以使用此 Aggregate Sorted Row 字段。由于 Talend tAggregateSortedRow 不维护任何缓冲区,因此它比 tAggregateRow 快。
在此 Talend Aggregate sorted row 示例中,我们使用了与 Aggregate row 示例中相同的 Customer 表。下面的屏幕截图显示了该表中的数据。

Talend Aggregate Sorted Row 示例
首先,拖放 DBInput 并从元数据中选择 Customers 表。有关连接设置,请参阅 tAggregateRow 文章。

接下来,将 Talend tAggregateSortedRow 从组件面板拖到作业设计中。通过选择该字段,您可以看到定义 tAggregateSortedRow 的工具提示。

请将 DBInput 的主行连接到 Talend tAggregateSortedRow。我们已经在之前的 示例 中解释了所有选项。除这些之外,组件选项卡中还有一个名为 Input rows count 的字段。在这里,您需要指定来自输入的总行数。
接下来,单击 Edit Schema 按钮将必需的列添加到 tAggregateSortedRow。在这里,我们添加了 Occupation、Yearly Income 和 Sales 列。

对于 Input rows 的数量,您可以手动输入数字或从大纲中选择 Number of lines (NB_Line)。在这里,我们不小心添加了 tAggregateSortedRow 的 NB_LINE,但您应该添加 DBInput 的 NB_LINE。我们之后更改了它,但忘记截图了。
请使用加号按钮添加分组依据列。在这里,我们添加了 Occupation 列用于分组。接下来,我们在 Operations 部分添加了 Yearly Income 和 Sales,并选择了 Sum 函数。
这意味着我们正在按职业对客户进行分组,并找到年收入和销售额的总和。

在这里,我们使用 DBOutput 将 Talend Aggregate Sorted Row 的输出保存在 SQL 数据库中。在这里,我们将 Talend_tAggSortedRow 表创建为目标表。

让我们运行 Talend Aggregate Sorted Row 作业。

让我打开 Management studio 来检查 tAggregateSortedRow 的结果。为了比较结果,我们还对 Customer 表编写了一个 T-SQL 查询。从下面的屏幕截图可以看出,两者返回的结果不同。这是因为 Talend tAggregateSortedRow 假设数据已排序。

让我们对数据进行排序并运行此 Talend Aggregate Sorted Row。为此,让我将 tSortRow 字段拖放到中间。
在这里,我们使用 tSortRow 字段按职业升序对数据进行排序。

接下来,我们将此 tSortRow 与 Talend tAggregateSortedRow 连接起来,将其余设置保持不变,然后运行了作业。

请检查 Talend aggregate sorted row 的结果。

这次,我们使用排序后的数据作为 DBInput 源数据。在此示例中,我们将输入表从 Customers 更改为 Talend_Sorted_Customers。这是我们从 Talend Sort Data 文章获得的输出表。

请保持 Grouping 和 aggregate functions 如上或如图所示。让我们运行此 Aggregate Sorted Row 作业。
Talend tAggregateSortedRow 作业的结果是
