Adaptive Query Execution (AQE) dynamically adjusts query plans based on runtime statistics. What is the primary benefit of using AQE?
Think about how AQE helps with query optimization without manual intervention.
AQE improves query performance by dynamically optimizing the query plan during execution using runtime statistics, reducing manual tuning effort.
Given the following Spark code with AQE enabled, what will be the number of partitions after the join?
spark.conf.set("spark.sql.adaptive.enabled", "true") from pyspark.sql import SparkSession spark = SparkSession.builder.getOrCreate() # Simulate two DataFrames left = spark.range(0, 1000) right = spark.range(0, 10) joined = left.join(right, left.id == right.id) partitions = joined.rdd.getNumPartitions() print(partitions)
Consider how AQE optimizes join partitioning when one side is small.
With AQE enabled, Spark detects the small size of the right DataFrame and reduces the number of partitions to match the small side, here 10.
What error will occur if you disable AQE but still use AQE-specific configuration options in Spark?
spark.conf.set("spark.sql.adaptive.enabled", "false") spark.conf.set("spark.sql.adaptive.coalescePartitions.enabled", "true") # Run a query that triggers coalescePartitions spark.range(1000).repartition(10).count()
Think about how Spark handles AQE-related configs when AQE is off.
When AQE is disabled, AQE-specific configs like coalescePartitions are ignored without error, so the query runs normally.
Given a Spark job with 100 shuffle partitions and AQE coalesce enabled, if the actual shuffle data size is small, what will be the number of shuffle partitions after AQE coalescing?
spark.conf.set("spark.sql.adaptive.enabled", "true") spark.conf.set("spark.sql.adaptive.coalescePartitions.enabled", "true") spark.conf.set("spark.sql.shuffle.partitions", "100") # Simulate a small shuffle by filtering df = spark.range(1000).filter("id < 10") df2 = df.repartition(100) partitions_before = df2.rdd.getNumPartitions() # Trigger an action to run AQE df2.count() partitions_after = df2.rdd.getNumPartitions() print(partitions_after)
Consider when AQE coalesce partitions takes effect.
AQE coalesce partitions happens during shuffle stage optimization, but repartition creates a new RDD with fixed partitions. The number of partitions remains 100 here.
You have two large DataFrames with skewed keys joining on a column. Which AQE setting helps reduce the impact of skew by splitting large partitions dynamically?
Think about AQE features that handle skewed joins.
Enabling spark.sql.adaptive.skewJoin.enabled allows AQE to detect skewed partitions and split them to balance workload.
