[英]time based query on hive table
我的表結構是這樣的:
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
我的目標是這個領域,
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的一些線索- https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-DateFunctions
但是我不知道如何使用此功能。
我試過了:
select unix_timestamp(received_at) from user_data2 limit 5;
OK
NULL
NULL
NULL
NULL
NULL
哪也沒有。
如果有人舉一個使用時間UDF並獲取兩個小時或其他時間范圍內的記錄的示例,我將不勝感激。
假設您當地的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.