How do you get 'event date > current date - 10 days) in HiveQL?

情到浓时终转凉″ 提交于 2020-01-07 09:03:15

问题


I'm putting together a query that will get refreshed daily that needs to pull records from the last ten dates.

The tables I'm accessing have a 'xxdatetime' column with the unix time stamp and an 'eventdate' column with the date in a yyyy-mm-dd.

In Impala, the answer was easy:

where eventdate > to_date(days_sub(now(), 10))

I used a variation of it in Hive that failed because I guess it was scanning the whole table and the tables are MASSIVE:

where datediff(cast(current_timestamp() as string), eventdate)=10

Is there a light weight way in Hive SQL to filter the xxdatetime or eventdate columns by 'today - 10 days'?


回答1:


Eventdate is my indexed column, date_sub is (string, days to subtract) and current_date is the current Hive yyyy mm dd.

    eventdate > date_sub(current_date, 5)

I'm not sure if this is super light weight but it works!



来源:https://stackoverflow.com/questions/33324375/how-do-you-get-event-date-current-date-10-days-in-hiveql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!