(详细)解决hive报错FAILED: SemanticException Cartesian products are disabled for safety的问题

在使用hive-2.3.3执行TPC-H benchmark时,遇到hive报错。而且这个错误不是以Java异常栈的形式跑出的,很可能被忽略:

FAILED: SemanticException Cartesian products are disabled for safety reasons. If you know what you are doing, please sethive.strict.checks.cartesian.product to false and that hive.mapred.mode is not set to 'strict' to proceed. Note that if you may get errors or incorrect results if you make a mistake while using some of the unsafe features.

查阅网上资料,发现有两种方法。

方式一:通过hive shell 模式设置相关变量
通过hive 命令开启hive shell 模式,输入以下命令进行设置:

hive> set hive.mapred.mode;   # 首先查看hive.mapred.mode
hive.mapred.mode=strict
hive> set hive.mapred.mode=nonstrict;   # 设置hive.mapred.mode为nonstrict
hive> set hive.mapred.mode;   # 查看hive.mapred.mode是否设置成功
hive.mapred.mode=nonstrict
hive> set hive.strict.checks.cartesian.product;   # 首先查看hive.strict.checks.cartesian.product
hive.strict.checks.cartesian.product=true
hive> set hive.strict.checks.cartesian.product=false;   # 设置hive.strict.checks.cartesian.product为false
hive> set hive.strict.checks.cartesian.product;    # 查看hive.strict.checks.cartesian.product是否设置成功
hive.strict.checks.cartesian.product=false

方式二:在hive-site.xml中设置相关变量
hive-site.xml文件中,加入新的设置:

 
	  hive.mapred.mode 
	  nonstrict 
	  The mode in which the hive operations are being performed. In strict mode, some risky queries are not allowed to run 

 
        hive.strict.checks.cartesian.product 
        false

由于都是处于尝试修改错误,所以都不知道自己究竟是使用哪种方法解决了这个错误的。下次再配置hive,建议一开始就在hive-site.xml中添加上面的内容。如果还会报错,再尝试方法一!

参考链接:
hive参数hive.mapred.mode分析
一例 Hive join 优化实战----8和9两点
hive strict模式-----重点参考
How allow hive.mapred.mode=nonstrict?
hive 非等值连接, 设置hive为nonstrict模式
STRICT MODE VS NON-STRICT MODE IN HIVE OR STATIC PARTITION VS DYNAMIC PARTITION IN HIVE?

你可能感兴趣的:(Hive)