在hive里面可以通过严格模式防止用户执行那些可能产生意想不到的不好的效果的查询,从而保护hive的集群。
用户可以通过 set hive.mapred.mode=strict 来设置严格模式,改成unstrict则为飞严格模式。 在严格模式下,用户在运行如下query的时候会报错。
1. 分区表的查询没有使用分区字段来限制。
select * from strategy.log where and id = "180843496599928148";
报错
ERROR: org.apache.hive.service.cli.HiveSQLException : Error while compiling statement: FAILED: SemanticException [Error 10041]: No partition predicate found for Alias "m_loss_prediction_log" Table "m_loss_prediction_log"
有异常抛出,执行结束。
指定分区:
select * from strategy.log where dt = "2018-08-16" and id = "123";
错误消除。
2. 使用了笛卡尔积
当用户写代码将表的别名写错的时候会引起笛卡尔积,例如
SELECT *
FROM origindb.promotion__campaign c
JOIN origindb.promotion__campaignex ce
ON c.id = c.id
limit 1000
3. order by 的时候没有使用limit
SELECT *
FROM origindb.promotion__campaign
order by id
当使用的limit的时候错误消除。