Talend 过滤行

Talend 过滤行(tFilterRow)组件会根据给定的表达式过滤或限制输入行,并返回输出。我们可以使用此过滤行组件来获取高于特定值的销售额,或返回特定城市、州或国家的记录等。

在此 Talend 过滤行示例中,我们使用了 SQL Server 数据库中的 Customers 表。下图显示了该表中的数据。

Customer Sales Table with HireDate

Talend 过滤行示例

首先,拖放 DBConnection、DBCommit 和 DBInput 组件以建立与 SQL Server 的连接。接下来,我们从元数据中选择了 Customers 表。

Configure Server Connection and write table Select query

接下来,将 Talend tFilterRow 组件从调色板拖放到作业设计中。从下面的工具提示可以看出,tFilterRow 通过评估列条件来过滤输入行。

请将 DBInput 的主输出行连接到 tFilterRow。通常,输入列会与 tFilterRow 同步。如果不是这种情况,请单击“同步列”按钮。

Talend Filter Rows 4

接下来,单击“编辑模式”按钮以根据您的要求检查或修改 tFilterRow 的模式。

Edit Schema

在“组件”选项卡中,有两种执行过滤的方法。一种是“逻辑运算符”,它有两个选项。默认情况下,选择“And”,但您可以将其更改为“Logical Or”。如果我们只选择一列,则此选项没有作用。但是,如果我们选择两列,则输出行必须同时满足这两个条件。

第二个是“条件”部分——这是我们选择列并执行操作的地方。

目前,我们保留了默认的逻辑“And”,然后单击“添加”(加号)按钮。默认情况下,它会添加 Customers 表中的第一列,即 EmpID。请使用下拉框选择所需的列,在这里,我们选择了 Occupation。

Talend Filter Rows Logical Operator and the Conditional Column

在“运算符”下,我们有以下选项,例如 Equals(等于)、Not Equal to(不等于)、Greater than(大于)、Lower than(小于)、Greater or Equal to(大于等于)、Lower or equal to(小于等于)。我认为不必解释这些选项,因为您知道它们的作用!

为了演示 Talend 过滤行,我们选择了“不等于”运算符,值为“Skilled Manual”。这意味着 Talend tFilterRow 必须返回所有职业不等于“Skilled Manual”的客户。

Talend Filter Rows based on the given condition

接下来,我们使用 DBOutput 将 Talend tFilterRow 的输出保存到 SQL 数据库中。在这里,我们将 Talend_FilterRow 表创建为目标表。

Configure DBOutput

让我们运行 Talend 过滤行作业。

Run Talend tFilterRow Job to Filter Rows

我将打开 Management studio 来检查结果。请记住,Talend tFilterRow 与 SQL Where Clause 相同。

Not Equal to result Table

这次,我们使用两个字段并运行作业。这意味着 Talend tFilterRow 必须返回所有职业不等于“Skilled Manual”且年收入大于 50000 的客户。

Talend Filter Rows using multiple conditional columns

请检查 Talend 过滤行的结果。

Greater Than Condition result Table

tFilterRow 组件选项卡有一个高级选项。使用此选项可以编写自定义 Java 代码来执行过滤。

Advanced Mode to write Java code

我将“逻辑运算符”从“And”更改为“Or”。这意味着过滤行返回职业等于“Management”或年收入大于等于 60000 的客户。

Talend Filter Rows using Logical Or operator

请检查 Talend tFilterRow 的结果。

Logical Operator in Advanced options result Table