1、select语句
HiveQL一般是用本地模式执行,但涉及到聚合函数之类的就会启动MapReduce任务。可以设置hive.exec.mode.local.auto为true,其他操作也会尽量走本地模式。
select id, name from cast;
-- 依次获取字符串、集合元素(Array)、Map元素、Struct对象
select name, subordinates[0], deductions['State Taxes'], address.city from employee limit 3;
-- 匹配所有以price为前缀的列名,但我本地测试并不成功...
select symbol, `price.*` from stocks;
-- 列值计算、算术计算、简单函数、聚合函数等
select round(price_close) from stocks;
-- 默认是只能执行一个count(distinct)函数
select count(distinct symbol) from stocks;
-- 表生成函数:将每个元素都拆成新的记录,跟聚合函数相反
select explode(subordinates) from employee;
select parse_url_tuple('https://google.com/search?q=rick+and+morty','HOST','PATH','QUERY') AS (HOST,PATH,QUERY);
-- 嵌套子查询
from (
select upper(name), round(salary*(1-deductions['Federal Taxes'])) as salary_with_tax
from employee
) e
select e.name, e.salary_with_tax
where e.salary_

本文介绍了HiveQL的基本查询操作,包括select、where、group by...having语句、join、排序、抽样查询、数据库抽样以及分桶表的输入裁剪。重点讲解了各种查询方式的特性和注意事项,例如where语句中浮点数比较的陷阱,join的执行策略,以及如何利用order by、sort by和distribute by进行排序。此外,还提到了分桶抽样和数据库抽样的应用场景,以及如何通过tablesample进行输入裁剪以提高效率。
最低0.47元/天 解锁文章
153

被折叠的 条评论
为什么被折叠?



