Spring 批处理:Hive 不支持的数据库类型



我正在尝试为我的步骤创建一个数据源,它使用Cloudera Hive Server 2驱动程序连接到Hadoop中的表。尽管我在其他用例中使用此驱动程序取得了成功,但尝试在Spring Batch中使用它会吐出此错误:

导致:java.lang.IllegalArgumentException:找不到数据库类型 产品名称:[阿帕奇蜂巢]

我已经在application.yml中创建了一个数据源

spring:
datasource:
url: <URL>
username:
password:
driver-class-name: com.cloudera.hive.jdbc4.HS2Driver

我注意到在DatabaseType.java中找到的列表中不支持此数据库类型。令人沮丧的是,由于其他问题,我无法使用Apache Hive驱动程序进行连接,因此我需要找到一种方法来告诉Spring这是一个有效的连接池,甚至欺骗它认为这是一个mysql连接。

任何想法将不胜感激!

请查看下面的代码,这将使您了解如何实现"Hive-Spring"连接。

使用 Hive JDBC 客户端

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- basic Hive driver bean -->
<bean id="hive-driver" class="org.apache.hadoop.hive.jdbc.HiveDriver"/>
<!-- wrapping a basic datasource around the driver -->
<!-- notice the 'c:' namespace (available in Spring 3.1+) for inlining constructor arguments, 
in this case the url (default is 'jdbc:hive://localhost:10000/default') -->
<bean id="hive-ds" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"
c:driver-ref="hive-driver" c:url="${hive.url}"/>
<!-- standard JdbcTemplate declaration -->
<bean id="template" class="org.springframework.jdbc.core.JdbcTemplate" c:data-source-ref="hive-ds"/>
<context:property-placeholder location="hive.properties"/>
</beans>

运行 Hive 脚本或查询

<hdp:hive-runner id="hiveRunner" run-at-startup="true">
<hdp:script>
DROP TABLE IF EXITS testHiveBatchTable; 
CREATE TABLE testHiveBatchTable (key int, value string);
</hdp:script>
<hdp:script location="hive-scripts/script.q"/>
</hdp:hive-runner>

有关更多详细信息,您可以参考此链接

最新更新