Odps执行SQL报错,提示Please set odps.sql.type.system.odps2=true to use it.

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;
}
相关推荐
_extraordinary_几秒前
Java 类和对象
java·开发语言
Aliano2175 分钟前
TestNGException ClassCastException SAXParserFactoryImpl是Java自带的Xerces解析器——解决办法
java·开发语言·python
进击的小白菜16 分钟前
用Java实现单词搜索(LeetCode 79)——回溯算法详解
java·算法·leetcode
Dreams_l29 分钟前
MySQL初阶:sql事务和索引
数据库·sql·mysql
越来越无动于衷32 分钟前
手写tomcat:基本功能实现(3)
java·tomcat
Uranus^35 分钟前
使用Spring Boot和Spring Security构建安全的RESTful API
java·spring boot·spring security·jwt·restful api
qq_5432485236 分钟前
Tomcat的调优
java·tomcat
Mcworld85742 分钟前
String的一些固定程序函数
java
越来越无动于衷42 分钟前
手写tomcat:基本功能实现(4)
java·tomcat
编程乐学(Arfan开发工程师)44 分钟前
05、基础入门-SpringBoot-HelloWorld
java·spring boot·后端