impala内建函数

来源:互联网 发布:国外 恐怖 知乎 编辑:程序博客网 时间:2024/05/17 02:35

数值处理:

select abs()    绝对值

select power(2,5)   求幂

select sin/cos/tan/asin/acos/atan/atan2()   三角函数

select bin()   十进制转换二进制

ceil()   返回大于参数的最小整数

floor() 返回小于参数的最大整数

conv(23,16,2)  第一个参数从第二个参数16进制转变成第三个参数2进制

degrees(3.14159)   约等于180   弧度转角度

factorial(5)  5的阶乘

fmod/mod/%(11.0,9.0)    2       取余

fnv_hash(type v)  返回64位hash值

greatest(bigint a[, bigint b ...]), greatest(double a[, double b ...]), greatest(decimal(p,s) a[, decimal(p,s) b ...]), greatest(string a[, string b ...]), greatest(timestamp a[, timestamp b ...])  返回最大值

least(bigint a[, bigint b ...]), least(double a[, double b ...]), least(decimal(p,s) a[, decimal(p,s) b ...]), least(string a[, string b ...]), least(timestamp a[, timestamp b ...])

precision()   scale()  返回精确度

rand() 产生0-1随机数

select truncate(3.456,7)  3.4560000   保留小数位

 

字符处理:

1 连接函数

concat('hello',',','world')   hello,world

concat_ws(string sep, string a, string b...)

group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符'])  分组拼接,组名相同的字符串用分隔符连接在一起,不写分隔符默认为逗号

group_concat(string s [, string sep])

分割

split_part('x,y,z', ',', 2)       y   返回第二个分隔符前字符,分割字符串

substr(string a, int start [, int len]), substring(string a, int start [, int len])

2 搜索函数

locate(string substr, string str[, int pos])  返回位置

 instr('hello world', 'o', -1)  从第三个参数位置开始数 返回位置

find_in_set(string str, string strList) 返回位置

instr(string str, string substr [, bigint position [, bigint occurrence ] ])
Purpose: Returns the position (starting from 1) of the first occurrence of a substring within a longer string.
Return type: int

regexp_extract(字符串, 正则表达式, 返回格式) 返回格式0 返回全部

字符串正则表达式解析函数。  功能强大

提取字母的正则表达式:([0-9]+)

提取数字的正则表达式:([a-z]+)

提取中文的正则表达式:([啊-龥]+)

select regexp_extract('wde我的qw','[啊-龥]+',0)   我的

 这个函数有点类似于 substring(str from 'regexp')

 

3 属性函数

cast(expr AS type)

describe table_name   表格描述

typeof()   返回参数类型

length(string a)

show partitions 表名

 

btrim(string a), btrim(string a, string chars_to_trim)去空格

space(int n)=repeat(' ',n)

repeat(string str, int n)  复制字符串几次

 

lower(string a), lcase(string a)

initcap('hello world')   Hello World   单词首字母变大

 

regexp_replace('aaabbbaaa', 'b+', 'xyz')    aaaxyzaaa

 

 

replace(string initial, string target, string replacement)

translate(string input, string from, string to)
Purpose: Returns the input string with a set of characters replaced by another set of characters.
Return type: string

 

LPAD('ABCDE',10,'X')    XXXXXABCDE 从左边进行填充 rpad 右填充

reverse()    反转排列

 

 

 

日期处理:

now() =current_timestamp()

add_months(now(), 2)   月份+2

adddate(now(), 2)  天数+2

date_add(now(), 2) 同上

date_add(cast('2016-01-31' as timestamp), interval 3 months)

date_part('year'/'month'/'hour',now())   去日期的年月日等

date_sub(now(), 2)   天数-2

datediff(timestamp enddate, timestamp startdate) 日期相减

day('2016-02-29')   29

day('2016-02-028')   null

dayofmonth(timestamp date) dayofweek(timestamp date) dayofyear(timestamp date)

dayname(now())   周几

to_date()

trunc(timestamp, string unit)  返回季度 月份 周 天 初始时刻

 

条件函数:

CASE a WHEN b THEN c [WHEN d THEN e]... [ELSE f] END

coalesce(type v1, type v2, ...)  返回第一个不是null的参数,常用默认值来取代null值

decode(type expression, type search1, type result1 [, type search2, type result2 ...] [, type default] )

if(boolean condition, type ifTrue, type ifFalseOrNull)

ifnull(type a, type ifNull)  

isfalse(boolean)  isnottrue(boolean)

isnotfalse(boolean)  istrue(boolean)

isnull(type a, type ifNull)

nullif(expr1,expr2)

nvl(type a, type ifNull)

nvl2(type a, type ifNull, type ifNotNull)



文档整理于:https://www.cloudera.com/documentation/enterprise/latest/topics/impala_string_functions.html#string_functions




 

原创粉丝点击