Background
Postgresql has the nice function date_trunc()
which makes it easy to compute the date a week starts. This is great for aggregations on a week level. eg.
SELECT
date_trunc('week', create_date),
count(*)
FROM ...
GROUP BY 1;
HiveQL has the function WEEKOFYEAR()
that gives you the week number. If you combine this with YEAR()
you can make aggregates of the same type as in postgres.
SELECT
YEAR(create_date),
WEEKOFYEAR(create_date),
count(*)
FROM ...
GROUP BY YEAR(create_date), WEEKOFYEAR(create_date);
This is great. But what if I would like the actual date of the week?
Question
How can I compute the week date in HiveQL, from either a year and week number or directly from a timestamp?