[英]Cannot retrieve correct max date from Hive table?
我有點困惑。 當我使用max(send_date)
我得到2018-02-04 23:59:51.0
。 但是,當我使用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
!!
為什么?
select max(send_date) from mytable;
麻生太郎,當我使用WHERE TO_DATE(from_unixtime(UNIX_TIMESTAMP(send_date, 'yyyy-mm-dd'))) = '2018-02-04'
,我得到的結果為0
,但這不是事實。
我使用的轉換格式不正確。 特別是,我使用yyyy-mm-dd
而不是yyyy-MM-dd
可以在以下位置找到更多詳細信息: http : //bigdataprogrammers.com/string-date-conversion-hive/
在Hive中使用to_date
,您甚至不必指定該格式,因為默認情況下它將返回該格式。 這是一個例子
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
輸出量
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.