PySpark Pivot, Unpivot & Rollup
6 interview problems on pivot, unpivot, rollup, cube and grouping sets, from easy to hard.
Learn Pivot, Unpivot & Rollup
- pivot · 5 min read. Turn row values into columns, and why passing the values list up front makes it faster.
- unpivot · 3 min read. Turn columns into rows (wide to long) with unpivot or the SQL stack() function.
- rollup / cube · 4 min read. Subtotals and grand totals in one pass, and how grouping() tells a total row from a real null.
- Pivot Quarterly Revenue · Medium · Pivot, Unpivot & Rollup, Aggregations
- Unpivot Wide Columns to Rows · Medium · Pivot, Unpivot & Rollup, Null Handling, Filtering & Selection
- Survey Scores by Question · Medium · Pivot, Unpivot & Rollup, Aggregations
- Subtotals with ROLLUP · Hard · Pivot, Unpivot & Rollup, Aggregations, Conditional Logic, Filtering & Selection
- All Combinations with CUBE · Hard · Pivot, Unpivot & Rollup, Aggregations, Conditional Logic
- Pivot with Several Aggregations · Hard · Pivot, Unpivot & Rollup, Aggregations, Null Handling
Browse
Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings · Data Lake · Lakehouse · Streaming · Data Prep for AI · Spark Performance
Difficulty: Easy · Medium · Hard · Learn · All problems · dbt practice