[英]Cannot retrieve correct max date from Hive table?
I am abit confused. 我有点困惑。 When I use max(send_date)
I get 2018-02-04 23:59:51.0
. 当我使用max(send_date)
我得到2018-02-04 23:59:51.0
。 However, when I use max(TO_DATE(from_unixtime(UNIX_TIMESTAMP(send_date, 'yyyy-mm-dd'))))
or TO_DATE(from_unixtime(max(UNIX_TIMESTAMP(send_date, 'yyyy-mm-dd'))))
, I get 2018-01-31
!! 但是,当我使用max(TO_DATE(from_unixtime(UNIX_TIMESTAMP(send_date, 'yyyy-mm-dd'))))
或TO_DATE(from_unixtime(max(UNIX_TIMESTAMP(send_date, 'yyyy-mm-dd'))))
,我得到2018-01-31
!!
Why? 为什么?
select max(send_date) from mytable;
Aso, when I use WHERE TO_DATE(from_unixtime(UNIX_TIMESTAMP(send_date, 'yyyy-mm-dd'))) = '2018-02-04'
, I get the restult 0
, but it's not true. 麻生太郎,当我使用WHERE TO_DATE(from_unixtime(UNIX_TIMESTAMP(send_date, 'yyyy-mm-dd'))) = '2018-02-04'
,我得到的结果为0
,但这不是事实。
I was using incorrect conversion format. 我使用的转换格式不正确。 In particular, I used yyyy-mm-dd
instead of yyyy-MM-dd
特别是,我使用yyyy-mm-dd
而不是yyyy-MM-dd
More details can be found here: http://bigdataprogrammers.com/string-date-conversion-hive/ 可以在以下位置找到更多详细信息: http : //bigdataprogrammers.com/string-date-conversion-hive/
When using to_date
with Hive you don't even have to specify that format because by default it returns that format. 在Hive中使用to_date
,您甚至不必指定该格式,因为默认情况下它将返回该格式。 Here is an example 这是一个例子
select max(to_date(d1)), max(d1), min(to_date(d1)), min(d1) from (
select '2018-02-04 23:59:51.0' as d1
union all
select '2018-02-04 23:59:59.0' as d1
union all
select '2018-01-31 23:59:51.0' as d1
union all
select '2018-01-31 23:59:59.0' as d1
) tbl
Output 输出量
OK
2018-02-04 2018-02-04 23:59:59.0 2018-01-31 2018-01-31 23:59:51.0
Time taken: 27.547 seconds, Fetched: 1 row(s)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.