Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Optimizing Spark and SQL
00:00
5 left

Optimizing Spark and SQL

MediumSQL · PostgreSQL

Problem

Tell me about a time you optimized a Spark query and used SQL and Python to solve a data problem end to end.

Use the provided query-run and stage-metric data to demonstrate the SQL portion of that workflow. Return the latest completed run for each query, compare it with the previous completed run, and identify the slowest stage.

Output

  1. One row per query, including queries with no stage metrics
  2. Columns: query_id, owner, run_id, total_duration_seconds, prior_duration_seconds, duration_delta_pct, bottleneck_stage, optimization_flag
  3. Sort by duration_delta_pct descending, with nulls last, then query_id ascending

Schema

query_catalog
ColumnTypeDescription
query_idPKINTLogical identifier for a Spark query
ownerVARCHAR(100)Query owner
query_textTEXTSQL text submitted to Spark
query_runs
ColumnTypeDescription
run_idPKINTUnique execution identifier
query_idINTReferenced logical query
run_started_atTIMESTAMPExecution start time
statusVARCHAR(20)Execution status
input_gbNUMERIC(10,2)Input data volume in gigabytes
stage_metrics
ColumnTypeDescription
run_idINTReferenced query execution
stage_idINTStage identifier within a run
stage_nameVARCHAR(100)Human-readable stage name
duration_secondsNUMERIC(12,2)Stage execution duration
shuffle_read_gbNUMERIC(10,2)Shuffle read volume in gigabytes
spill_gbNUMERIC(10,2)Spill volume in gigabytes
Tablesquery_catalogquery_runsstage_metrics
Interviewer

Your question is Optimizing Spark and SQL. Start with the requirements and the three 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.