好程序员大数据学习路线hive内部函数

图灵完备者
• 阅读 131

好程序员大数据学习路线hive内部函数,持续为大家更新了大数据学习路线,希望对正在学习大数据的小伙伴有所帮助。
1、取随机数函数:rand()
语法: rand(),rand(int seed) 返回值: double 说明: 返回一个0到1范围内的随机数。如果指定seed,则会得到一个稳定的随机数序列
select rand();
select rand(10);
2、分割字符串函数:split(str,splitor)
语法: split(string str, string pat) 返回值: array 说明: 按照pat字符串分割str,会返回分割后的字符串数组,注意特殊分割符的转义
select split(5.0,".")[0];
select split(rand(10)*100,".")[0];
3、字符串截取函数:substr,substring
语法: substr(string A, int start),substring(string A, int start) 返回值: string 说明:返回字符串A从start位置到结尾的字符串
语法: substr(string A, int start, int len),substring(string A, int start, int len) 返回值: string 说明:返回字符串A从start位置开始,长度为len的字符串
select substr(rand()*100,0,2);
select substring(rand()*100,0,2);
4、If函数:if
语法: if(boolean testCondition, T valueTrue, T valueFalseOrNull) 返回值: T 说明: 当条件testCondition为TRUE时,返回valueTrue;否则返回valueFalseOrNull
select if(100>10,"this is true","this is false");
select if(2=1,"男","女");
select if(1=1,"男",(if(1=2,"女","不知道")));
select if(3=1,"男",(if(3=2,"女","不知道")));
5、条件判断函数:CASE
第一种格式:
语法: CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END 返回值: T 说明:如果a为TRUE,则返回b;如果c为TRUE,则返回d;否则返回e
第二种格式:
语法: CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END 返回值: T 说明:如果a等于b,那么返回c;如果a等于d,那么返回e;否则返回f
select
case 6
when 1 then "100"
when 2 then "200"
when 3 then "300"
when 4 then "400"
else "others"
end
;

创建表

create table if not exists cw(
flag int
)
;
load data local inpath '/home/flag' into table cw;

第一种格式

select
case c.flag
when 1 then "100"
when 2 then "200"
when 3 then "300"
when 4 then "400"
else "others"
end
from cw c
;

第二种格式

select
case
when 1=c.flag then "100"
when 2=c.flag then "200"
when 3=c.flag then "300"
when 4=c.flag then "400"
else "others"
end
from cw c
;
6、正则表达式替换函数:regexp_replace
语法: regexpreplace(string A, string B, string C) 返回值: string 说明:将字符串A中的符合java正则表达式B的部分替换为C。注意,在有些情况下要使用转义字符,类似oracle中的regexpreplace函数
select regexp_replace("1.jsp",".jsp",".html");
7、类型转换函数: cast
语法: cast(expr as ) 返回值: Expected "=" to follow "type" 说明: 返回转换后的数据类型
select 1;
select cast(1 as double);
select cast("12" as int);
8、字符串连接函数:concat;带分隔符字符串连接函数:concat_ws
语法: concat(string A, string B…) 返回值: string 说明:返回输入字符串连接后的结果,支持任意个输入字符串
语法: concat_ws(string SEP, string A, string B…) 返回值: string 说明:返回输入字符串连接后的结果,SEP表示各个字符串间的分隔符
select "千峰" + 1603 + "班级";
select concat("千峰",1603,"班级");
select concat_ws("|","千峰","1603","班级");
9、排名函数:
rownumber(): 名次不并列 rank():名次并列,但空位 denserank():名次并列,但不空位

数据

id class score
1 1 90
2 1 85
3 1 87
4 1 60
5 2 82
6 2 70
7 2 67
8 2 88
9 2 93

1 1 90 1
3 1 87 2
2 1 85 3
9 2 93 1
8 2 88 2
5 2 82 3

create table if not exists uscore(
uid int,
classid int,
score double
)
row format delimited fields terminated by 't'
;
load data local inpath '/home/uscore' into table uscore;
select
u.uid,
u.classid,
u.score
from uscore u
group by u.classid,u.uid,u.score
limit 3
;
select
u.uid,
u.classid,
u.score,
row_number() over(distribute by u.classid sort by u.score desc) rn
from uscore u
;
取前三名
select
t.uid,
t.classid,
t.score
from
(
select
u.uid,
u.classid,
u.score,
row_number() over(distribute by u.classid sort by u.score desc) rn
from uscore u
) t
where t.rn < 4
;
查看三个排名区别
select
u.uid,
u.classid,
u.score,
row_number() over(distribute by u.classid sort by u.score desc) rn,
rank() over(distribute by u.classid sort by u.score desc) rank,
dense_rank() over(distribute by u.classid sort by u.score desc) dr
from uscore u
;
10.聚合函数:
min() max() count() count(distinct ) sum() avg()
count(1):不管正行有没有值,只要出现就累计1 count(*):正行值只要有一个不为空就给类计1 count(col):col列有值就累计1 count(distinct col):col列有值并且不相同才累计1
11.null值操作
几乎任何数和 NULL操作都返回NULL
select 1+null;
select 1/0;
select null%2;
12.等值操作
select null=null; #null
select null<=>null;#true

点赞
收藏
评论区
推荐文章
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
liam liam
2年前
Mock 语法讲解
是生成随机数据,拦截Ajax请求的JavaScript库。本文来介绍下Mock的常用语法。模拟数据生成随机数据Mock.Random.boolean()生成一个随机的布尔值。例如:返回值为true或false。Mock.Random.integer(min
Wesley13 Wesley13
3年前
java学习过程
一、序JAVA的学习路线,在网上可以看到一大堆学习路线的图片,那么当我们学习了基本语言语法,常用的开发工具,常用的集成框架之后满足了现有的公司的项目需求,可以轻松应付日常所见的开发任务,一段时间后我发现工作就只剩下了增删改查,即时有新框架需要熟悉,也是马上拿过来按旧有的流程改造一同,实现一个特定的需求
Stella981 Stella981
3年前
Hive内部表和外部表的区别详解
内部表&外部表未被external修饰的是内部表(managedtable),被external修饰的为外部表(externaltable);区别:内部表数据由Hive自身管理,外部表数据由HDFS管理;内部表数据存储的位置是hive.metastore.warehouse.dir(默认:/user/hive/warehouse)
Wesley13 Wesley13
3年前
mysql中时间比较的实现
MySql中时间比较的实现unix\_timestamp()unix\_timestamp函数可以接受一个参数,也可以不使用参数。它的返回值是一个无符号的整数。不使用参数,它返回自1970年1月1日0时0分0秒到现在所经过的秒数,如果使用参数,参数的类型为时间类型或者时间类型的字符串表示,则是从1970010100:00:0
Stella981 Stella981
3年前
HIVE 时间操作函数
日期函数UNIX时间戳转日期函数: from\_unixtime语法:   from\_unixtime(bigint unixtime\, string format\)返回值: string说明: 转化UNIX时间戳(从19700101 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式举例:hive   selec
Wesley13 Wesley13
3年前
MySQL中的数值函数
常用数值函数函  数功  能ABS(x)返回数值x的绝对值CEIL(x)返回大于或等于x的最小整数值FLOOR(x)返回小于或等于x的最大整数值MOD(x,y)返回x除以y的余数RAND()返回0~1内的随机数ROUND(x,y)返回x四舍五入后有y位小数的数值TRUNCATE(
Wesley13 Wesley13
3年前
mysql——GROUP BY和HAVING
GROUPBY语法可以根据给定数据列的每个成员对查询结果进行分组统计,最终得到一个分组汇总表。select子句中的列名必须为分组列或列函数,列函数对于groupby子句定义的每个组返回一个结果。某个员工信息表结构和数据如下:  id  name  dept  salary  edlevel     hiredate   1  张
Wesley13 Wesley13
3年前
HarmonyOS三方件开发指南(13)
鸿蒙入门指南,小白速来!0基础学习路线分享,高效学习方法,重点答疑解惑【课程入口】(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fharmonyos.51cto.com%2Factivity%2F43%23kyzg)目录:1\.SwipeLayou
美凌格栋栋酱 美凌格栋栋酱
5个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(