0

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?

while
  • 3,602
  • 4
  • 33
  • 42

1 Answers1

1

Well there are not many functions in Hive. So it has the support for Custom UDF. You write your own function and integrate in Hive.

Here are some of the UDF which might be helpful:

1.) Link 1

2.) Link 2

Hope this helps..!!!

Community
  • 1
  • 1
Mukesh S
  • 2,856
  • 17
  • 23