use of java.sql.Connection in project hive by apache.
the class TestJdbcWithLocalClusterSpark method createDb.
// setup DB
private static void createDb() throws Exception {
Connection conn = DriverManager.getConnection(miniHS2.getJdbcURL(), System.getProperty("user.name"), "bar");
Statement stmt2 = conn.createStatement();
stmt2.execute("DROP DATABASE IF EXISTS " + dbName + " CASCADE");
stmt2.execute("CREATE DATABASE " + dbName);
stmt2.close();
conn.close();
}
use of java.sql.Connection in project hive by apache.
the class TestJdbcWithLocalClusterSpark method testTempTable.
@Test
public void testTempTable() throws Exception {
// Create temp table with current connection
String tempTableName = "tmp1";
stmt.execute("CREATE TEMPORARY TABLE " + tempTableName + " (key string, value string)");
stmt.execute("load data local inpath '" + dataFilePath.toString() + "' into table " + tempTableName);
String resultVal = "val_238";
String queryStr = "SELECT * FROM " + tempTableName + " where value = '" + resultVal + "'";
verifyResult(queryStr, resultVal, 2);
// A second connection should not be able to see the table
Connection conn2 = DriverManager.getConnection(miniHS2.getJdbcURL(dbName), System.getProperty("user.name"), "bar");
Statement stmt2 = conn2.createStatement();
stmt2.execute("USE " + dbName);
boolean gotException = false;
try {
stmt2.executeQuery(queryStr);
} catch (SQLException err) {
// This is expected to fail.
assertTrue("Expecting table not found error, instead got: " + err, err.getMessage().contains("Table not found"));
gotException = true;
}
assertTrue("Exception while querying non-existing temp table", gotException);
}
use of java.sql.Connection in project hive by apache.
the class TestJdbcWithMiniHA method createDb.
// setup DB
private static void createDb() throws Exception {
Connection conn = DriverManager.getConnection(miniHS2.getJdbcURL(), System.getProperty("user.name"), "bar");
Statement stmt2 = conn.createStatement();
stmt2.execute("DROP DATABASE IF EXISTS " + dbName + " CASCADE");
stmt2.execute("CREATE DATABASE " + dbName);
stmt2.close();
conn.close();
}
use of java.sql.Connection in project hive by apache.
the class TestJdbcWithMiniHS2 method testUdfWhiteBlackList.
/**
* Test UDF whitelist
* - verify default value
* - verify udf allowed with default whitelist
* - verify udf allowed with specific whitelist
* - verify udf disallowed when not in whitelist
* @throws Exception
*/
@Test
public void testUdfWhiteBlackList() throws Exception {
HiveConf testConf = new HiveConf();
assertTrue(testConf.getVar(ConfVars.HIVE_SERVER2_BUILTIN_UDF_WHITELIST).isEmpty());
// verify that udf in default whitelist can be executed
Statement stmt = conDefault.createStatement();
stmt.executeQuery("SELECT substr('foobar', 4) ");
stmt.close();
// setup whitelist
stopMiniHS2();
Set<String> funcNames = FunctionRegistry.getFunctionNames();
funcNames.remove("reflect");
String funcNameStr = "";
for (String funcName : funcNames) {
funcNameStr += "," + funcName;
}
// remove ',' at begining
funcNameStr = funcNameStr.substring(1);
testConf.setVar(ConfVars.HIVE_SERVER2_BUILTIN_UDF_WHITELIST, funcNameStr);
startMiniHS2(testConf);
Connection conn = getConnection(miniHS2.getJdbcURL(testDbName), System.getProperty("user.name"), "bar");
stmt = conn.createStatement();
// verify that udf in whitelist can be executed
stmt.executeQuery("SELECT substr('foobar', 3) ");
// verify that udf not in whitelist fails
try {
stmt.executeQuery("SELECT reflect('java.lang.String', 'valueOf', 1) ");
fail("reflect() udf invocation should fail");
} catch (SQLException e) {
// expected
}
conn.close();
// Restore original state
restoreMiniHS2AndConnections();
}
use of java.sql.Connection in project hive by apache.
the class TestJdbcWithMiniHS2 method testNewConnectionConfiguration.
/**
* 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.
*
* @throws Exception
*/
@Test
public void testNewConnectionConfiguration() throws Exception {
// 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.max.worker.threads=15";
// Set some conf vars
String hiveVar = "stab=salesTable;icol=customerID";
String jdbcUri = miniHS2.getJdbcURL() + "?" + 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.max.worker.threads", "15");
verifyConfProperty(stmt, "stab", "salesTable");
verifyConfProperty(stmt, "icol", "customerID");
stmt.close();
con1.close();
}
Aggregations