分享

Hive快捷查询:不启用Mapreduce job启用Fetch task三种方式介绍

hyj 2014-4-19 20:04:48 发表于 总结型 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 10 49555
问题导读:
1.什么情况下,可以不启用MapReduce Job?
2.方法1通过什么方式,不启用job?
3.bin/hive --hiveconf hive.fetch.task.conversion=more的作用是什么?
4.如果一直开启不使用MapReduce Job,该如何配置?







如果你想查询某个表的某一列,Hive默认是会启用MapReduce Job来完成这个任务,如下:
  1. hive> SELECT id, money FROM m limit 10;
  2. Total MapReduce jobs = 1
  3. Launching Job 1 out of 1
  4. Number of reduce tasks is set to 0 since there's no reduce operator
  5. Cannot run job locally: Input Size (= 235105473) is larger than
  6. hive.exec.mode.local.auto.inputbytes.max (= 134217728)
  7. Starting Job = job_1384246387966_0229, Tracking URL =
  8. http://l-datalogm1.data.cn1:9981/proxy/application_1384246387966_0229/
  9. Kill Command = /home/q/hadoop-2.2.0/bin/hadoop job  
  10. -kill job_1384246387966_0229
  11. hadoop job information for Stage-1: number of mappers: 1;
  12. number of reducers: 0
  13. 2013-11-13 11:35:16,167 Stage-1 map = 0%,  reduce = 0%
  14. 2013-11-13 11:35:21,327 Stage-1 map = 100%,  reduce = 0%,
  15. Cumulative CPU 1.26 sec
  16. 2013-11-13 11:35:22,377 Stage-1 map = 100%,  reduce = 0%,
  17. Cumulative CPU 1.26 sec
  18. MapReduce Total cumulative CPU time: 1 seconds 260 msec
  19. Ended Job = job_1384246387966_0229
  20. MapReduce Jobs Launched:
  21. Job 0: Map: 1   Cumulative CPU: 1.26 sec   
  22. HDFS Read: 8388865 HDFS Write: 60 SUCCESS
  23. Total MapReduce CPU Time Spent: 1 seconds 260 msec
  24. OK
  25. 1       122
  26. 1       185
  27. 1       231
  28. 1       292
  29. 1       316
  30. 1       329
  31. 1       355
  32. 1       356
  33. 1       362
  34. 1       364
  35. Time taken: 16.802 seconds, Fetched: 10 row(s)
复制代码

 我们都知道,启用MapReduce Job是会消耗系统开销的。对于这个问题,从Hive0.10.0版本开始,对于简单的不需要聚合的类似SELECT <col> from <table> LIMIT n语句,不需要起MapReduce job,直接通过Fetch task获取数据,可以通过下面几种方法实现:

方法一:
  1. hive> set hive.fetch.task.conversion=more;
  2. hive> SELECT id, money FROM m limit 10;
  3. OK
  4. 1       122
  5. 1       185
  6. 1       231
  7. 1       292
  8. 1       316
  9. 1       329
  10. 1       355
  11. 1       356
  12. 1       362
  13. 1       364
  14. Time taken: 0.138 seconds, Fetched: 10 row(s)
复制代码

上面 set hive.fetch.task.conversion=more;开启了Fetch任务,所以对于上述简单的列查询不在启用MapReduce job!

方法二:

  1. bin/hive --hiveconf hive.fetch.task.conversion=more
复制代码

方法三:
上面的两种方法都可以开启了Fetch任务,但是都是临时起作用的;如果你想一直启用这个功能,可以在${HIVE_HOME}/conf/hive-site.xml里面加入以下配置:

  1. <property>
  2.   <name>hive.fetch.task.conversion</name>
  3.   <value>more</value>
  4.   <description>
  5.     Some select queries can be converted to single FETCH task
  6.     minimizing latency.Currently the query should be single
  7.     sourced not having any subquery and should not have
  8.     any aggregations or distincts (which incurrs RS),
  9.     lateral views and joins.
  10.     1. minimal : SELECT STAR, FILTER on partition columns, LIMIT only
  11.     2. more    : SELECT, FILTER, LIMIT only (+TABLESAMPLE, virtual columns)
  12.   </description>
  13. </property>
复制代码
这样就可以长期启用Fetch任务了,很不错吧,也赶紧去试试吧!





已有(10)人评论

跳转到指定楼层
mvs2008 发表于 2015-7-2 17:16:37
什么情况下用fetch task,什么时候用mapreduce呢?
可以稍微说下吗?@hyj
回复

使用道具 举报

tec_feng 发表于 2015-1-28 17:49:33
非常不错的功能
回复

使用道具 举报

zpcandzhj 发表于 2015-7-5 21:17:34
什么时候要用MapReduce。什么时候直接取数据呢?
回复

使用道具 举报

muyannian 发表于 2015-7-5 21:27:45
zpcandzhj 发表于 2015-7-5 21:17
什么时候要用MapReduce。什么时候直接取数据呢?

select * from table
select * from table limit
不会执行mapreduce,直接读取文件

回复

使用道具 举报

muyannian 发表于 2015-7-5 21:28:53
mvs2008 发表于 2015-7-2 17:16
什么情况下用fetch task,什么时候用mapreduce呢?
可以稍微说下吗?@hyj

select * from table
select * from table limit
不会执行mapreduce,直接读取文件
回复

使用道具 举报

mvs2008 发表于 2015-7-6 08:37:07
muyannian 发表于 2015-7-5 21:28
select * from table
select * from table limit
不会执行mapreduce,直接读取文件

select * from table [limit]确实会启用fetch task。我只是想知道具体什么时候用fetch task。网上说了下,简单查询的时候启用fetch task比较省资源。
回复

使用道具 举报

12下一页
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条