Odps执行SQL报错,提示Please set odps.sql.type.system.odps2=true to use it.
或提示Please add put { "odps.sql.submit.mode" : "script"} for multi-statement query in settings
的解决方案
odps错误信息
java
AnonymousSQLTask--ODPS-0130071:[1,474] Semantic analysis exception - DATE type is not enabled in current mode.
Please set odps.sql.type.system.odps2=true to use it.
ODPS-0130071:[1,1165] Semantic analysis exception - DATE type is not enabled in current mode.
Please set odps.sql.type.system.odps2=true to use it.
// 或提示下面的错误信息
com.aliyun.odps.OdpsException:
Please add put { "odps.sql.submit.mode" : "script"} for multi-statement query in settings
解决方案:
在执行task前,将上面的配置信息增加进hints中
java
public Instance sqlRunTable(String sql) throws OdpsException {
Map<String, String> hints = new HashMap<>();
hints.put("odps.sql.submit.mode", "script");
hints.put("odps.sql.type.system.odps2", "true");
SQLTask.setDefaultHints(hints);
Instance instance = SQLTask.run(odps, sql);
if (!instance.isSync()) {
instance.waitForSuccess();
}
if (!instance.isSuccessful()) {
log.error("ODPS执行SQL语句失败!{}", sql);
for (String key : instance.getTaskResults().keySet()) {
log.error("{}--{}", key, instance.getTaskResults().get(key));
}
}
return instance;
}