我的表结构是这样的:
StartNew
我正在瞄准这些领域,
hive> describe user_data2;
OK
received_at string
message_id string
type string
version string
timestamp_user string
user_id string
sent_at string
channel string
time_log string
在此我想做基于时间的查询。喜欢
我得到了一些使用Datetime UDF的线索 - https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-DateFunctions
但我不知道如何使用这个功能。
我试过了:
hive> select received_at, time_log, user_id from user_data2 limit 5;
OK
2016-01-08T12:27:05.565Z 1452256025 836871
2016-01-08T12:27:12.634Z 1452256033 800798
2016-01-08T12:27:12.632Z 1452256033 795799
2016-01-08T12:27:13.694Z 1452256033 820359
2016-01-08T12:27:15.821Z 1452256036 294141
哪个没有。
如果有人举例说明使用时间UDF并在两小时或其他时间段内获取记录,我感激不尽。
答案 0 :(得分:1)
假设您当地的TZ是罗马......
select
from_utc_timestamp(regexp_replace(regexp_replace(RECEIVED_AT, 'T',' '), '\\..*$',''), 'Europe/Rome') as TS_RECEIVED,
cast(from_unixtime(cast(TIME_LOG as int)) as timestamp) as TS_LOGGED
from WTF ;
+------------------------+------------------------+--+
| ts_received | ts_logged |
+------------------------+------------------------+--+
| 2016-01-08 13:27:05.0 | 2016-01-08 13:27:05.0 |
+------------------------+------------------------+--+