Fetch抓取
hive中对某些情况的查询可以不用MapReduce计算。例如select * from emp,可以简单的读取emp文件,输出结果。
在hive-default.xml.template文件中的hive.fetch.task.conversion默认为more,老版本默认为minimal。该值设为more后,在全局查找、字段查找和limit查找等都不使用MapReduce。
<property> <name>hive.fetch.task.conversion</name> <value>more</value> <description> Expects one of [none, minimal, more]. 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 incurs RS), lateral views and joins. 0. none : disable hive.fetch.task.conversion 1. minimal : SELECT STAR, FILTER on partition columns, LIMIT only 2. more : SELECT, FILTER, LIMIT only (support TABLESAMPLE and virtual columns) </description> </property>
hive>set hive.fetch.task.conversion=more; hive>select * from emp; hive>select name from emp; hive>select name from emp limit 3; #以上在将值设为more后,都不会执行MapReduce,设为none,都会执行MapReduce。
本地模式
大多数hadoop job是需要hadoop提供完整的可拓展性来处理大数据集的,不过,有时hive的输入数据量比较小。在这种情况下,为查询触发任务消耗的时间可能比实际job执行时间多的多。对这种情况,hive可以通过本地模式在单台机器上处理所有的任务,对于小数据集,执行时间被明显缩短。
通过设置hive.exec.mode.local.auto的值为true,让hive在适当的时候自动启用这个优化。
# 开启本地mr hive>set hive.exec.mode.local.auto=true; # 设置local mr的最大输入数据量,当输入数据量小于这个值时,采用local mr,默认134217728,即128M hive>set hive.exec.mode.local.auto.inputbytes=50000000; # 设置local mr的最大输入文件个数,当输入文件个数小于这个值时,采用loacl mr,默认4 hive>set hive.exec.mode.local.auto.input.files.max=10;
1)开启本地模式,并执行查询语句
hive (default)> set hive.exec.mode.local.auto=true; hive (default)> select * from emp cluster by deptno; Time taken: 1.328 seconds, Fetched: 14 row(s)
2)关闭本地模式,并执行查询语句
hive (default)> set hive.exec.mode.local.auto=false; hive (default)> select * from emp distribute by deptno; Time taken: 20.09 seconds, Fetched: 14 row(s)
严格模式
防止用户执行那些可能意向不到的不好的影响的查询。
设置属性hive.mapred.mode的值,默认为nonstrict(非严格模式)。当值为strict时,为严格模式,会禁止特定的查询。
<property> <name>hive.mapred.mode</name> <value>strict</value> <description> The mode in which the Hive operations are being performed. In strict mode, some risky queries are not allowed to run. They include: Cartesian Product. No partition being picked up for a query. Comparing bigints and strings. Comparing bigints and doubles. Orderby without limit. </description> </property>
对于使用了order by语句的查询,要求必须使用limit语句。因为order by为了执行排序过程会将所有的数据发送个同一个reducer进行处理。强制要求用户增加这个limit语句可以防止reducer额外执行很长一段时间。
限制笛卡尔积的查询。