Index: jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java =================================================================== --- jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java +++ jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java @@ -124,14 +124,13 @@ Statement stmt = createStatement(); for (Entry hiveConf : connParams.getHiveConfs().entrySet()) { stmt.execute("set " + hiveConf.getKey() + "=" + hiveConf.getValue()); - stmt.close(); } // For remote JDBC client, try to set the hive var using 'set hivevar:key=value' for (Entry hiveVar : connParams.getHiveVars().entrySet()) { stmt.execute("set hivevar:" + hiveVar.getKey() + "=" + hiveVar.getValue()); - stmt.close(); } + stmt.close(); } } Index: jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java =================================================================== --- jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java +++ jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java @@ -49,6 +49,7 @@ import org.apache.hive.service.cli.operation.ClassicTableTypeMapping.ClassicTableTypes; import org.apache.hive.service.cli.operation.HiveTableTypeMapping; import org.apache.hive.service.cli.operation.TableTypeMappingFactory.TableTypeMappings; +import org.apache.hive.service.server.HiveServer2; /** @@ -204,6 +205,55 @@ expectedException); } + // This method tests whether while creating a new connection, + // the config variables specified in the JDBC URI are properly set for the connection. + // This is a test for HiveConnection#configureConnection. + public void testNewConnectionConfiguration() throws Exception { + // Start HiveServer2 with default conf + HiveServer2 hiveServer2 = new HiveServer2(); + hiveServer2.init(new HiveConf()); + hiveServer2.start(); + Thread.sleep(3000); + + // Set some conf parameters + String hiveConf = "hive.cli.print.header=true;hive.server2.async.exec.shutdown.timeout=20;" + + "hive.server2.async.exec.threads=30;hive.server2.thrift.http.max.worker.threads=15"; + // Set some conf vars + String hiveVar = "stab=salesTable;icol=customerID"; + String jdbcUri = "jdbc:hive2://localhost:10000/default" + + "?" + hiveConf + + "#" + hiveVar; + + // Open a new connection with these conf & vars + Connection con1 = DriverManager.getConnection(jdbcUri); + + // Execute "set" command and retrieve values for the conf & vars specified above + // Assert values retrieved + Statement stmt = con1.createStatement(); + + // Verify that the property has been properly set while creating the connection above + verifyConfProperty(stmt, "hive.cli.print.header", "true"); + verifyConfProperty(stmt, "hive.server2.async.exec.shutdown.timeout", "20"); + verifyConfProperty(stmt, "hive.server2.async.exec.threads", "30"); + verifyConfProperty(stmt, "hive.server2.thrift.http.max.worker.threads", "15"); + verifyConfProperty(stmt, "stab", "salesTable"); + verifyConfProperty(stmt, "icol", "customerID"); + con1.close(); + + if(hiveServer2 != null) { + hiveServer2.stop(); + } + } + + private void verifyConfProperty(Statement stmt, String property, String expectedValue) + throws Exception { + ResultSet res = stmt.executeQuery("set " + property); + while(res.next()) { + String resultValues[] = res.getString(1).split("="); + assertEquals(resultValues[1], expectedValue); + } + } + public void testBadURL() throws Exception { checkBadUrl("jdbc:hive2://localhost:10000;principal=test"); checkBadUrl("jdbc:hive2://localhost:10000;" + @@ -1124,7 +1174,7 @@ ResultSet res = stmt.executeQuery( "select c1, c2, c3, c4, c5 as a, c6, c7, c8, c9, c10, c11, c12, " + - "c1*2, sentences(null, null, null) as b, c17, c18, c20, c21 from " + dataTypeTableName + + "c1*2, sentences(null, null, null) as b, c17, c18, c20, c21 from " + dataTypeTableName + " limit 1"); ResultSetMetaData meta = res.getMetaData();