On by Default Since Spark 3.2
Concepts covered: Adaptive Query Execution
AQE in its current form shipped in Spark 3.0, released in June 2020, and it shipped switched off. It stayed off by default through 3.1. Spark 3.2.0, released in October 2021, changed the default to on. From that release forward, DataFrame and SQL queries on a cluster with default settings run adaptively, with no change to the code that defines them.
| Spark version | Adaptive execution | Default |
|---|---|---|
| Before 3.0 | A narrower predecessor | Off |
| 3.0 and 3.1 | AQE as taught here | Off |
| 3.2 and later | AQE as taught here | On |
One flag, and how to read it
The switch is a single setting, spark.sql.adaptive.enabled. The default describes a fresh cluster. It says nothing certain about the cluster in front of you, where a platform team, a launch script or a line in an old notebook may have set the flag either way. The reliable habit is to ask the running session.
print(spark.version)
print(spark.conf.get("spark.sql.adaptive.enabled"))spark.conf.get reports the value in effect for this session after every layer of configuration has been applied: the cluster's defaults, the settings passed when the application was launched, and anything the session's own code has set. That makes it the one check that behaves the same on a laptop, in a shared notebook and on a production cluster.
The answer comes back as text
The call returns the text true or false, as a Python string. Python treats every non-empty string as truthy, so a bare if on the result passes even when AQE is off. Compare against the string when a script needs to branch on it.
aqe_on = spark.conf.get("spark.sql.adaptive.enabled") == "true"
print(aqe_on)Queries the default covers
Is this query adaptive on a default 3.2+ cluster?
- DataFrame and SQL queries with a shuffle: They pass through the optimizer, which is where the re-planning happens.
- RDD code: An RDD pipeline bypasses the optimizer, so Spark holds no plan it could rewrite.
- Queries built only from narrow transformations: With no shuffle there is no pause, and nothing gets measured.
- The same code on Spark 3.0 or 3.1: The feature is present and waits for someone to set the flag to true.
The flag is a session setting, so it can change while an application runs. spark.conf.set("spark.sql.adaptive.enabled", "false") turns it off for the queries that follow in that session, and setting it to "true" turns it back on. At this stage the one good use for the off position is comparison: run a query both ways and see what the measurements changed. Otherwise leave it on.
When the 5-second check is worth running
2 situations make the check worth doing every time. One is inheriting a job. A pipeline written for Spark 2.4 and migrated forward may carry an explicit false that someone added during the move, and nobody has revisited it since. The other is benchmarking. A timing comparison between 2 clusters means little if one runs adaptively and the other follows a fixed plan.
A notebook on a Spark 3.4 cluster runs this cell, and it prints AQE is on. A teammate says the output proves AQE is enabled. Is the teammate right?
if spark.conf.get("spark.sql.adaptive.enabled"):
print("AQE is on")- Yes. Spark 3.4 is later than 3.2, so the flag is always true there and the cell only confirms it.
- No. The call returns the string true or false, and both are truthy in Python, so the message prints either way.
- Yes. spark.conf.get returns a Python boolean, so the branch runs only when AQE is switched on.
- No. spark.conf.get reads the cluster default and ignores any value set inside the current session.
On by default means you will rarely switch AQE on yourself. It also means the plan a query finishes with can differ from the plan it started with, on any modern cluster, without anyone asking for it. Seeing that difference is the next skill.
About this lesson
This section is part of the Adaptive Query Execution: Beginner lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.