Skip to content

Instantly share code, notes, and snippets.

@dr-dror
Created September 27, 2024 15:06
Show Gist options
  • Save dr-dror/0f59e31e4d7d7dbd8d191ba816bd67dd to your computer and use it in GitHub Desktop.
Save dr-dror/0f59e31e4d7d7dbd8d191ba816bd67dd to your computer and use it in GitHub Desktop.
Pivot a dataframe directly using Spark SQL
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
SELECT
*
FROM
(
SELECT
date_format (tpep_pickup_datetime, 'EEEE') AS day_of_week,
fare_amount,
passenger_count
FROM
data
) PIVOT (
{agg_func}(fare_amount) FOR day_of_week IN (
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
)
)
ORDER BY
passenger_count;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment