Search code examples
springjdbchiveset

override hive property in sprint hive jdbc


I want to override some of my hive property values.I am connecting to hive using spring context. Basically i want to execute statement SET hive.auto.convert.join=false; template.execute(splitQuery); but this did not work.
I have also tried by setting this var into jdbc url like this. jdbc:hive2://host:port/default;hive.auto.convert.join=false but this also did not work.

My sprint context.xml is

<?xml version="1.0" encoding="UTF-8"?><beans:beans xmlns="http://www.springframework.org/schema/hadoop" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:c="http://www.springframework.org/schema/c"
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
  http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd">

<context:property-placeholder location="hadoop.properties,hive.properties" />

<configuration>
    fs.defaultFS=${hd.fs}
    yarn.resourcemanager.address=${hd.rm}
    mapreduce.framework.name=yarn
    mapreduce.jobhistory.address=${hd.jh}
</configuration>

<!-- This sample requires a running HiveServer2 -->
<hive-client-factory id="hiveClientFactory" hive-data-source-ref="hiveDataSource" />

<beans:bean id="hiveDriver" class="org.apache.hive.jdbc.HiveDriver" />

<beans:bean id="hiveDataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
    <beans:constructor-arg name="driver" ref="hiveDriver" />
    <beans:constructor-arg name="url" value="${hive.url}" />
    <beans:constructor-arg name="username" value="${hive.user}" />
    <beans:constructor-arg name="password" value="${hive.password}" />
</beans:bean>

<beans:bean id="template" class="org.springframework.jdbc.core.JdbcTemplate" c:data-source-ref="hiveDataSource"/>

<!-- hive-template id="hiveTemplate"/ -->

Can any one suggest any other way? Thanks


Solution

  • you should be able to inject the additional properties as part of the

    https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/AbstractDriverBasedDataSource.java

    it will inject the properties during the driver.connect method. So you should be able to do something like (not tested)

    <bean id="myproperties"
          class="org.springframework.beans.factory.config.PropertiesFactoryBean">
      <property name="properties">
        <value>
            hive.auto.convert.join=false
        </value>
      </property>
    </bean>
    
    <beans:bean id="hiveDataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
        <beans:constructor-arg name="driver" ref="hiveDriver" />
        <beans:constructor-arg name="url" value="${hive.url}" />
        <beans:constructor-arg name="username" value="${hive.user}" />
        <beans:constructor-arg name="password" value="${hive.password}" />
        <property name="connectionProperties" ref="myproperties">
    </property>
    </beans:bean>