--在下述4种情况下 sql不走mr程序
-- more 模式下如下内容不需要走mr程序
--全局查找
select * from student;
--字段查找
select num,name from student;
--limit 查找
select num,name from student limit 2;
-- 简单的条件过滤
select num,name from student where num > 2;
-- minimal 模式下如下内容不需要走mr程序
--全局查找
select * from student;
--字段查找
select num,name from student;
--limit 查找
select num,name from student limit 2;
-- none 模式下所有的操作都需要走mr程序
mapreduce本地模式 (了解)
功能:如果非要执行MapReduce程序,能够本地执行的,尽量不提交yarn上执行。
默认是关闭的。意味着只要走MapReduce就提交yarn执行。
mapreduce.framework.name = local 本地模式 mapreduce.framework.name = yarn 集群模式
set hive.exec.mode.local.auto = true;
--3个条件必须都满足 自动切换本地模式
The total input size of the job is lower than: hive.exec.mode.local.auto.inputbytes.max (128MB by default) --数据量小于128M
The total number of map-tasks is less than: hive.exec.mode.local.auto.tasks.max (4 by default) --maptask个数少于4个
The total number of reduce tasks required is 1 or 0. --reducetask个数是0 或
--背景:
大表join大表本身数据就十分具体,如果join字段存在null空值 如何处理它?
任何数据和null进行连接,都无法连接成功,所以此时我们会进行空值处理
--方式1:空key的过滤 此行数据不重要 where is not null
参与join之前 先把空key的数据过滤掉
SELECT a.* FROM (SELECT * FROM nullidtable WHERE id IS NOT NULL ) a JOIN ori b ON a.id =b.id;
--方式2:空Key转换
CASE WHEN a.id IS NULL THEN 'xxx任意字符串' ELSE a.id END -- 如果给空值赋值默认值空值数量太大,会造成某个桶的数据量过大
CASE WHEN a.id ='xxx' THEN concat('hive', rand()) ELSE a.id --避免转换之后数据倾斜 随机分布打散
-- 方式3: 对于两张大表中的数据先过滤再连接
-- 不建议
select * from t1 join t2 on t1.id = t2.id and t1.price >1000;
-- 建议
select * from (select * from t1 where price >1000) t1 join t2 on t1.id = t2.id;