impala中時間處理

impala-shell ??

set request_pool = production;

unix_timsstamp long格式徐紧;from_unixtime timestamp格式

select from_unixtime(unix_timestamp(now() + interval 3 days), 'yyyy/MM/dd HH:mm');

http://www.cloudera.com/documentation/cdh/5-1-x/Impala/Installing-and-Using-Impala/ciiu_timestamp.html#timestamp

http://www.cloudera.com/documentation/cdh/5-1-x/Impala/Installing-and-Using-Impala/ciiu_datetime_functions.html#datetime_functions

Partitioning:

Although you cannot use aTIMESTAMPcolumn as a partition key, you can extract the individual years, months, days, hours, and so on and partition based on those columns. Because the partition key column values are represented in HDFS directory names, rather than as fields in the data files themselves, you can also keep the originalTIMESTAMPvalues if desired, without duplicating data or wasting storage space. SeePartition Key Columnsfor more details on partitioning with date and time values.

date_add(timestamp startdate, int days),date_add(timestamp startdate,interval_expression)

Purpose:Adds a specified number of days to aTIMESTAMPvalue. The first argument can be a string, which is automatically cast toTIMESTAMPif it uses the recognized format, as described inTIMESTAMP Data Type. With anINTERVALexpression as the second argument, you can calculate a delta value using other units such as weeks, years, hours, seconds, and so on; seeTIMESTAMP Data Typefor details.

Return type:timestamp

date_sub(timestamp startdate, int days),date_sub(timestamp startdate,interval_expression)

Purpose:Subtracts a specified number of days from aTIMESTAMPvalue. The first argument can be a string, which is automatically cast toTIMESTAMPif it uses the recognized format, as described inTIMESTAMP Data Type. With anINTERVALexpression as the second argument, you can calculate a delta value using other units such as weeks, years, hours, seconds, and so on; seeTIMESTAMP Data Typefor details.


[localhost:21000] > create table timeline (event string) partitioned by (happened timestamp);

ERROR: AnalysisException: Type 'TIMESTAMP' is not supported as partition-column type in column: happened


[localhost:21000] > select from_unixtime(1392394861,"yyyy-MM-dd HH:mm:ss.SSSS");

+-------------------------------------------------------+

| from_unixtime(1392394861, 'yyyy-mm-dd hh:mm:ss.ssss') |

+-------------------------------------------------------+

| 2014-02-14 16:21:01.0000? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |

+-------------------------------------------------------+

[localhost:21000] > select from_unixtime(1392394861,"yyyy-MM-dd");

+-----------------------------------------+

| from_unixtime(1392394861, 'yyyy-mm-dd') |

+-----------------------------------------+

| 2014-02-14? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |

+-----------------------------------------+

[localhost:21000] > select from_unixtime(1392394861,"HH:mm:ss.SSSS");

+--------------------------------------------+

| from_unixtime(1392394861, 'hh:mm:ss.ssss') |

+--------------------------------------------+

| 16:21:01.0000? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |

+--------------------------------------------+

[localhost:21000] > select from_unixtime(1392394861,"HH:mm:ss");

+---------------------------------------+

| from_unixtime(1392394861, 'hh:mm:ss') |

+---------------------------------------+

| 16:21:01? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |

+---------------------------------------+

unix_timestamp()andfrom_unixtime()are often used in combination to convert aTIMESTAMPvalue into a particular string format. For example:

select from_unixtime(unix_timestamp(now() + interval 3 days), 'yyyy/MM/dd HH:mm');


select cast('1966-07-30' as timestamp);

select cast('1985-09-25 17:45:30.005' as timestamp);

select cast('08:30:00' as timestamp);

select hour('1970-01-01 15:30:00');? ? ? ? -- Succeeds, returns 15.

select hour('1970-01-01 15:30');? ? ? ? ? ? -- Returns NULL because seconds field required.

select hour('1970-01-01 27:30:00');? ? ? ? -- Returns NULL because hour value out of range.

select dayofweek('2004-06-13');? ? ? ? ? ? -- Returns 1, representing Sunday.

select dayname('2004-06-13');? ? ? ? ? ? ? -- Returns 'Sunday'.

select date_add('2004-06-13', 365);? ? ? ? -- Returns 2005-06-13 with zeros for hh:mm:ss fields.

select day('2004-06-13');? ? ? ? ? ? ? ? ? -- Returns 13.

select datediff('1989-12-31','1984-09-01'); -- How many days between these 2 dates?

select now();? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- Returns current date and time in UTC timezone.

create table dates_and_times (t timestamp);

insert into dates_and_times values

('1966-07-30'), ('1985-09-25 17:45:30.005'), ('08:30:00'), (now());

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市踱承,隨后出現(xiàn)的幾起案子晨炕,更是在濱河造成了極大的恐慌膏执,老刑警劉巖誓篱,帶你破解...
    沈念sama閱讀 217,185評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件皮壁,死亡現(xiàn)場離奇詭異撩荣,居然都是意外死亡铣揉,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,652評論 3 393
  • 文/潘曉璐 我一進店門餐曹,熙熙樓的掌柜王于貴愁眉苦臉地迎上來逛拱,“玉大人,你說我怎么就攤上這事台猴⌒嗪希” “怎么了?”我有些...
    開封第一講書人閱讀 163,524評論 0 353
  • 文/不壞的土叔 我叫張陵饱狂,是天一觀的道長曹步。 經(jīng)常有香客問我,道長休讳,這世上最難降的妖魔是什么讲婚? 我笑而不...
    開封第一講書人閱讀 58,339評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮俊柔,結果婚禮上筹麸,老公的妹妹穿的比我還像新娘。我一直安慰自己雏婶,他們只是感情好物赶,可當我...
    茶點故事閱讀 67,387評論 6 391
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著尚骄,像睡著了一般块差。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上倔丈,一...
    開封第一講書人閱讀 51,287評論 1 301
  • 那天憨闰,我揣著相機與錄音,去河邊找鬼需五。 笑死鹉动,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的宏邮。 我是一名探鬼主播泽示,決...
    沈念sama閱讀 40,130評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼缸血,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了械筛?” 一聲冷哼從身側響起捎泻,我...
    開封第一講書人閱讀 38,985評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎埋哟,沒想到半個月后笆豁,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,420評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡赤赊,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,617評論 3 334
  • 正文 我和宋清朗相戀三年闯狱,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片抛计。...
    茶點故事閱讀 39,779評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡哄孤,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出吹截,到底是詐尸還是另有隱情瘦陈,我是刑警寧澤,帶...
    沈念sama閱讀 35,477評論 5 345
  • 正文 年R本政府宣布饭弓,位于F島的核電站双饥,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏弟断。R本人自食惡果不足惜咏花,卻給世界環(huán)境...
    茶點故事閱讀 41,088評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望阀趴。 院中可真熱鬧昏翰,春花似錦、人聲如沸刘急。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,716評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽叔汁。三九已至统求,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間据块,已是汗流浹背码邻。 一陣腳步聲響...
    開封第一講書人閱讀 32,857評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留另假,地道東北人像屋。 一個月前我還...
    沈念sama閱讀 47,876評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像边篮,于是被迫代替她去往敵國和親己莺。 傳聞我的和親對象是個殘疾皇子奏甫,可洞房花燭夜當晚...
    茶點故事閱讀 44,700評論 2 354

推薦閱讀更多精彩內(nèi)容