1、pom依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>2.3.8</version>
</dependency>
2、配置文件
spring.datasource.dynamic.hive.driver-class-name=org.apache.hive.jdbc.HiveDriver
spring.datasource.dynamic.hive.url=jdbc:hive2://192.168.0.1:10000/user
spring.datasource.dynamic.hive.username=root
spring.datasource.dynamic.hive.password=root12345
spring.datasource.dynamic.hive.druid.filters=stat,slf4j
3、entity实体类
import lombok.Data;
import java.io.Serializable;
@Data
public class HiveSql implements Serializable {
private static final long serialVersionUID = 1L;
}
4、mapper
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lydms.entity.HiveSql;
@DS("hive")
public interface HiveSqlMapper extends BaseMapper<HiveSql> {
@SqlParser(filter = true)
void explainQuery(String sql);
}
5、mapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lydms.mapper.HiveSqlMapper">
<update id="explainQuery">
${templateName,jdbcType=VARCHAR}
</update>
</mapper>
6、service使用
import com.lydms.mapper.HiveSqlMapper;
import com.lydms.entity.HiveSql;
@Autowired
private HiveSqlMapper hiveSqlMapper;
@Override
public R<String> checkSqlRule(String sql) {
hiveSqlMapper.explainQuery(sql);
}
7、可能遇到的问题
dbType not support : sqlite :
解决:
配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall’用于防火墙(启动sqlite时候需要关闭wall)。把filters中的stat,wall,slf4j 改成stat,slf4j
spring.datasource.dynamic.hive.druid.filters=stat,slf4j
参考连接:
http://www.zyiz.net/tech/detail-143690.html
|