show functions 查看了所有的方法
把所有的方法记录下来,下次免得去翻别人的博客了

数学函数

数学常规函数

函数

简介

用法

abs

绝对值

select abs(-13);13

negative

正数转负数,负数转正数

select negative(-4);4 select negative(4);-4

sin

正弦值 参数无限制数字即可

select sin(0.52); 0.49688

cos

余弦值 参数无限制数字即可

select cos(13); 0.907446

tan

正切值 参数无限制数字即可

select tan(0.523); 0.576552

asin

反正弦值 参数a介于-1到1之间,否则返回NULL值

select asin(0.25);0.2526

acos

反余弦值 参数a介于-1到1之间,否则返回NULL值

select acos(0.25);1.3181

atan

反正切值 参数无限制数字即可

select atan(-10.34);-1.47438

degrees

弧度值转换为度数值

select degrees(0.1);5.729577951308232

radians

度数值转换为弧度值

select radians(30);0.5235987755982988

div

整数除法器 将a除以b结果为整数

SELECT 9 div 2;4

mod

余数

select mod(7,5) ;2

pmod

a除以b的余数的绝对值

select pmod(-9,4);3 select pmod(9,4);1

ceil

向上取整

select ceil(10.1);11

ceiling

向上取整

select ceil(10.1);11

round

四舍五入

select round(1.5);2 select round(3.1415926,4);3.1416

floor

小于或等于该数值参数的最大整数

select floor(9.5);9

bround

银行家算法 第二个参数可以限制小数位

select bround(2.5);2,bround(3.5);4

cbrt

立方根函数

select cbrt(27);3

ln

以e为底log对数

select ln(22026.465794806718);10

log

返回以第一个参数为低的第二个参数对数

select log(2,8);3

log10

以10为底log对数

select log10(100);2

log2

以2为底log对数

select log2(8);3

sqrt

开方根函数

SELECT sqrt(16);4

pow

次方函数

select pow(2,4);16.0

power

次方函数

select power(2,4);16.0

e

e常量

select e();2.718281828459045

exp

e的N次方

select exp(2);7.38905609893065

pi

派常量

select pi();3.141592653589793

factorial

阶乘函数

select factorial(5);54321=120

format_number

数字格式化成"#,###.##" 保留第二参数小数位

select format_number(123345.65545,2);123,345.66

rand

产生随机数 有第二个参数每次相同

select rand();0.742319 select rand(100);0.7220096548596434

positive

返回当前值

select positive(-1);-1 select positive(1);1

shiftleft

二进制左移函数

select shiftleft(5,2);20

shiftright

二进制右移函数

select shiftright(20,2);5

shiftrightunsigned

无符号二进制右移函数

select shiftrightunsigned(-20,2);1073741819

sign

数值符号类型,如果参数大于0,返回1.0;小于0,返回-1.0;等于0,返回0.0

select sign(100.0);1 select sign(0);0 select sign(-100.0);-1

统计学相关函数

函数

简介

用法

std

一组数字的标准偏差

select std(id) from data;94365.2855709603

stddev

一组数字的标准偏差

select stddev(id) from data;94365.2855709603

stddev_pop

一组数字的标准偏差

select stddev_pop(id) from data;94365.2855709603

stddev_samp

返回一组数字的样本标准差

select stddev_samp(id) from data;115573.39954043635

var_pop

返回一组数字的方差

select var_pop(id) from data;8.904807120888887E9

variance

返回一组数字的方差

select var_pop(id) from data;8.904807120888887E9

var_samp

返回一组数字的样本方差

select var_samp(id) from data;1.3357210681333332E10

covar_pop

总体协方差

select covar_pop(a,b) from big_data;8.333333333324998E10

covar_samp

样本协方差

select covar_samp(a,b) from big_data;8.333334090900824E10

corr

皮尔逊相关系数

select corr(a,b) from big_data;1.0

regr相关函数

函数

简介

用法

regr_avgx

计算第二个参数的平均值,参数值为x,y

select regr_avgx(id,user_id) from test;= avg(user_id)

regr_avgy

计算第一个参数的平均值,参数值为x,y

select regr_avgy(id,user_id) from test;= avg(id)

regr_count

返回两列非空数量

select regr_count(id,user_id) from test;

regr_intercept

返回回归线的y轴截距 (SUM(y)* SUM(x * x)-SUM(X)* SUM(x * y))/(N * SUM(x * x)-SUM(x)* SUM(X) )

select regr_intercept(id,user_id) from test;-4.5

regr_r2

返回回归线的确定系数POWER(N * SUM(x * y)-SUM(x)* SUM(y),2)/((N * SUM(x * x)-SUM(x)* SUM(x ))*(N * SUM(y * y)-SUM(y)* SUM(y)))

select regr_r2(id,user_id) from test;1

regr_slope

返回线性回归线的斜率 (N * SUM(x * y)-SUM(x)* SUM(y))/(N * SUM(x * x)-SUM(x)* SUM(x))

select regr_slope(id,user_id) from test;1.5

regr_sxx

辅助分析函数 SUM(x * x)-SUM(x)* SUM(x)/ N

select regr_sxx(id,user_id) from test;2.0

regr_sxy

回归模型的统计有效性 SUM(x * y)-SUM(x)* SUM(y)/ N

select regr_sxy(id,user_id) from test;3.0

regr_syy

辅助分析函数SUM(y * y)-SUM(y)* SUM(y)/ N

select regr_syy(id,user_id) from test;4.5

字符串函数

字符串常规函数

函数

简介

用法

aes_decrypt

解密(input binary, key string/binary)

select aes_decrypt(unbase64('ThkIuvL03UnaQXTfWjSZNg=='),'123456789012345a');abcd

aes_encrypt

加密(input string/binary, key string/binary)返回值二进制需要base64 第二个字符串长度16/24/32别的不会显示

select base64(aes_encrypt('abcd','123456789012345a'));

length

字符串长度

select length('abcdefgh');8

uuid

唯一标识符字符串

select uuid();e8b6113b-6c2e-49da-b9f8-1ec01c0edf29

repeat

重复函数

select repeat('1234',4);1234123412341234

reverse

倒置函数

select reverse('abcd');dcba

space

返回X个空格

select concat('a',space(4),'a');a a

printf

打印函数 必须字符串

select printf('abfhg');

字符串大小写函数

函数

简介

用法

initcap

字符串首字母大写

select initcap('abcdefg');Abcdefg

lower

字符串转小写

select lower('ABCD');abcd

lcase

字符串转小写

select lcase('ABCD');abcd

ucase

字符串大写

elect ucase('aBCD');ABCD

upper

字符串转大写

select upper('abcd');ABCD

字符串查找、拼接、替换函数

函数

简介

用法

coalesce

第一个不为空的值

select coalesce(NULL,null,1,'1');1

levenshtein

字符串差异个数 仅限字符串

select levenshtein('abcdABcd', 'ABCDADcd');5

field

返回第一个字符串在后续字符串的下标

select field('2022',id,user_id,desc) from data;2

locate

第一次出现的位置

select locate('abcd','abcdabcdabcd',2);5

elt

返回第n个字符串 参数仅限字符串

select elt(3,'a','b','c','d','e','f');c

lpad

指定长度字符串,不足指定的长度的字符串,则用指定字符从左边补全

select lpad('abcd',10,1);111111abcd

rpad

指定长度字符串,不足指定的长度的字符串,则用指定字符从右边补全

select rpad('abcd',10,1);abcd111111

concat

字符串拼接

select concat('ab','cd','ef');abcdef

substr

字符串截取

select substr('abcdef',1,3);abc select substr('abcdef',3);cdef

substring

字符串截取

select substring('abcdef',1,3);abc select substring('abcdef',3);cdef

substring_index

第二个分隔符出现之前的字符串

select substring_index('ab.cd.ef.gh','.',2);ab.cd

replace

字符串替换

select replace('abcdm','a','m');mbcdm

translate

字符串替换 abc替换成xyz

select translate('abcdefgh','abc','xyz');

soundex

字符串转换成 soundex字符串

select soundex('abcd');A123

instr

子字符串在字符串中位置

select instr('abcdefg','cd');3

rtrim

去掉字符串右侧空格

select rtrim(' abcd ');abcd

ltrim

去掉字符串左侧空格

select ltrim(' abcd');abcd

trim

去掉字符串左右侧空格

select ltrim(' abcd ');abcd

字符正则相关函数

函数

简介

用法

regexp

正则like

select 'abcdefgh' regexp '^ab';true

regexp_extract

将字符串按照正则表达式的规则拆分,返回指定的字符

select regexp_extract('abcd1efgh2ijk', '([a-z]*)', 1);abcd1

regexp_replace

正则替换

select regexp_replace('abcd1234', '\d+', 'a');abcda

rlike

正则like

select 'abcdefgh' rlike '^ab';true "." 任意单个字符 "*" 匹配前面的字符0次或多次 "+" 匹配前面的字符1次或多次 "?" 匹配前面的字符0次或1次 "\d" 等于 [0-9] "\u4E00-\u9FA5" 汉字

字符串编码、进制相关函数

函数

简介

用法

ascii

字符串转ascii码

select ascii('4');52

md5

md5加密

select md5('abc');900150983cd24fb0d6963f7d28e17f72

sha

SHA-1摘要 作为十六进制字符串返回

SELECT sha('ABC');3c01bdbb26f358bab27f267924aa2c9a03fcfdb8

sha1

SHA-1摘要 作为十六进制字符串返回 字符串和二进制

SELECT sha1('ABC');SELECT sha1(binary('3'));

sha2

SHA-2摘要 作为十六进制字符串返回

select sha2('abcd',224/256/384/512);

encode

第二个参数字符集对第一个参数进行编码

select encode('aa','UTF-8');aa

decode

第二个参数解码第一个参数

select decode(encode('aa','UTF-8'),'utf-8');aa

chr

将字节码数字转为对应字母

select chr('108');l select chr('106');j

character_length

返回字符串或者二进制的长度

SELECT char_length(bin(1024));SELECT char_length('1234');

char_length

返回字符串或者二进制的长度

SELECT char_length(bin(1024));SELECT char_length('1234');

octet_length

str或二进制数据中的字节数

SELECT octet_length('HUX8 ');5 SELECT octet_length('abcde');5

crc32

返回字符串或二进制参数的循环冗余校验值

select crc32('abc');891568578

conv

进制转换

SELECT conv('100', 10, 2);1100100

base64

将给定的二进制转换为字符串

select base64(unbase64('abcd'));abcd

unbase64

64位的字符串转换二进制

select base64(unbase64('abcd'));abcd

bin

将整数转换为二进制,参数限制整数

select bin(3);

binary

将字符串转换为二进制,参数限制字符串

select binary('3');

hex

字符串转十六进制

select hex(1234);4D2 select hex('abcd');61626364

unhex

解析十六进制

select unhex('61626364');abcd

hash

返回参数的哈希值

select hash('abcd');2987074

日期函数

日期获取函数

函数

简介

用法

datetime_legacy_hybrid_calendar

日历有一个起始时间,这个之前时间是错误的 用这个函数修正 不重要

select datetime_legacy_hybrid_calendar(CAST('0601-03-07' AS DATE));0601-03-04

to_epoch_milli

暂时不知道这个函数用法 纪元的毫秒数

create table tstz1_n1(t timestamp with local time zone);insert into tstz1_n1 values(current_timestamp());select to_epoch_milli(t) from tstz1_n1;1660403689952

trunc

第二个参数最开始时间

select trunc(current_date(),'MM');'MM','QUARTER','YYYY'

second

返回时间的秒 参数date/timestamp

select second(date('2018-09-19'));select second(current_timestamp());

minute

返回时间的分钟 参数date/timestamp

select minute(date('2018-09-19'));select minute(current_timestamp());

hour

返回时间的小时参数date/timestamp

select hour(date('2018-09-19'));0 select hour(current_timestamp());

current_date

当前日期

select current_date();2022-08-13

current_timestamp

当前时间戳

select current_timestamp();2022-08-13 12:15:17.435

day

当前日期的天 参数date/timestamp

select day(date('2018-09-19'));19 select day(current_timestamp());14

dayofmonth

月里面天数 参数date/timestamp

select dayofmonth(date('2018-09-19'));19 select dayofmonth(current_timestamp());14

dayofweek

周天数 参数date/timestamp

select dayofweek(date('2022-09-19'));2 select dayofweek(current_timestamp());1

weekofyear

周数 参数date/timestamp

select weekofyear(date('2022-08-13'));select weekofyear(current_timestamp());

month

返回时间的月份参数date/timestamp

select month(date('2018-09-19'));select month(current_timestamp());

quarter

返回时间的季度参数date/timestamp

select quarter(date('2018-09-19'));select quarter(current_timestamp());

year

返回时间的年份 参数date/timestamp

select year(date('2018-09-19'));select year(current_timestamp());

日期转换函数

函数

简介

用法

to_date

返回时间戳中的日期部分

select to_date(current_timestamp());

to_unix_timestamp

转化成时间戳

select to_unix_timestamp('1970-01-01 00:00:00','PST');0

from_utc_timestamp

输入转成对应时区的时间

SELECT from_utc_timestamp('2016-08-31', 'Asia/Seoul');2016-08-31 09:00:00

to_utc_timestamp

转化成UTC下的时间戳

select to_utc_timestamp('1970-01-01 00:00:00','PST');1970-01-01 08:00:00

date_format

前面格式转换成后面的格式

1:date/timestamp/string select date_format('2009-07-30','yyyyMMdd');select date_format(current_timestamp(),'yyyy

from_unixtime

UNIX时间戳转日期

select from_unixtime(86400,'yyyy-MM-dd HH:mm:ss');1970-01-02 00:00:00

unix_timestamp

日期转UNIX时间戳

select unix_timestamp('2022-01-01 00:00:00');1640995200

datediff

日期差 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd' 第一个减去第二个

SELECT datediff('2009-07-30', '2009-07-25');5 SELECT datediff('2009-07-30 12:12:12', '2009-07-25 12:12:12');5

last_day

月份最后一天的日期函数

select last_day(current_date());2022-08-31

next_day

当前日期的下一个周几是哪天

SELECT next_day('2022-08-13','TU');下一个周二是哪天 2022-08-16

date_add

日期相加

SELECT date_add('2009-07-30', 1);2009-07-31 不是这个格式的NULL

date_sub

日期相减

SELECT date_sub('2009-07-30', 1);

add_months

月份相加 输入必须yyyy-MM-dd 输出可以第三个参数指定

select add_months('2022-08-01',2,'yyyyMMdd');20221001

months_between

相差的月份

select months_between(current_date(),'2022-5-13'),months_between('2022-09-13','2022-5-13') ;3 4

日期获取 floor函数

函数

简介

用法

floor_day

返回时间戳的天开始时间

select floor_day(current_timestamp());2022-08-13 00:00:00 (真实时间 2022-08-13 14:45:30)

floor_hour

返回时间戳的小时开始时间

select floor_hour(current_timestamp());2022-08-13 14:00:00 (真实时间 2022-08-13 14:45:30)

floor_minute

返回时间戳的分钟开始时间

select floor_minute(current_timestamp());2022-08-13 14:45:00 (真实时间 2022-08-13 14:45:30)

floor_month

返回时间戳的月份开始时间

select floor_month(current_timestamp());2022-08-01 00:00:00 (真实时间 2022-08-13 14:45:30)

floor_quarter

返回时间戳的季度开始时间

select floor_quarter(current_timestamp());2022-07-01 00:00:00 (真实时间 2022-08-13 14:45:30)

floor_second

返回时间戳的秒开始时间

select floor_second(current_timestamp());2022-08-13 14:45:30 (真实时间 2022-08-13 14:45:30)

floor_week

返回时间戳的周开始时间

select floor_week(current_timestamp());2022-08-08 00:00:00 (真实时间 2022-08-13 14:45:30)

floor_year

返回时间戳的年开始时间

select floor_year(current_timestamp());2022-01-01 00:00:00 (真实时间 2022-08-13 14:45:30)

集合函数

函数

简介

用法

size

集合长度函数

select size(map(1,2,3,4));2 select size(array(1,2,3,4));4

array

输入参数转数组 会把所有值转换为字符串

select array(1,2,'3','4');["1","2","3","4"]

split

字符串切数组

select split('a,b,c,d',',');["a","b","c","d"]

index

返回第一个参数的 第二个参数的值

select index(array(1,2,3,4),2);

array_contains

数组包含 第二个参数必须是字符串

select array_contains(array('a',2,'3','4'),'2');

sort_array

集合排序

select sort_array(array(4,2,3,4));[2,3,4,4]

sort_array_by

集合排序

 

replicate_rows

一行变成多行

select replicate_rows(cast (5 as BIGINT),'abcd');

explode

爆炸函数

select desc,dessplit from data lateral view explode(split(desc,','))t as dessplit;a,b,c,d,e,f {a,b,c,d,e,f}

posexplode

带下标的爆炸函数

select desc,dessplit,dessplit_index from data lateral view posexplode(split(desc,','))t as dessplit,dessplit_index;

collect_list

将列转换数组 可以重复

select collect_list(id) from data;

collect_set

将列转换数组 不可以重复

select collect_set(id) from data;

concat_ws

将数组内容按照分隔符拼接成字符串

select concat_ws('*',collect_list(user_id)) from data;

find_in_set

返回str_array中str的第一个匹配项,其中str_array是逗号分隔的字符串

SELECT find_in_set('abcd','a,ab,abc,abcd,abcde');4

inline

将数据和结构分解为表

select inline(array(struct('a','1','b',2),struct('c','3','d',4)));col1 col2 col3 col4 a 1 b 2 c 3 d 4

str_to_map

字符串转map

select str_to_map('a:1,b:2,c:3,d:4',',',':');{"a":"1","b":"2","c":"3","d":"4"}

map

构造map函数都转成字符串

select map(1,2,'a','b');{"1":"2","a":"b"}

map_keys

返回map的key

select map_keys(map(1,2,'a','b'));["1","a"]

map_values

返回map的value

select map_values(map(1,2,'a','b'));["2","b"]

struct

构造结构体函数

select struct(1,'abcd',2.0,false);{"col1":1,"col2":"abcd","col3":2,"col4":false}

named_struct

结构体构造

select named_struct('a',1,'b',2);{"a":1,"b":2}

分组函数

函数

简介

用法

min

最小值

select min(id) over(partition by id) from data;

max

最大值

select max(id) over(partition by id) from data;

least

列表最小的值

select least(id,user_id) from data;

greatest

两列最大的值

select greatest(id,user_id) from data;

sum

聚合函数

select name, score, sum(score)over(order by name ) from window_test;

row_number

组函数 不用介绍了

 

grouping

groupby 升级用法

SELECT id,user_id,count(1) FROM data GROUP BY id,user_id GROUPING SETS (id,user_id,(id,user_id));

first_value

第一个值 依赖over函数

select name, score, first_value(score)over(partition by name order by score) from window_test;

last_value

最后一个值 依赖over函数

select name, score, last_value(score)over(partition by name order by score) from window_test;

lag

上两行score字段

select name, score, lag(score,2)over(partition by name order by score) from window_test;

lead

下两行score字段

select name, score, lead(score,2)over(partition by name order by score) from window_test;

rank

排名函数1234 ,相同顺序 下一个加二 依赖over函数

select name, score, dense_rank()over(partition by name order by score) from window_test;

dense_rank

排名函数,相同顺序 下一个加一 依赖over函数

select name, score, dense_rank()over(partition by name order by score) from window_test;

cume_dist

排名/总排名函数

select name, score, cume_dist()over(partition by name order by score) from window_test;

percent_rank

百分比分组函数

select name, score, percent_rank()over(partition by name order by score) from window_test;

percentile

百分位数函数

select percentile(id,0.5) from data; 2023.0

percentile_approx

多个百分位数函数

select percentile_approx(id,array(0.25,0.5,0.75,1)) from data;[2022.0,2023.0,102112.0,202201.0]

ntile

分块函数,数据氛围多块 参数为int

select name, score, ntile(3)over(order by score) from window_test;

field

返回第一个字符串在后续字符串的下标

select field('2022',id,user_id,desc) from data;2

文件解析函数

函数

简介

用法

in_file

文件数据与字符串str匹配 整行匹配

select in_file('202201,2022,2021','/opt/hive/hive/data/data/000000_0');

URL解析函数

函数

简介

用法

parse_url

从URL中提取部件:HOST,PATH,QUERY,REF,PROTOCOL,AUTHORITY,FILE,USERINFO 键指定要提取的查询

SELECT parse_url('http://facebook.com/path/p1.php?query=1','USERINFO');NULL

parse_url_tuple

从URL中提取部件

SELECT parse_url_tuple('http://facebook.com/path/p1.php?query=1','HOST','PATH','QUERY','REF','PROTOCOL','AUTHORITY','FILE','USERINFO');

JSON解析函数

函数

简介

用法

get_json_object

解析字符串

select get_json_object('{"a": 1, "b": [1, 2, 3]}','$.b');[1,2,3]

json_tuple

解析字符串

select json_tuple('{"a": 1, "b": [1, 2, 3]}','a','b');1 [1,2,3]

XML解析函数

函数

简介

用法

xpath

按照第二个参数解析第一个xml

SELECT xpath('b1b2b3c1c2','a/b/text()');["b1","b2","b3"]

xpath_boolean

xml解析 布尔类型判断

SELECT xpath_boolean('false','a/b/text()="false"');true

xpath_double

xml解析 类型提取

SELECT xpath_double('3.1415','a/b/text()');3.1415

xpath_float

xml解析 类型提取

SELECT xpath_float('3.1415','a/b/text()');3.1415

xpath_int

xml解析 类型提取

SELECT xpath_int('3.1415','a/b/text()');3

xpath_long

xml解析 类型提取

SELECT xpath_long('3.1415','a/b/text()');3

xpath_number

xml解析 类型提取

SELECT xpath_number('3.1415','a/b/text()');3.1415

xpath_short

xml解析 类型提取

SELECT xpath_short('3.1415','a/b/text()');3

xpath_string

xml解析 类型提取

SELECT xpath_string('3.1415','a/b/text()');3.1415

java反射函数

函数

简介

用法

java_method

使用反射调用方法

select java_method("java.lang.Math", "max", 2, 3);

reflect

使用反射调用方法

select reflect('java.lang.Math','abs',-18);18

reflect2

Hive类型对应类的方法

select reflect2(-18,'toString');18 这个是Integer

系统函数

函数

简介

用法

compute_stats

返回一列的元数据信息

select compute_stats(id,'hll') from data;{"columntype":"Long","min":2022,"max":2022,"countnulls":0,"numdistinctvalues":1,"ndvbitvector":HLL����}

current_authorizer

当前认证规则

select current_authorizer();org.apache.hadoop.hive.ql.udf.generic.GenericUDFCurrentAuthorizer

current_database

当前数据库

select current_database();default

current_groups

当前用户组

select current_groups();root

current_user

当前用户

select current_user();root 暂时不理解这个用户和current_authorizer的关系

logged_in_user

返回登录的用户名

select logged_in_user();NULL

version

hive版本

select version();3.1.3 r4df4d75bf1e16fe0af75aad0b4179c34c07fc975

类型转换函数

函数

简介

用法

cast

类型转换函数

select cast('20220101' as int);20220101

udftoboolean

参数转布尔类型默认为true

select udftoboolean('true');true select udftoboolean('false');false select udftoboolean('1234');true

udftobyte

参数转字节类型默认为NULL

select udftobyte(true);1 select udftobyte('false');-128 ~ 127

udftodouble

参数转双精度类型默认为NULL

select udftodouble('3');3.0 select udftodouble('sad');NULL

udftofloat

参数转浮点类型默认为NULL

select udftofloat('true');NULL select udftofloat('3');3.0

udftointeger

参数转整数类型

select udftointeger('true');NULL select udftointeger('1234');1234 -2147483648 ~ 2147483647

udftolong

参数转长类型

select udftolong('true');NULL select udftolong('1234');1234 -9223372036854775808 ~ 9223372036854775807

udftoshort

参数转整数类型

select udftoshort('true');NULL select udftoshort('1234');1234 -32768~32767

udftostring

参数转字符串类型

select udftostring('false');false select udftostring('true');true select udftostring(1234);1234

判断函数

函数

简介

用法

if

条件函数 不用介绍了

select if(11>10,true,false) ;

nullif

两个参数相等 NULL 否则第一个参数

select nullif(12,10);12

nvl

第一个参数为null 就返回默认值

select nvl(13,12);13 select nvl(NULL,12);12 select nvl(null,12);12

isfalse

false返回true 别的返回false

select isfalse(true);false select isfalse(false);true select isfalse('1234');false

isnotfalse

不是false 返回true 别的返回false

select isnotfalse(true);true select isnotfalse(false);false select isnotfalse('1234');true

isnotnull

非空返回true 别的返回false

select isnotnull(null);false select isnotnull(NULL);false select isnotnull('1234');true

isnottrue

不是true 返回true 别的返回false

select isnottrue(true);false select isnottrue(false);true select isnottrue('1234');false

isnull

空返回true 别的返回false

select isnull(null);true select isnull(NULL);true select isnull('1234');false

istrue

true返回true 别的返回false

select istrue(true);true select istrue(false);false select istrue('-1234');true

assert_true

如果不为true的话抛出异常,true返回NULL。这个函数还不如if呢

 

assert_true_oom

仅仅测试模式可用

 

enforce_constraint

强制非空检查 内部使用

 

不知道怎么分类函数

函数

简介

用法

create_union

将第一个参数和后面第一个参数对应的值union起来

select create_union(3,'a','b','c','d','e','f');{3:"d"}

stack

将列转换为第一个参数的行数

SELECT stack(1, "en", "dbpedia", NULL );col0 col1 col2 en dbpedia NULL

restrict_information_schema

是否强制信息 内部使用

select restrict_information_schema();false

sentences

按照空格将输入语句变成数组

SELECT sentences("Hive is an excellent tool for data querying") AS value;[["Hive","is","an","excellent","tool","for","data","querying"]]

sq_count_check

对标量子查询表达式进行内部检查,以确保返回最多一行

select sq_count_check(id) from data;

width_bucket

width_bucket(expr, min_value, max_value, num_buckets)

 

min_value<expr<max_value 均值映射

expr>max_value=max_value+1 

expr<min_value=1

select width_bucket(2,1,4,4);2

merge

合并表 full join 类似的功能 

set hive.support.concurrency=true;
set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
set hive.enforce.bucketing = true;
set hive.exec.dynamic.partition.mode = nonstrict;
set hive.compactor.initiator.on = true;
set hive.compactor.worker.threads = 1;
set hive.auto.convert.join=false;
set hive.merge.cardinality.check=false;

ALTER TABLE data_year_orc SET TBLPROPERTIES ("transactional"="true");
select * from data_year_orc;

explain merge into data_year_orc as table_a

USING data_year as table_b
on table_a.year = table_b.year
WHEN MATCHED and (table_a.year = '2014') THEN UPDATE SET b=table_b.b
WHEN MATCHED and table_b.year = '2015' then delete
WHEN NOT MATCHED then insert VALUES(table_b.year,table_b.b);

暂未理解、废弃函数

函数

简介

用法

bloom_filter

布隆过滤器,应该是用于索引的。但是hive 3.0 起删除索引 建议使用parquet和orc文件

 

in_bloom_filter

布隆过滤器 废弃了

 

cardinality_violation

select cardinality_violation(id) from data;在源码里面搜到explain merge 会有,但是没有不知道为什么

 

context_ngrams

第一个参数字符串数组、字符串数组数组 第二个参数将估计主要表达式中ab之后的前'k'个单词 第四个参数是内存 出来结果是NULL 看不懂这个函数

SELECT context_ngrams(sentences(user_id), array('a','b',null), 3).estfrequency FROM data;

get_splits

暂时不知道这个函数用法 没有tez引擎

select get_splits('abcdefgh',4);

histogram_numeric

使用第二个参数bin计算数字'expr'的直方图

select histogram_numeric(id,3) from data;[{"x":2022.0,"y":1.0}]

likeall

暂时不知道这个函数用法 like 多个函数

select * from test where id like any ('%3%','%6%');但是没有调通

likeany

暂时不知道这个函数用法 like 多个函数

select * from test where id like any ('%3%','%6%');但是没有调通

matchpath

暂时看不懂这个函数的意思

create table flights_tiny_n0 ( ORIGIN_CITY_NAME string, DEST_CITY_NAME string, YEAR int, MONTH int,DAY_OF_MONTH int, ARR_DELAY float, FL_NUM string );select origin_city_name, fl_num, year, month, day_of_month, sz, tpath from matchpath(on flights_tiny_n0 distribute by fl_num sort by year, month, day_of_month arg1('LATE.LATE+'), arg2('LATE'), arg3(arr_delay > 15), arg4('origin_city_name, fl_num, year, month, day_of_month, size(tpath) as sz, tpath[0].day_of_month as tpath') )

murmur_hash

 

 

ngrams

暂时看不懂这个函数的意思,下面是函数的用法 看代码应该是字符串拷贝的类

SELECT ngrams(sentences(lower('abcd')), 2, 100, 1000).estfrequency ;

noop

暂时看不懂这个函数的意思,下面是函数的用法 看代码应该是字符串拷贝的类

select count(id) from noop(on data_par partition by id);

noopstreaming

暂时看不懂这个函数的意思,下面是函数的用法 看代码应该是字符串拷贝的类

select count(id) from noopstreaming(on data_par partition by id);

noopwithmap

暂时看不懂这个函数的意思,下面是函数的用法 看代码应该是字符串拷贝的类

select count(id) from noopwithmap(on data_par partition by id);

noopwithmapstreaming

暂时看不懂这个函数的意思,下面是函数的用法 看代码应该是字符串拷贝的类

select count(id) from noopwithmapstreaming(on data_par partition by id);

windowingtablefunction

暂时不知道这个函数用法 这个函数在hive 测试中没有一个测试用例,应该是内部函数

 

字符串掩盖函数

mask 掩盖给定值

mask(value,upperChar, lowerChar,digitChar,otherChar,numberChar,dayValue,monthValue,yearValue)

    upperChar - 用大写字符替换大写字符的字符。指定-1以保留原始字符。默认值:'     lowerChar - 用小写替换小写字符的字符。指定-1以保留原始字符。默认值:'x'
    digitChar - 用数字字符替换的字符。指定-1以保留原始字符。默认值:'    otherChar - 用其替换所有其他字符的字符。指定-1以保留原始字符。默认值:-1
    numberChar - 用数字替换数字的字符。有效值:0-9。默认值:'   dayValue - 用日期替换日期字段的值。指定-1以保留原始值。有效值:1-31。默认值:1
    monthValue - 用日期替换日期中的月份字段的值。指定-1以保留原始值。有效值:0-11。默认值:0   yearValue - 用日期替换年份字段的值。指定-1以保留原始值。默认值:0

mask_first_n 掩盖值的前n个字符

mask_first_n(value,charCount,upperChar,lowerChar,digitChar,otherChar, numberChar)

     value - 要屏蔽的值。支持的类型:TINYINT,SMALLINT,INT,BIGINT,STRING,VARCHAR,CHAR
     charCount - 字符数。默认值:4
     upperChar - 用大写字符替换大写字符的字符。指定-1以保留原始字符。默认值:'
     X'lowerChar - 用小写替换小写字符的字符。指定-1以保留原始字符。默认值:'x'
     digitChar - 用数字字符替换的字符。指定-1以保留原始字符。默认值:'
     n'otherChar - 用其替换所有其他字符的字符。指定-1以保留原始字符。默认值:-1
     numberChar - 用数字替换数字的字符。有效值:0-9。默认值:'1'

mask_hash 返回给定值的哈希值

select mask_hash('1234');03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4

mask_last_n 屏蔽值的最后n个字符

mask_last_n(value,charCount,upperChar,lowerChar,digitChar,otherChar, numberChar)

    value - 要屏蔽的值。支持的类型:TINYINT,SMALLINT,INT,BIGINT,STRING,VARCHAR,CHAR  charCount-字符数。默认值:4
    upperChar - 用大写字符替换大写字符的字符。指定-1以保留原始字符。默认值:'  lowerChar - 用小写替换小写字符的字符。指定-1以保留原始字符。默认值:'x'
    digitChar - 用数字字符替换的字符。指定-1以保留原始字符。默认值:'   otherChar - 用其替换所有其他字符的字符。指定-1以保留原始字符。默认值:-1
    numberChar - 用数字替换数字的字符。有效值:0-9。默认值:'1'

mask_show_first_n 掩码除了值的前n个字符以外的所有字符

mask_show_first_n(value,charCount,upperChar,lowerChar,digitChar,otherChar ,numberChar)

    value - 要屏蔽的值。支持的类型:TINYINT,SMALLINT,INT,BIGINT,STRING,VARCHAR,CHAR  charCount - 字符数。默认值:4
    upperChar - 用大写字符替换大写字符的字符。指定-1以保留原始字符。默认值:'  lowerChar - 用小写替换小写字符的字符。指定-1以保留原始字符。默认值:'x'
    digitChar - 用数字字符替换的字符。指定-1以保留原始字符。默认值:'  otherChar - 用其替换所有其他字符的字符。指定-1以保留原始字符。默认值:-1
    numberChar - 用数字替换数字的字符。有效值:0-9。默认值:'1'

mask_show_last_n 掩码除了值的最后n个字符之外的所有

mask_show_last_n(value,charCount,upperChar,lowerChar,digitChar,otherChar ,numberChar)

    value - 要屏蔽的值。支持的类型:TINYINT,SMALLINT,INT,BIGINT,STRING,VARCHAR,CHAR
    charCount - 字符数。默认值:4   upperChar - 用大写字符替换大写字符的字符。指定-1以保留原始字符。默认值:' lowerChar - 用小写替换小写字符的字符。指定-1以保留原始字符。默认值:'x'
    digitChar - 用数字字符替换的字符。指定-1以保留原始字符。默认值:'  otherChar - 用其替换所有其他字符的字符。指定-1以保留原始字符。默认值:-1
    numberChar - 用数字替换数字的字符。有效值:0-9。默认值:'1'

搬砖多年终不得要领,遂载源码看之望得真经。