Typorithm · medium

Joins

spark-joinsparkjoinbroadcastdistributed
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Joins

0%

Spark SQL

Join distributed tables on a key with JOIN ... ON; broadcast the smaller table with /*+ BROADCAST(c) */ to skip an expensive shuffle.

A join pairs rows from two distributed tables on a key, here orders to customers on customer_id = id.

By default Spark shuffles both sides across the network to colocate matching keys, which is costly for large tables.

When one side is small, a broadcast join ships that whole table to every executor — add a /*+ BROADCAST(c) */ hint to avoid the shuffle entirely.

01

JOIN ... ON pairs rows on a key.

02

Default joins shuffle both sides.

03

Broadcast a small table to skip the shuffle.

SELECT o.id, c.name FROM orders o JOIN customers c ON o.customer_id = c.id

Read the implementation

Connect each part of the code to the concept before you type.

1. Left table alias

orders o aliases the left, typically large, table as o for short references.

FROM orders o

2. Join the tables

JOIN customers c brings in the second table, aliased c, to combine matching rows.

JOIN customers c

3. Join key

ON defines the equality key that pairs each order with its customer.

ON o.customer_id = c.id

4. Qualified columns

Qualifying columns with the alias avoids ambiguity when both tables share a name.

SELECT o.id, c.name

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Joins: Lesson & Practice · Typorithm | ApplyDjinn