Timestamp & String comparison in Hive
Issue:
Below is a sample test
CREATE DATABASE IF NOT EXISTS tmp;
DROP TABLE IF EXISTS tmp.orders;
CREATE TABLE tmp.orders (username STRING, order_creation_date TIMESTAMP, amount DOUBLE);
INSERT INTO TABLE tmp.orders VALUES ("jack", '2017-02-26 13:45:12', 88.2), ("jones", '2017-02-28 15:28:14', 92.4);
HDP 2.4.2
SELECT username FROM tmp.orders WHERE order_creation_date > '2017-02-27';
OK
jones
select * from tmp.orders;
OK
jack 2017-02-26 13:45:12 88.2
jones 2017-02-28 15:28:14 92.4
SELECT username FROM tmp.orders WHERE order_creation_date > '2017-02-27';
OK
SELECT username FROM tmp.orders WHERE order_creation_date > TO_DATE('2017-02-27');
OK
You can notice the above 2 queries did not display any result
Resolution:
Workaround: Use cast function in hive or include hh:mm:ss as below
SELECT username FROM tmp.orders WHERE order_creation_date > '2017-02-27 00:00:00';
OK
jones
This is a known bug in hive
Reference: Apache, Hortonworks

