SELECT c.country, SUM(o.amount) AS revenue
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id
WHERE o.order_date >= DATE'2025-01-01' AND 1 = 1
GROUP BY c.country1 = 1 to true, then drops AND true.order_date filter below the join, next to the orders scan.isnotnull(customer_id) on both join sides and isnotnull(order_date).customer_id, amount, order_date / customer_id, country.| scan | ReadSchema | PushedFilters |
|---|---|---|
| orders | order_id, customer_id, product_id, qty, amount, order_date, status | — |
| customers | customer_id, name, country, signup_date, tier | — |
== Optimized Logical Plan ==Aggregate [country#17], [country#17, sum(amount#12) AS revenue#26]+- Filter ((order_date#13 >= 2025-01-01) AND (1 = 1)) +- Join Inner, (customer_id#9L = customer_id#15L) :- Relation spark_catalog.default.orders[order_id#8L,customer_id#9L,product_id#10L,qty#11,amount#12,order_date#13,status#14] parquet +- Relation spark_catalog.default.customers[customer_id#15L,name#16,country#17,signup_date#18,tier#19] parquet# Spark runs all of these by default; the lab starts with them off
spark.conf.set(
"spark.sql.optimizer.excludedRules",
",".join([
"org.apache.spark.sql.catalyst.optimizer.ConstantFolding",
"org.apache.spark.sql.catalyst.optimizer.BooleanSimplification",
"org.apache.spark.sql.catalyst.optimizer.PushDownPredicates",
"org.apache.spark.sql.catalyst.optimizer.InferFiltersFromConstraints",
"org.apache.spark.sql.catalyst.optimizer.ColumnPruning",
]),
)
spark.conf.set("spark.sql.parquet.filterPushdown", "false")
revenue.explain(mode="extended") # or spark.sql(q).explain(True)