美文网首页产品汪之家
【DataPM】Impala里的日期函数

【DataPM】Impala里的日期函数

作者: 88d45b859862 | 来源:发表于2018-10-23 13:34 被阅读10次

最近Impala里查数据的时候,发现有很多时间函数不支持,因此,搜集整理了一批常用时间函数,以备查询。

让日期自己与自己比较大小

datediff(first_value(create_time) over(partition by create_user order by create_time),create_time)

这是利用orcale里的窗口函数,first_value ()  over(partition by     order by   )意思是先将creat_time按照create_user分组,再按create_time进行排序,然后first_value()取出第一个时间,也就是最小时间,然后与create_time进行比较,通过得到的数值比较大小。

有什么应用场景呢?

若datediff()=0,那就表示只在当天,可以用来判断是否是只在当天有数据,也就是新增数据。

增加月份

add_months(timestamp date, int months)

add_months(timestamp date, bigint months)

Return type: timestamp

usage:add_months(now(),1)

增加日期

adddate(timestamp startdate, int days),

adddate(timestamp startdate, bigint days)

Return type: timestamp

usage:adddate(now(),1)

当前时间戳

current_timestamp()和now()等价

日期相减

datediff(string enddate, string startdate)

Return type: int

usage:datediff("2018-08-05", "2018-08-03")

得到天,得到月份

day(string date)

Return type: int

usage: day("2018-08-05")

得到星期英文

dayname(string date)

Return type: string

usage:dayname("2018-08-05") Sunday

得到这一天是这周的第几天

dayofweek(string date)  1 (Sunday) to 7 (Saturday).

Return type: int

usage:dayofweek("2018-08-06")

加天数

days_add(timestamp startdate, int days)

Return type: timestamp

usage:days_add(now(),2)

减天数

days_sub(timestamp startdate, int days)

Return type: timestamp

usage:days_sub(now(), 2)

格式化日期

from_unixtime(bigint unixtime[, string format])

Return type: string

注意参数

usage:from_unixtime(1392394861,"yyyy-MM-dd");

得到小时

hour(string date)

Return type: int

usage:hour("2018-08-06 12:32:54")

增加小时

hours_add(timestamp date, int hours)

Return type: timestamp

usage:hours_add(now(),2)

减少

hours_sub(timestamp date, int hours)

Return type: timestamp

usage:hours_sub(now(),2)

得到分钟

minute(string date)

Return type: int

usage:minute(now())

增加分钟

minutes_add(timestamp date, int minutes)

Return type: timestamp

usage:minutes_add(now(),2)

减少分钟

minutes_sub(timestamp date, int minutes)

Return type: timestamp

usage:minutes_sub(now(),2)

得到月份

month(string date)

Return type: int

usage:month("2018-08-06 12:32:54")

月份相加

months_add(timestamp date, int months)

Return type: timestamp

usage:months_add(now(),3)

减月份

months_sub(timestamp date, int months)

Return type: timestamp

months_sub(now(),3)

得到秒

second(string date)

Return type: int

秒加

seconds_add(timestamp date, int seconds)

Return type: timestamp

秒减

seconds_sub(timestamp date, int seconds)

Return type: timestamp

得到日期

to_date(now())

得到1970到今秒

unix_timestamp(),

unix_timestamp(string datetime),

unix_timestamp(string datetime, string format),

unix_timestamp(timestamp datetime)

Return type: bigint

得到这周是这年的多少周

weekofyear(string date)

Return type: int

usage:weekofyear("2018-08-06 12:32:54")

周加

weeks_add(timestamp date, int weeks)

Return type: timestamp

usage:weeks_add("2018-08-06 12:32:54", 1)

周减

weeks_sub(timestamp date, int weeks)

Return type: timestamp

usage:weeks_sub("2018-08-06 12:32:54", 1)

得到年

year(string date)

Return type: int

年加

years_add(timestamp date, int years)

Return type: timestamp

年减

years_sub(timestamp date, int years)

Return type: timestamp

相关文章

  • 【DataPM】Impala里的日期函数

    最近Impala里查数据的时候,发现有很多时间函数不支持,因此,搜集整理了一批常用时间函数,以备查询。 让日期自己...

  • Impala 其他函数

    Impala数学函数 Impala中其他函数,比如基本类型转换,时间,条件等其他函数 函数列表 cast(expr...

  • Impala 数值函数大全

    Impala数学函数 Impala中数学函数用来执行数值计算,比如基本加法,减法,乘法和除法及更复杂的运算 函数列...

  • Impala String函数大全

    Impala字符串函数 Impala中字符串函数主要应用于 varchar、char、string类型,如果把va...

  • impala条件判断函数

    1、coalesce(T v1, T v2, ...) 返回第一个不为null的v,全部为null则返回null ...

  • 浅谈交互式查询⼯工具Impala(一)

    一、Impala概述(Impala是什什么,优势,劣势,与Hive对⽐) Impala是什什么 Impala是Cl...

  • Impala快速上手:Impala简介,Impala shell

    摘要:impala,JDBC,DBCP impala简介 Impala是Cloudera由C++编写的基于MPP(...

  • [一起学Hive]之二–Hive函数大全-完整版

    Hive函数大全–完整版 现在虽然有很多SQL ON Hadoop的解决方案,像Spark SQL、Impala、...

  • 日期函数

    一、日期函数: 根据这一组函数可以将日期(YMD)和时间(hms)随心所欲的拆分或组合 1、基本用法 ⑴日期函数 ...

  • 日期函数

    datedif函数 datedif函数解释: datedif(起始日期,终止日期,间隔单位)计算两个日期的间隔 计...

网友评论

    本文标题:【DataPM】Impala里的日期函数

    本文链接:https://www.haomeiwen.com/subject/ujiozftx.html