0

I am trying to convert a Teradata query to Hive

WHERE visit_date BETWEEN (CURRENT_DATE-194) AND  (CURRENT_DATE)

where visit_date is a string of format yyyy-mm-dd.

CURRENT_DATE is valid in Hive but CURRENT_DATE-194 is giving error.

How can I do it in Hive?

ayush nigam
  • 177
  • 1
  • 4
  • 15

2 Answers2

1

Got the solution by using

visit_date BETWEEN date_sub(CURRENT_DATE,194) AND CURRENT_DATE
ayush nigam
  • 177
  • 1
  • 4
  • 15
  • Right, unix_timestamp() is non-deterministic and prevents query from being optimized. You solution is better. See also: http://stackoverflow.com/a/41140298/2700344 – leftjoin Dec 28 '16 at 09:08
0

To get data of past 194 days in Hive;
Try below query:

select * from table_1 where visit_date > date_sub(from_unixtime(unix_timestamp()), 194);

Note: TIMESTAMP is milliseconds
unix_timestamp is in seconds

Vikrant
  • 4,920
  • 17
  • 48
  • 72