hadoop学习笔记之HiveSQL 数据查询

本文是关于Hadoop学习的笔记,重点介绍了HiveSQL在数据查询中的应用,包括子查询的使用以及UDF, UDAF, UDTF等函数的讲解。同时提到了Hive中floor, round和ceil函数对double类型处理以及时间处理函数的参数要求。" 80826949,7790950,Python数据分析:Numpy与Pandas常用函数速查,"['Python', '数据分析', 'Numpy', 'Pandas']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

数据查询


select [all | distinct] select_expr, ...
from table_reference
[where where_condition]
[group by col_list]
[cluster by col_list] | [distribute by col_list] [sort by col_list]
[limit number]


查找正则表达式的列:
select '(ds|dh)? +.+' from sales


多路group by 
from pv_users
insert overwrite table pr_gender_sum
select pv_users.gender, count(distinct pv_users.userid)
group by pv_users.gender
insert overwrite directory '/路径'
select pv_users.age, count(distinct pv_users.userid)
group by pv_users.age




区别
order by全局排序
sort by 保证reducer输出有序
distribute by 将数据分到同个reducer
cluster by = distribute by+ sort by




JOIN
内关联:select a.* from a join b on (a.id=b.id)
外关联:select a.val, b.val  from a left[right|full] outer join b on (a.key=b.key)
where写法:select * from table1 t1, talbe2 t2, table3 t3 where t1.id=t2.id and t2.id=t3.id and t1.zipcode='0000';


改写IN语句
select a.key, a.val from a left semi join b on (a.key=b.key)


注意:
/* + streamtable(a) */ 指定大表为a 防止这个表放入内存
/* + mapjoin(a) */ 指定小表,放入内存做mapjoin
union all


虚拟列:
input_file_name
block_offset_inside_file


子查询
subqueries in the from clause

subqueries in the where clause



函数UDF,UDAF,UDTF
详见技术文档

附:
floor, round和ceil是会将double转换为bigint
时间处理函数要传入integer或string作为参数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值