查询某个表的某一列,Hive默认是会启用MapReduce来完成这个任务,如下:
hive> SELECT uid, number FROM test limit 9;
Total MapReduce CPU Time Spent: 2 seconds 320 msec
OK
1 12
2 15
3 21
4 22
5 26
6 29
7 32
8 36
9 39
Time taken: 24.108 seconds, Fetched: 9 row(s)
启用MapReduce会消耗系统性能。从Hive0.10.0版本开始,对于简单的不需要聚合的类似SELECT <column> from <table> LIMIT num语句,不需要起MapReduce job,直接通过Fetch task 本地获取数据,有几种方法实现:
方法一:
hive> set hive.fetch.task.conversion=more;
hive> SELECT uid, number FROM test limit 9;
OK
1 12
2 15
3 21
4 22
5 26
6 29
7 32
8 36
9 39
Time taken: 0.258 seconds, Fetched: 9 row(s)
以上set hive.fetch.task.conversion=more;开启Fetch task,不在启用MapReduce job
方法二:
#hive --hiveconf hive.fetch.task.conversion=more
方法三:
以上两种方法都可以开启Fetch task,但是都是临时的;如果想一直启用这个功能,需要在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>
hive> SELECT uid, number FROM test limit 9;
Total MapReduce CPU Time Spent: 2 seconds 320 msec
OK
1 12
2 15
3 21
4 22
5 26
6 29
7 32
8 36
9 39
Time taken: 24.108 seconds, Fetched: 9 row(s)
启用MapReduce会消耗系统性能。从Hive0.10.0版本开始,对于简单的不需要聚合的类似SELECT <column> from <table> LIMIT num语句,不需要起MapReduce job,直接通过Fetch task 本地获取数据,有几种方法实现:
方法一:
hive> set hive.fetch.task.conversion=more;
hive> SELECT uid, number FROM test limit 9;
OK
1 12
2 15
3 21
4 22
5 26
6 29
7 32
8 36
9 39
Time taken: 0.258 seconds, Fetched: 9 row(s)
以上set hive.fetch.task.conversion=more;开启Fetch task,不在启用MapReduce job
方法二:
#hive --hiveconf hive.fetch.task.conversion=more
方法三:
以上两种方法都可以开启Fetch task,但是都是临时的;如果想一直启用这个功能,需要在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>