Spark SQL Tutorials for Data Engineers
Learn Spark SQL step by step, from your first SELECT to window functions and query plans. Every query comes with its real result.
Introduction to Spark SQL
Learn what Spark SQL is, where to run it, and write your first queries on a sample employees table.
Tables & Views
Understand temp views, global temp views, managed and external tables, and how to create, fill and inspect them.
SELECT, Aliases & Sorting
Select columns and expressions, rename them with aliases, remove duplicates with DISTINCT, and sort with ORDER BY.
Filtering with WHERE
Filter rows with comparisons, AND/OR, IN, BETWEEN, LIKE and IS NULL, and avoid the common traps.
GROUP BY & Aggregations
Summarize data with COUNT, SUM, AVG, MIN and MAX, group it with GROUP BY, and filter groups with HAVING.
CASE WHEN & Conditional Logic
Add if-then-else logic to queries with CASE WHEN, IF, COALESCE and NULLIF, including conditional aggregation.
Handling NULLs
Learn how NULL behaves in comparisons, arithmetic, aggregates and NOT IN, and the functions that handle it safely.
Joins
Combine tables with inner, left, right, full, semi, anti, cross and self joins, and avoid duplicate and NULL key traps.
UNION, INTERSECT & EXCEPT
Stack and compare query results with UNION, UNION ALL, INTERSECT and EXCEPT.
Subqueries & CTEs
Break complex queries into steps with scalar subqueries, IN and EXISTS, derived tables and the WITH clause.
Advanced Spark SQL Topics ๐
Window functions, nested data, pivots and query plans, explained with runnable examples.
String Functions
Clean and reshape text with concat, substring, trim, split, regexp_extract, regexp_replace and more.
Date & Time Functions
Parse, format, truncate and do arithmetic on dates and timestamps in Spark SQL.
Window Functions #1
Rank rows and compute per-group aggregates without collapsing rows, using OVER, PARTITION BY and ORDER BY.
LEAD & LAG #2
Compare each row with the previous or next one to compute changes, gaps and trends.
Window Frames #3
Build running totals and moving averages with ROWS and RANGE frames, and avoid the default frame trap.
ROLLUP, CUBE & GROUPING SETS
Produce subtotals and grand totals in a single query with GROUPING SETS, ROLLUP and CUBE.
PIVOT & UNPIVOT
Turn rows into columns with PIVOT and columns back into rows with UNPIVOT.
Arrays, Maps & Structs
Work with nested data: build and query arrays, maps and structs, explode them, and use higher-order functions.
EXPLAIN, Hints & Caching
Read query plans with EXPLAIN, steer joins with hints, and speed up repeated queries with caching.