Multi-table join

Updated at:

This topic describes how to use the Multi-table Join operator and its usage considerations.

Purpose

The Multi-table Join operator joins multiple data tables based on specified join conditions. It is an advanced version of a two-table join operator and supports various join types across multiple data tables.

Scenarios

Compute Link

Compute engine

Supported

Offline

MaxCompute

Yes

Hive

Yes

HiveStorage

Yes

RDS/MySQL

Yes

Spark

Yes

Instructions

Source nodes

The Multi-table Join operator requires two or more source nodes, also known as input nodes. Each source node is treated as a table. The operator then joins the data from these source nodes.

Primary table

The primary table in the Multi-table Join operator is one of the input nodes. It serves as the base table for joining with other nodes. By default, the system designates the first input node as the primary table. You can set any other node as the primary table.

Important

If you reassign the primary table after configuring join conditions, the existing conditions are deleted.

Connection type

The Multi-table Join operator supports five types of table joins: left outer join, right outer join, full outer join, inner join, and cross join. You can use different join types for different table pairs. For example, you can use an inner join between the primary table (node A) and node B, and a left join between the primary table (node A) and node C.

The five join types are defined as follows:

Left join: Returns all records from the left table and the matched records from the right table.

image

Right join: Returns all records from the right table and the matched records from the left table.

image

Full outer join: Returns all records from both the left and right tables. Matched records are combined into a single row.

image

Inner join: Returns records that have matching values in both tables.

image

Cross join: If no join condition is specified, it returns the Cartesian product of the two tables. The number of rows in the result is the number of rows in the left table multiplied by the number of rows in the right table. If a join condition is specified, it returns matched records from both tables, which is the same result as an inner join.

image

Note

1. Join conditions are required for all join types except cross join.

2. RDS/MySQL does not support full outer joins.

3. MaxCompute (ODPS) does not support Cartesian products, which are cross joins without a condition. To perform a Cartesian product, you can enable MapJoin in the operator node configuration and specify the small tables.

Warning

Performing a Cartesian product, which is a cross join without a condition, on large data tables can cause data bloat. This leads to a massive result set, increases node execution duration, and consumes significant storage space.

Join conditions

Join conditions specify which fields to use for joining two data tables. A record from one table is joined with a record from another table if the values in the specified join fields are identical. The Multi-table Join operator lets you specify different join conditions for different table pairs. For example, you can specify the condition "A.ID=B.ID" between the primary table (node A) and node B, and the condition "A.NAME=C.NAME" between the primary table (node A) and node C.

Enable MapJoin

When joining a large table with one or more small tables, you can enable MapJoin and explicitly specify the small tables to improve performance.

Note

The MapJoin feature is supported only by the MaxCompute (ODPS) engine. It has no effect on other engines.

Output fields

You can configure the list of fields that the current node outputs to descendant nodes. By default, all fields from all source nodes are included. You can remove fields as needed. If different source nodes have fields with the same name or code, you must manually rename the duplicate fields.