I'm switching statistics from MySQL to Amazon DynamoDB and Elastic MapReduce.
I have query bellow that works with MySQL and I have the same table on hive and need the same results as on MySQL (product views for last_week, last_month and last_year).
SELECT product_id,
SELECT COUNT(product_id) from dev_product_views_hive as P2 where P2.product_id=P.product_id and created >= DATE_SUB(NOW(), INTERVAL 1 WEEK) as weekly,
SELECT count(product_id) from dev_product_views_hive as P3 where P3.product_id=P.product_id and created >= DATE_SUB(NOW(), INTERVAL 1 MONTH) as monthly,
SELECT count(product_id) from dev_product_views_hive as P4 where P4.product_id=P.product_id and created >= DATE_SUB(NOW(), INTERVAL 1 YEAR) as yearly
from dev_product_views_hive as P group by product_id;
I figured out how to get results for example for last month with hive:
SELECT product_id, COUNT(product_id) as views from dev_product_views_hive WHERE created >= UNIX_TIMESTAMP(CONCAT(DATE_SUB(FROM_UNIXTIME(UNIX_TIMESTAMP()), 31)," ","00:00:00")) GROUP BY product_id;
but i need grouped results like I get with MySql:
product_id views_last_week views_last_month views_last_year
2 564 2460 29967
4 980 3986 54982
Is it possible to do this with hive?
Thank you in advance,
Amer