Hive 严格模式设置

Hive 在早期使用参数 hive.mapred.mode 来决定是否执行严格模式, 其值为 strict 或者 nostrict. 当其值为 strict 时,执行严格模式,如从分区表查询时,过滤条件必须有分区字段。

在 Hive 3.1.3 中,因为 hive.mapred.mode 比较粗暴,为了能更好的在不同地方是否严格模式,在不同的地方用各自的参数。

为了使用不同的参数,hive.mapred.mode 已经被废弃,不能设置,如果设置了,则以 hive.mapred.mode 值为准,新的参数不生效。

新的参数值为 boolean 型, 值可以为 true 和 false。

严格模式的参数如下:

1. hive.strict.checks.orderby.no.limit

是否禁止 order by 后没有 limit 的操作。

注意:当前检查不考虑数据量,仅从 query 的语法上检查。

示例:

hive.strict.checks.orderby.no.limittrue 时,以下查询不能执行。

sql 复制代码
select c1, c2 from t order by c1;

必须有 limit 部分,如以下 query 可以执行。

sql 复制代码
select c1, c2 from t order by c1 limit 100;

2. hive.strict.checks.no.partition.filter

是否禁止查询分区表没有分区字段的过滤操作。

注意:当前检查不考虑数据量,仅从 query 的语法上检查。

如表 t 有分区字段 pc1, pc2。

hive.strict.checks.no.partition.filter=true 时,以下查询不能执行。

sql 复制代码
select c1, sum(c2) 
from t 
where c3 > 100 
group by c1 ;

必须加上至少一个分区字段, 如以下 query 可以执行。

sql 复制代码
select c1, sum(c2) 
from t 
where c3 > 100 
    and pt1='aaa' 
group by c1 ;

3. hive.strict.checks.type.safety

执行严格的类型检查,当开启时,禁止以下操作:

bigint 和 string 类型的比较。

bigint 和 double 类型的比较。

开启时,执行以下 Query 会报错。

sql 复制代码
create table t1(c_bigint bigint, c_string string, c_double double);

开启时,执行以下查询会有警告WARNING: Comparing a bigint and a double may result in a loss of precision.

sql 复制代码
select * from t1 where c_bigint > c_double;

4. hive.strict.checks.cartesian.product

开启时,禁止迪卡尔积关联。

sql 复制代码
select * from t1 join t2;

需要加上关联条件,可以用 on 或者 where 部分都可以。

如以下 Query 都可以

sql 复制代码
select * from t1 join t2 
on t1.c1=t2.c1;

select * from t1 join t2 
where t1.c1=t2.c1;

5. hive.strict.checks.bucketing

开启时,禁用对 bucketing 表执行 load into 操作。

相关推荐
Vin0sen19 小时前
Hadoop安装
大数据·hadoop·分布式
AllData公司负责人20 小时前
AllData数据中台集成开源项目Apache Doris建设实时数仓平台
java·大数据·数据库·数据仓库·apache doris·实时数仓平台·doris集群
隐于花海,等待花开21 小时前
HIVE日期函数大全
数据仓库·hive·hadoop
juniperhan21 小时前
Flink 系列第9篇:Flink 重启策略详解
java·大数据·数据仓库·flink
隐于花海,等待花开2 天前
FIND_IN_SET 与 LIKE 函数:使用场景及性能对比
hive
夕除2 天前
javaweb--04
数据仓库·hive·hadoop
juniperhan3 天前
Flink 系列第4篇:Flink 时间系统与 Timer 定时器实战精讲
java·大数据·数据仓库·flink
juniperhan3 天前
link 系列第7篇:Flink 状态管理全解析(原理+类型+存储+实操)
大数据·数据仓库·flink
juniperhan3 天前
Flink 系列第6篇:Watermark 水印全解析(原理+实操+避坑)
大数据·数据仓库·flink
武子康3 天前
大数据-264 实时数仓-MySQL Binlog配置详解:从原理到实践|数据恢复与主从复制实战
大数据·hadoop·后端