Search in sources :

Example 11 with String

use of java.lang.String in project hive by apache.

the class TestJdbcDriver2 method testQueryCancel.

/**
   * Test the cancellation of a query that is running.
   * We spawn 2 threads - one running the query and
   * the other attempting to cancel.
   * We're using a dummy udf to simulate a query,
   * that runs for a sufficiently long time.
   * @throws Exception
   */
@Test
public void testQueryCancel() throws Exception {
    String udfName = SleepMsUDF.class.getName();
    Statement stmt1 = con.createStatement();
    stmt1.execute("create temporary function sleepMsUDF as '" + udfName + "'");
    stmt1.close();
    final Statement stmt = con.createStatement();
    // Thread executing the query
    Thread tExecute = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                System.out.println("Executing query: ");
                // The test table has 500 rows, so total query time should be ~ 500*500ms
                stmt.executeQuery("select sleepMsUDF(t1.under_col, 1) as u0, t1.under_col as u1, " + "t2.under_col as u2 from " + tableName + " t1 join " + tableName + " t2 on t1.under_col = t2.under_col");
                fail("Expecting SQLException");
            } catch (SQLException e) {
                // This thread should throw an exception
                assertNotNull(e);
                System.out.println(e.toString());
            }
        }
    });
    // Thread cancelling the query
    Thread tCancel = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                // Sleep for 100ms
                Thread.sleep(100);
                System.out.println("Cancelling query: ");
                stmt.cancel();
            } catch (Exception e) {
            // No-op
            }
        }
    });
    tExecute.start();
    tCancel.start();
    tExecute.join();
    tCancel.join();
    stmt.close();
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) String(java.lang.String) SQLTimeoutException(java.sql.SQLTimeoutException) ParseException(java.text.ParseException) Exception(java.lang.Exception) SQLException(java.sql.SQLException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 12 with String

use of java.lang.String in project hive by apache.

the class TestJdbcDriver2 method metaDataGetTableTypeTest.

/**
   * Test if Connection.getMetaData().getTableTypes() returns expected
   *  tabletypes
   * @param tabletypes expected table types
   * @throws SQLException
   */
private void metaDataGetTableTypeTest(Set<String> tabletypes) throws SQLException {
    ResultSet rs = con.getMetaData().getTableTypes();
    int cnt = 0;
    while (rs.next()) {
        String tabletype = rs.getString("TABLE_TYPE");
        assertEquals("Get by index different from get by name", rs.getString(1), tabletype);
        tabletypes.remove(tabletype);
        cnt++;
    }
    rs.close();
    assertEquals("Incorrect tabletype count.", 0, tabletypes.size());
    assertTrue("Found less tabletypes then we test for.", cnt >= tabletypes.size());
}
Also used : ResultSet(java.sql.ResultSet) String(java.lang.String)

Example 13 with String

use of java.lang.String in project hive by apache.

the class TestJdbcDriver2 method testParseUrlHttpMode.

@Test
public void testParseUrlHttpMode() throws SQLException, JdbcUriParseException, ZooKeeperHiveClientException {
    new HiveDriver();
    for (String[] testValues : HTTP_URL_PROPERTIES) {
        JdbcConnectionParams params = Utils.parseURL(testValues[0], new Properties());
        assertEquals(params.getHost(), testValues[1]);
        assertEquals(params.getPort(), Integer.parseInt(testValues[2]));
        assertEquals(params.getDbName(), testValues[3]);
        assertEquals(params.getSessionVars().get("transportMode"), testValues[4]);
        assertEquals(params.getSessionVars().get("httpPath"), testValues[5]);
    }
}
Also used : JdbcConnectionParams(org.apache.hive.jdbc.Utils.JdbcConnectionParams) String(java.lang.String) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with String

use of java.lang.String in project hive by apache.

the class TestJdbcDriver2 method testErrorMessages.

@Test
public void testErrorMessages() throws SQLException {
    String invalidSyntaxSQLState = "42000";
    // These tests inherently cause exceptions to be written to the test output
    // logs. This is undesirable, since you it might appear to someone looking
    // at the test output logs as if something is failing when it isn't.
    // Not sure how to get around that.
    doTestErrorCase("SELECTT * FROM " + tableName, "cannot recognize input near 'SELECTT' '*' 'FROM'", invalidSyntaxSQLState, 40000);
    doTestErrorCase("SELECT * FROM some_table_that_does_not_exist", "Table not found", "42S02", 10001);
    doTestErrorCase("drop table some_table_that_does_not_exist", "Table not found", "42S02", 10001);
    doTestErrorCase("SELECT invalid_column FROM " + tableName, "Invalid table alias or column reference", invalidSyntaxSQLState, 10004);
    doTestErrorCase("SELECT invalid_function(under_col) FROM " + tableName, "Invalid function", invalidSyntaxSQLState, 10011);
    // TODO: execute errors like this currently don't return good error
    // codes and messages. This should be fixed.
    doTestErrorCase("create table " + tableName + " (key int, value string)", "FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask", "08S01", 1);
}
Also used : String(java.lang.String) Test(org.junit.Test)

Example 15 with String

use of java.lang.String in project hive by apache.

the class TestJdbcDriver2 method testMetaDataGetTypeInfo.

@Test
public void testMetaDataGetTypeInfo() throws SQLException {
    HiveBaseResultSet rs = (HiveBaseResultSet) con.getMetaData().getTypeInfo();
    Set<String> typeInfos = new HashSet<String>();
    typeInfos.add("BOOLEAN");
    typeInfos.add("TINYINT");
    typeInfos.add("SMALLINT");
    typeInfos.add("INT");
    typeInfos.add("BIGINT");
    typeInfos.add("FLOAT");
    typeInfos.add("DOUBLE");
    typeInfos.add("STRING");
    typeInfos.add("TIMESTAMP");
    typeInfos.add("BINARY");
    typeInfos.add("DECIMAL");
    typeInfos.add("ARRAY");
    typeInfos.add("MAP");
    typeInfos.add("STRUCT");
    typeInfos.add("UNIONTYPE");
    int cnt = 0;
    while (rs.next()) {
        String typeInfo = rs.getString("TYPE_NAME");
        assertEquals("Get by index different from get by name", rs.getString(1), typeInfo);
        typeInfos.remove(typeInfo);
        cnt++;
    }
    rs.close();
    assertEquals("Incorrect typeInfo count.", 0, typeInfos.size());
    assertTrue("Found less typeInfos than we test for.", cnt >= typeInfos.size());
}
Also used : String(java.lang.String) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

String (java.lang.String)192 Override (java.lang.Override)35 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)20 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)16 IOException (java.io.IOException)13 KeyValueMap (android.filterfw.core.KeyValueMap)12 GraphIOException (android.filterfw.io.GraphIOException)12 Statement (java.sql.Statement)12 Pattern (java.util.regex.Pattern)12 SQLException (java.sql.SQLException)11 Exception (java.lang.Exception)9 Map (java.util.Map)9 SQLTimeoutException (java.sql.SQLTimeoutException)8 List (java.util.List)8 Object (java.lang.Object)7 ParseException (java.text.ParseException)7 DbModel (net.tsz.afinal.db.sqlite.DbModel)7