Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Spark Query Optimization Internals
00:00
5 left

Spark Query Optimization Internals

HardSQL · PostgreSQL

Problem

Which types of query optimization do you know in Spark, and how do they work internally?

Use the supplied PostgreSQL tables to provide a hands-on SQL illustration of aggregating stage metrics and identifying completed jobs with high shuffle amplification. Explain how the corresponding Spark SQL plan could benefit from Catalyst optimization, predicate pushdown, partition pruning, join strategy selection, and Adaptive Query Execution.

Output

  1. One row per qualifying completed job
  2. Columns: job_id, application_name, input_gb, shuffle_read_mb, shuffle_write_mb, shuffle_ratio, shuffle_rank
  3. Include jobs with a shuffle ratio of at least 0.50, ordered by shuffle_ratio descending, then job_id ascending

Schema

spark_jobs
ColumnTypeDescription
job_idPKINTUnique Spark job identifier
application_nameVARCHAR(100)Spark application name
submitted_atTIMESTAMPJob submission timestamp
statusVARCHAR(20)Final job status
input_gbDECIMAL(10,2)Input data size in gigabytes
spark_stages
ColumnTypeDescription
stage_idPKINTUnique Spark stage identifier
job_idINTParent Spark job identifier
stage_nameVARCHAR(100)Stage description
shuffle_read_mbINTShuffle data read in megabytes
shuffle_write_mbINTShuffle data written in megabytes
Tablesspark_jobsspark_stages
Interviewer

Your question is Spark Query Optimization Internals. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.