[英]time based query on hive table
My table structure is like this: 我的表结构是这样的:
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
And I am targetting this fields, 我的目标是这个领域,
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
On this I want to make time based query. 在此我想进行基于时间的查询。 like 喜欢
I got some clue of using Datetime UDF - https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-DateFunctions 我得到了使用日期时间UDF的一些线索- https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-DateFunctions
But I am not aware how to use this function. 但是我不知道如何使用此功能。
I tried: 我试过了:
select unix_timestamp(received_at) from user_data2 limit 5;
OK
NULL
NULL
NULL
NULL
NULL
Which gives none. 哪也没有。
I appreciate if someone give example of using time UDF and getting records between two hours or some other time frame. 如果有人举一个使用时间UDF并获取两个小时或其他时间范围内的记录的示例,我将不胜感激。
Assuming your local TZ is Rome... 假设您当地的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 |
+------------------------+------------------------+--+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.