9.6 严格模式

Hive 提供了一个严格模式,可以防止用户执行那些可能带来意想不到的不好的影响的查询。

hive.mapred.mode 默认是 nonestrict, 修改为 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>

1) 对于分区表,除非where语句中含有分区字段过滤条件来限制范围,否则不允许执行。换句话说,就是用户不允许扫描所有分区。进行这个限制的原因是,通常分区表都拥有非常大的数据集,而且数据增加迅速。没有进行分区限制的查询可能会消耗令人不可接受的巨大资源来处理这个表。

2)对于使用了order by语句的查询,要求必须使用limit语句。因为order by为了执行排序过程会将所有的结果数据分发到同一个Reducer中进行处理,强制要求用户增加这个LIMIT语句可以防止Reducer额外执行很长一段时间。

3)限制笛卡尔积的查询。对关系型数据库非常了解的用户可能期望在执行JOIN查询的时候不使用ON语句而是使用where语句,这样关系数据库的执行优化器就可以高效地将WHERE语句转化成那个ON语句。不幸的是,Hive并不会执行这种优化,因此,如果表足够大,那么这个查询就会出现不可控的情况。


在2.x 新版本中上面属性被标记为过时了, 使用hive.strict.checks.* 系列属性来代替:

<property>
  <name>hive.strict.checks.large.query</name>
  <value>false</value>
  <description>
    Enabling strict large query checks disallows the following:
      Orderby without limit.
      查询分区表单的时候没有使用分区
      No partition being picked up for a query against partitioned table.
      不考虑数据量, 仅仅考虑查询模式
    Note that these checks currently do not consider data size, only the query pattern.
  </description>
</property>
<property>
  <name>hive.strict.checks.type.safety</name>
  <value>true</value>
  <description>
    Enabling strict type safety checks disallows the following:
      bigint和字符串比较
      Comparing bigints and strings.
      bigintdouble比较
      Comparing bigints and doubles.
  </description>
</property>
<property>
  <name>hive.strict.checks.cartesian.product</name>
  <value>true</value>
  <description>
    Enabling strict Cartesian join checks disallows the following:
      不允许笛卡尔积
      Cartesian product (cross join).
  </description>
</property>
<property>
  <name>hive.strict.checks.bucketing</name>
  <value>true</value>
  <description>
    Enabling strict bucketing checks disallows the following:
      向分桶表加载数据
      Load into bucketed tables.
  </description>
</property>

Copyright © 尚硅谷大数据 2019 all right reserved,powered by Gitbook
该文件最后修订时间: 2019-03-16 07:15:56

results matching ""

    No results matching ""