spring批处理:配置单元的数据库类型不受支持

f3temu5u  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(287)

我正在尝试为我的步骤创建一个数据源,它使用cloudera HiveServer2驱动程序连接到hadoop中的表。虽然我在其他用例中成功地使用了这个驱动程序,但尝试在spring批处理中使用它会发现以下错误:
原因:java.lang.illegalargumentexception:找不到产品名为[apache hive]的databasetype
我在application.yml中创建了一个数据源

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

我注意到在中找到的列表中不支持此数据库类型 DatabaseType.java . 令人沮丧的是,由于其他问题,我无法将apache配置单元驱动程序用于我的连接,因此我需要找到一种方法来告诉spring这是一个有效的连接池,甚至欺骗它,使其认为这是一个mysql连接。
任何想法都将不胜感激!

a14dhokn

a14dhokn1#

请看下面的代码,这将给你如何实现“HiveSpring”连接的想法。
使用HiveJDBC客户机

<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>

运行配置单元脚本或查询

<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>

有关更多详细信息,请参阅此链接

相关问题