走进大数据丨 Hive常见函数

Hive中常见的SQL函数

  1. 显示HOST地址

    1. select parse_url('地址','HOST')

    2. 实例: select parse_url('http://www.taobao.com/','HOST');

  1. 字符串连接函数

   1)concat()函数 将多个字符串用特定符号链接成一个字符串

 concat(constellation, ",", blood_type,",",字段1,",",字段2,",",字段3)

 select concat(constellation, ",", blood_type, ":", name) from person_info;

  2)concat_ws()函数 将多个字符串用特定符号链接成一个字符串

select concat_ws(",", blood_type, constellation, name) from person_info;

  3) collect_set()函数 将多个字符串用特定符号链接成一个字符串且去除重复元素。

select collect_set(constellation) from person_info;

  1. 显示本地时间戳函数

select unix_timestamp();

select current_timestamp;

  1. 字符串替换函数

将指定字符串替换成另一个字符串

select regexp_replace('www.taobao.com','taobao','tianmao');

  1. 将指定字符串重复指定次数

select repeat('A',3);

  1. 左补足字符串

select lpad('A',5,'B');  ==> BBBBA

  1. 右补足字符串

select rpad('A',5,'B');  ==> ABBBB

  1. 时间函数

select to_date('2019-08-10 15:22:33');  ==> 2019-08-10

  1. 时间格式化处理

select date_format('2017-01-16 09:55:54', 'yyyy-MM-dd');

select date_add('2019-11-10', 7);

select last_day('2019-11-16 09:55:54');

  1. 查看字符串长度

select length("Ab cd");

  1. 返回最大值

select greatest('5','4','1',null);

  1. 生成0到1随机数

select rand()+1;

  1. 字段分割

select split('andy','n');

  1. 开窗函数

select ename,count(*) over() from emp where sal < 1000;

select ename,count(*) over(partition by 某字段 ) from emp where sal < 1000;

走进大数据丨 Hive常见函数