use of java.sql.Statement in project hive by apache.
the class TestJdbcWithMiniLlap method createTestTable.
private void createTestTable(String tableName) throws Exception {
Statement stmt = hs2Conn.createStatement();
// create table
stmt.execute("DROP TABLE IF EXISTS " + tableName);
stmt.execute("CREATE TABLE " + tableName + " (under_col INT COMMENT 'the under column', value STRING) COMMENT ' test table'");
// load data
stmt.execute("load data local inpath '" + kvDataFilePath.toString() + "' into table " + tableName);
ResultSet res = stmt.executeQuery("SELECT * FROM " + tableName);
assertTrue(res.next());
assertEquals("val_238", res.getString(2));
res.close();
stmt.close();
}
use of java.sql.Statement in project hive by apache.
the class TestMultiSessionsHS2WithLocalClusterSpark method createConnection.
private void createConnection() throws Exception {
Connection connection = DriverManager.getConnection(miniHS2.getJdbcURL(dbName), System.getProperty("user.name"), "bar");
Statement statement = connection.createStatement();
localConnection.set(connection);
localStatement.set(statement);
statement.execute("USE " + dbName);
}
use of java.sql.Statement in project hive by apache.
the class TestJdbcDriver2 method testShowTables.
@Test
public void testShowTables() throws SQLException {
Statement stmt = con.createStatement();
assertNotNull("Statement is null", stmt);
ResultSet res = stmt.executeQuery("show tables");
boolean testTableExists = false;
while (res.next()) {
assertNotNull("table name is null in result set", res.getString(1));
if (tableName.equalsIgnoreCase(res.getString(1))) {
testTableExists = true;
}
}
assertTrue("table name " + tableName + " not found in SHOW TABLES result set", testTableExists);
stmt.close();
}
use of java.sql.Statement in project hive by apache.
the class TestJdbcDriver2 method testNullResultSet.
@Test
public void testNullResultSet() throws Exception {
List<String> setupQueries = new ArrayList<String>();
String testQuery;
Statement stmt = con.createStatement();
// -select- should return a ResultSet
testQuery = "select * from " + tableName + " limit 5";
checkResultSetExpected(stmt, setupQueries, testQuery, true);
setupQueries.clear();
// -create- should not return a ResultSet
setupQueries.add("drop table test_t1");
testQuery = "create table test_t1 (under_col int, value string)";
checkResultSetExpected(stmt, setupQueries, testQuery, false);
setupQueries.clear();
// -create table as select- should not return a ResultSet
setupQueries.add("drop table test_t1");
testQuery = "create table test_t1 as select * from " + tableName + " limit 5";
checkResultSetExpected(stmt, setupQueries, testQuery, false);
setupQueries.clear();
// -insert table as select- should not return a ResultSet
setupQueries.add("drop table test_t1");
setupQueries.add("create table test_t1 (under_col int, value string)");
testQuery = "insert into table test_t1 select under_col, value from " + tableName + " limit 5";
checkResultSetExpected(stmt, setupQueries, testQuery, false);
setupQueries.clear();
stmt.close();
}
use of java.sql.Statement in project hive by apache.
the class TestJdbcDriver2 method setUpBeforeClass.
@SuppressWarnings("deprecation")
@BeforeClass
public static void setUpBeforeClass() throws SQLException, ClassNotFoundException {
conf = new HiveConf(TestJdbcDriver2.class);
dataFileDir = conf.get("test.data.files").replace('\\', '/').replace("c:", "");
dataFilePath = new Path(dataFileDir, "kv1.txt");
dataFileRowCount = 500;
dataTypeDataFilePath = new Path(dataFileDir, "datatypes.txt");
// Create test database and base tables once for all the test
Class.forName(driverName);
System.setProperty(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LEVEL.varname, "verbose");
System.setProperty(ConfVars.HIVEMAPREDMODE.varname, "nonstrict");
System.setProperty(ConfVars.HIVE_AUTHORIZATION_MANAGER.varname, "org.apache.hadoop.hive.ql.security.authorization.DefaultHiveAuthorizationProvider");
System.setProperty(ConfVars.HIVE_SERVER2_PARALLEL_OPS_IN_SESSION.varname, "false");
con = getConnection(defaultDbName + ";create=true");
Statement stmt = con.createStatement();
assertNotNull("Statement is null", stmt);
stmt.execute("set hive.support.concurrency = false");
stmt.execute("drop database if exists " + testDbName + " cascade");
stmt.execute("create database " + testDbName);
stmt.execute("use " + testDbName);
createTestTables(stmt, testDbName);
stmt.close();
}
Aggregations