• hive中常用的函数


    目录:

    1.date_sub (string statdate, int days) --返回到statdate之前int days的日期

    2.concat(str1,str2,...)--将多个字符串连接成一个字符串

    3.contact_ws(eperator,str1,str2...)--这个函数会跳过分隔符参数后的任何null和空字符串,分隔符将被加到被连接的字符串之间

    4.sum(if(category=1,1,0))--sum函数返回一个数值,如果,category=1,则返回1,否则,返回0

      count(if(category=1,true,null))--count函数返回一个布尔值类型的数据(即当返回值为true时进行计数)

    5.variance(col)--求指定列数值的方差

     

    1.date_sub()函数

    作用:返回到statdate之前int days的日期

    使用:date_sub (string statdate, int days) 

    eg:date_sub('2019-02-26',10)--------2019-02-16

     

    题外话:

    hive的书写顺序:

     

    select … from … where … group by … having … order by … 

     

    hive的执行顺序:

     

    from … where … select … group by … having … order by …

     

    2.concat()函数

    将多个字符串连接成一个字符串

    eg:select id,name from B limt 1

    id  name

    1    lon

    concat(str1,str2,...)

    返回的结果为连接string产生的字符串,如果其中有任何一个参数为null,则返回的值为null

    select concat(id,',',name) col from B limit 1

    col

    1,lon----------相当于用,把1和lon连接起来了

     

    3.contact_ws(eperator,str1,str2...)

    这个函数会跳过分隔符参数后的任何null和空字符串,分隔符将被加到被连接的字符串之间

    eg:select concat_ws(',','aa','bb')

    'aa,bb'

     

    更新于2019-02-26

     

    4.sum(if())和count(if())

    sum(if(category=1,1,0)),sum函数返回一个数值,如果,category=1,则返回1,否则,返回0

    count(if(category=1,true,null)),count函数返回一个布尔值类型的数据(即当返回值为true时进行计数),如果category=1,返回true,否则,返回null

    count(if(category=1,1,0))--返回的全部都是true,即全部都会计数

     

    5.variance(col)--return the wariance of a numeric column in the group.

                              求指定列数值的方差

    6.lateral view explode()函数

    explode()可以将数列类型拆分成多行--行转列

    lateral view可以进行相关的聚合

    对应拆分

    explode将复杂结构一行拆成多行,然后再用lateral view做各种聚合。

  • 相关阅读:
    解说asp.net core MVC 过滤器的执行顺序
    asp.net core 2.0 Microsoft.Extensions.Logging 文本文件日志扩展
    【技术累积】【点】【java】【30】代理模式
    【技术累积】【点】【java】【29】MapUtils
    【技术累积】【点】【java】【28】Map遍历
    【技术累积】【点】【java】【27】@JSONField
    【技术累积】【点】【java】【26】@Value默认值
    【技术累积】【点】【java】【25】Orderd
    【技术累积】【点】【java】【23】super以及重写重载
    【技术累积】【线】【java】【2】AOP
  • 原文地址:https://www.cnblogs.com/ellencc/p/10436822.html
Copyright © 2020-2023  润新知