Talend tMap 连接

在我们之前的 tJoin 示例中,我们解释了 Join。在此示例中,我们使用 Talend tMap 字段执行 Join。 

为了使这个 Talend tMap Joins 文章更有趣,我们使用相同的 SQL 源数据。在这里,我们使用 tMap 字段连接两个 SQL 表并执行 Inner Join 和 Left Join。下图显示了 DupEmployees 表数据。

Department 表数据是

Talend tMap 连接示例。

在此 tMap 连接示例中,拖放 DBConnection 和 tDBCommit 以建立到 SQL 的连接并关闭它。接下来,我们使用 tDBInput 从 Talend 存储库中选择 DupEmployees 表。

接下来,我们使用另一个 tDBInput 从存储库中选择 Department 表。

因此,我们得到了两个表。接下来,拖放 Talend tMap 字段。请将 DupEmployee 主行连接到 tMap。接下来,将 Department 查找行连接到 tMap。

Editor in Component Tab of Talend tMap to perform Joins

接下来,请单击 Map Editor 按钮或双击 tMap 字段。它将打开以下窗口。我们已经在 tMap 文章中解释了所有字段,请参考相同的文章。

首先,我们必须使用键列在两个表(即 row1 和 row2)之间创建连接。所以,将 row1 中的 DeptID 拖放到 row2 中的 DeptID 旁边。

Mark the Key Column

现在,您可以看到 DeptID 列旁边有一个小键和 row1.DepID,即表达式键。这意味着我们指定了两个表中的公共键列。

接下来,单击 + 按钮将打开一个新弹出窗口来添加输出。让我创建一个新的输出并将其命名为 JoinsOutput。

Add the Output Name

它将添加输出字段。请将 row1 和 row2 中的必需字段拖放到 JoinsOutput 部分。

Talend tMap to perform Joins 11

请单击小的 Talend tMap 设置按钮来打开或展开隐藏列以检查 Join Model。从下面的屏幕截图可以看出,它已将 Left Outer Join 选为默认的 Join Model。我将保持原样,然后单击 Apply 和 OK 按钮。

Check the Model of the Talend tMap to perform Joins

在此 tMap 连接示例中,我们将输出保存在 SQL 数据库中。所以,拖放 DBOutput 并选择 SQL Server 作为服务器类型。

右键单击 tMap 允许您选择已创建的输出或创建新的输出(主)。让我选择我们之前创建的 JoinsOutput,并将其连接到 tDBOutput。

Set the Output

正如您从下面看到的,我们正在创建一个新的 Talend_tMap_Joins(如果不存在)表作为目标表。

Configure the output table name

让我们运行 tMap 连接作业。

Run the Talend tMap Job to perform Joins

让我打开 Management studio 来检查 Talend tMap Left Outer Join 的结果。

Result Table

请打开 tMap 编辑器以添加另一个用于被拒绝行的输出,并将 row1 和 row2 中的所有列添加到 RejectedRows 部分。

接下来,单击小的设置按钮来打开或展开隐藏字段。正如您所看到的,默认情况下,tMap 没有捕获被拒绝的行,或者没有捕获查找内部连接的行。

Caching the rejected rows in tMap to perform Joins

请将这两个选项都更改为 True 以捕获 Inner Join 的被拒绝行。接下来,请使用浏览按钮将 Talend Join Model 从 Left Outer Join 更改为 Inner Join。

Talend tMap to perform Inner Join

检查所有 Talend tMap Join 属性,然后单击 Apply 和 OK 按钮。

这次,当您右键单击 tMap 时,您可以看到我们现在创建的新输出,即 RejectedRows。请选择它并将其连接到 tLogRow,然后选择 Table preview。

Set the Rejected Rows

让我运行这个 Talend tMap inner join 作业。在这里,您可以看到那四个 inner join 被拒绝的行。

Run the tMap Job to perform Inner Join

tMap Inner join 的结果是

Destinnation Table