环境相关:
hadoop-2.6.0-cdh5.7.1
hive-1.1.0-cdh5.7.1
IP:192.168.1.10
实验推导
参照文档《hive-1.1.0-cdh5.7.1编译安装部署》,已经部署了hive,并且创建了表helloworld,相关HQL推导过程如下:
hive
select id,name from helloworld;
-- 将id和name连接成列,使用空格分隔,做出“要被分析的表”
select concat(id,' ',name) as str1 from helloworld;
-- 使用split根据空格将表的每一列分裂成一个列表
select split(concat(id,' ',name),' ') as str1 from helloworld;
-- 进一步使用explode,将列表每一个元素变成一行
select explode(split(concat(id,' ',name),' ')) as str1 from helloworld;
-- 以下语法报错,在HQL中不能这么做
select count(explode(split(concat(id,' ',name),' '))) as str1 from helloworld;
-- 将explode出来的数据做成子表,然后再count是可以的
select * from (select explode(split(concat(id,' ',name),' ')) from helloworld) as word;
select count(*) from (select explode(split(concat(id,' ',name),' ')) from helloworld) as word;
exit;
# 可以看出HQL和SQL还是有一些差异的
[TOC]