Skip to the page
Tecyfy

PySpark interview question · hard

What is Spark SQL, and how does it differ from core Spark?

The short answerSpark SQL is the Spark module for structured data.

The full answer

Spark SQL is the Spark module for structured data. It lets you query data with SQL or the DataFrame API, works out the schema of the data, and runs every query through the Catalyst optimizer and Tungsten execution engine. "Core Spark" usually means the original RDD API: distributed collections of arbitrary objects processed with functions, with no schema and no query optimisation.

Spark SQL (DataFrames, Datasets, SQL)Core Spark (RDDs)
Data modelTables: rows with named, typed columnsCollections of any objects
How you express workSQL or declarative DataFrame operationsFunctions passed to map, filter, reduceByKey
OptimisationCatalyst: pushdown, pruning, join strategy, adaptive executionNone: your functions run as written
ExecutionTungsten: compact binary rows, generated codeJava or Python objects
Data sourcesBuilt-in readers for Parquet, ORC, JSON, CSV, Avro, JDBC, Delta, Iceberg, Hive tablesText files, Hadoop input formats, your own code
LanguagesSQL, Python, Scala, Java, RScala, Java, Python
Performance in PythonClose to Scala, since work runs in the JVMSlower: data moves to Python workers
Where it's availableEverywhere, including Spark Connect and serverlessNot in Spark Connect

What Spark SQL provides

  • A SQL engine with ANSI SQL behaviour (on by default since Spark 4), window functions, common table expressions, and features such as MERGE with table formats that support it.
  • A catalog of databases, tables, views and functions (the Hive metastore, Unity Catalog or another catalog).
  • JDBC and ODBC access through the Thrift server, so BI tools can query Spark.
  • The basis for most of the rest of Spark: Structured Streaming, MLlib's DataFrame APIs and the pandas API on Spark all run on Spark SQL.

Example of the same job

# Spark SQL (DataFrame API)
from pyspark.sql import functions as F
(spark.read.parquet("/data/orders")
    .filter(F.col("amount") > 0)
    .groupBy("country").agg(F.sum("amount").alias("revenue")))
-- Spark SQL (SQL)
SELECT country, SUM(amount) AS revenue
FROM parquet.`/data/orders`
WHERE amount > 0
GROUP BY country;
# Core Spark (RDD)
(sc.textFile("/data/orders.csv")
    .map(lambda line: line.split(","))
    .filter(lambda f: float(f[2]) > 0)
    .map(lambda f: (f[1], float(f[2])))
    .reduceByKey(lambda a, b: a + b))

The RDD version has to parse the file by hand, can't skip columns or rows at the source, and is not optimised.

How they relate Spark SQL runs on the core engine: DataFrame plans are compiled into RDD operations underneath, using the same scheduler, executors and fault tolerance. Today almost all new work uses Spark SQL; the RDD API remains for low-level control and legacy code.

Last updated 16 October 2026