標籤:
轉自:http://www.iteblog.com/archives/831
如果你想查詢某個表的某一列,Hive預設是會啟用MapReduce Job來完成這個任務,如下:
hive> SELECT id, money FROM m limit 10;Total MapReduce jobs = 1Launching Job 1 out of 1Number of reduce tasks is set to 0 since there‘s no reduce operatorCannot run job locally: Input Size (= 235105473) is larger than hive.exec.mode.local.auto.inputbytes.max (= 134217728)Starting Job = job_1384246387966_0229, Tracking URL = http://l-datalogm1.data.cn1:9981/proxy/application_1384246387966_0229/Kill Command = /home/q/hadoop-2.2.0/bin/hadoop job -kill job_1384246387966_0229hadoop job information for Stage-1: number of mappers: 1; number of reducers: 02013-11-13 11:35:16,167 Stage-1 map = 0%, reduce = 0%2013-11-13 11:35:21,327 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 1.26 sec2013-11-13 11:35:22,377 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 1.26 secMapReduce Total cumulative CPU time: 1 seconds 260 msecEnded Job = job_1384246387966_0229MapReduce Jobs Launched:Job 0: Map: 1 Cumulative CPU: 1.26 sec HDFS Read: 8388865 HDFS Write: 60 SUCCESSTotal MapReduce CPU Time Spent: 1 seconds 260 msecOK1 1221 1851 2311 2921 3161 3291 3551 3561 3621 364Time taken: 16.802 seconds, Fetched: 10 row(s)
我們都知道,啟用MapReduce Job是會消耗系統開銷的。對於這個問題,從Hive0.10.0版本開始,對於簡單的不需要彙總的類似SELECT <col> from <table> LIMIT n語句,不需要起MapReduce job,直接通過Fetch task擷取資料,可以通過下面幾種方法實現:
方法一:
hive> set hive.fetch.task.conversion=more;hive> SELECT id, money FROM m limit 10;OK1 1221 1851 2311 2921 3161 3291 3551 3561 3621 364Time taken: 0.138 seconds, Fetched: 10 row(s)
上面 set hive.fetch.task.conversion=more;開啟了Fetch任務,所以對於上述簡單的列查詢不在啟用MapReduce job!
方法二:
bin/hive --hiveconf hive.fetch.task.conversion=more
方法三:
上面的兩種方法都可以開啟了Fetch任務,但是都是臨時起作用的;如果你想一直啟用這個功能,可以在${HIVE_HOME}/conf/hive-site.xml裡面加入以下配置:
<property> <name>hive.fetch.task.conversion</name> <value>more</value> <description> Some select queries can be converted to single FETCH task minimizing latency.Currently the query should be single sourced not having any subquery and should not have any aggregations or distincts (which incurrs RS), lateral views and joins. 1. minimal : SELECT STAR, FILTER on partition columns, LIMIT only 2. more : SELECT, FILTER, LIMIT only (+TABLESAMPLE, virtual columns) </description></property>
這樣就可以長期啟用Fetch任務了
[轉]Hive:簡單查詢不啟用Mapreduce job而啟用Fetch task