- Talend Open Studio Cookbook
- Rick Barton
- 273字
- 2025-03-31 04:05:00
Hierarchical joins using tMap
The previous recipe covered the basics of tMap
joining, but tMap
has another level of joining capability, in that it can join together data in a hierarchical fashion. This simple example shows how easily this can be achieved using tMap
.
Getting ready
Open the job jo_cook_ch04_0080_hierarchicaltMapJoin
.
How to do it...
- Open the
tMap
component. You will see three input tables. - Select customerId from the
customer
table and drag it into Expr. key of thecustomerId
in the order table. - You will see that a join link, a purple key symbol has been added to the column.
- Change the tMap settings for the
order
table to Inner Join and All Matches (see previous recipe if you are not sure how to do this) - Now, select
orderId
from theorder
table and drag it toorderId
in theorderItem
table. - Change the tMap settings for the
orderItem
table to Inner Join and All Matches. ExittMap
and run the job. - You should see a printed table containing denormalized customer/order/orderitem rows.
How it works…
This job works on the hierarchy that exists between customer, order, and order item. A customer has many orders and an order has many order items.
The key for orders is customer, and the key for order items is order. Thus, to get all the order items for a customer, it is necessary to first find the keys for all the orders, and then find all the order items that match the order keys.
As you can see. tMap
allows this relationship to be defined easily simply by dragging the relevant parent key to the child structure.