排序和聚集
正常在数据少的情况下
直接使用order by来操作即可,因为是全排序所以要在一个reduce中完成
from records
select year,temperature
order by year asc,temperature desc;
如果数据量大,并且不需要全排序,只是需要每个reduce中的数据排序即可。如下根据year来指定(distribute by)到相同的reduce中,然后根据sort by来排序
from records
select year,temperature
distribute by year
sort by year asc,temperature desc;
当然一般如果不用指定排序默认字段是排序asc的且在同一个reduce中
from records
select year,temperature
cluster by year;
--------------------------------------------------
from records
select year,temperature
cluster by year,temperature;
MapReduce脚本
连接
内连接
Hive中的连接就是把我们查询操作根据连接条件解析成对对应的maper的输出key,value就是数据对象关联的两条记录。Reducer去处理连接查询的操作。
数据准备