Talend获取给定键的每个实例的最新行

时间:2016-05-04 14:27:43

标签: talend

我们有两个数据源需要合并为一个。我们需要保留最新的行。来源具有相同的列。关键是机器专栏。

输入:

tFileInputDelimited A
+---------+------+-------------------+
| Machine | Desc | LastScanTimestamp |
+---------+------+-------------------+
| M01     | AA   |                25 |
| M02     | AB   |                23 |
| M03     | AC   |                28 |
+---------+------+-------------------+

tFileInputDelimited B
+---------+------+-------------------+
| Machine | Desc | LastScanTimestamp |
+---------+------+-------------------+
| M02     | BB   |                25 |
| M03     | BC   |                27 |
| M04     | BD   |                26 |
+---------+------+-------------------+

想要输出:

+---------+------+-------------------+
| Machine | Desc | LastScanTimestamp |
+---------+------+-------------------+
| M01     | AA   |                25 |
| M02     | BB   |                25 |
| M03     | AC   |                28 |
| M04     | BD   |                26 |
+---------+------+-------------------+

我们的问题类似于这个SQL问题: SQL query to get most recent row for each instance of a given key

我们无法使用SQL查询来执行此操作。我们用tUnite,tAggregateRow和tMap找到了一种方法。这不是很优雅和可维护。

非常感谢。

1 个答案:

答案 0 :(得分:0)

我在Talend论坛上发现了一个问题:https://www.talendforge.org/forum/viewtopic.php?id=49655

tInputFileDelimited--->tUnite--->tSortRow--->tUniqRow--->tLogRow
                     /                           
tInputFileDelimited-/

tSortRow:按LastScanTimestamp desc

排序

tUniqRow:Key = Machine

相关问题