Solve “Broadcast Join”

Free. Runs in your browser, no install.

PySpark · Joins & Performance

PySpark join types (incl left anti/semi)

Hardjoinsleft-antileft-semisql

Interview question

What join types does PySpark support, including left anti and left semi?

How to answer

The short answer

PySpark joins mirror . You specify the condition and a how type.

Common types

Output
inner       matching keys only
left / left_outer
right / right_outer
full / full_outer
left_semi   left rows with a match on right (no right columns)
left_anti   left rows with NO match on right
cross       cartesian product (use carefully)
Python
# Inner / left
orders.join(customers, "customer_id", "inner")
orders.join(customers, "customer_id", "left")

# Existence checks without blowing up columns
# Customers who placed at least one order
customers.join(orders, "customer_id", "left_semi")

# Customers with no orders
customers.join(orders, "customer_id", "left_anti")

Diagram

Output
Left Anti (A anti B):
  A rows whose key does not appear in B

Left Semi (A semi B):
  A rows whose key appears in B (A columns only)

Why semi/anti beat some patterns

Python
# Often worse: join then filter / distinct on right columns
# Better: left_semi / left_anti for membership tests

Interview tip

Call out duplicate key blow-ups on inner/left joins, null-safe join keys (eqNullSafe), and broadcast hints for small dimensions.

Lock it in with a real drill

You remember an answer longer once you have used it. Try a hands-on problem on this concept.

Open related drill