Search in sources :

Example 71 with SQLException

use of java.sql.SQLException in project hive by apache.

the class cbo_rp_TestJdbcDriver2 method testShowRoleGrant.

@Test
public void testShowRoleGrant() throws SQLException {
    Statement stmt = con.createStatement();
    // drop role. ignore error.
    try {
        stmt.execute("drop role role1");
    } catch (Exception ex) {
        LOG.warn("Ignoring error during drop role: " + ex);
    }
    stmt.execute("create role role1");
    stmt.execute("grant role role1 to user hive_test_user");
    stmt.execute("show role grant user hive_test_user");
    ResultSet res = stmt.getResultSet();
    assertTrue(res.next());
    assertEquals("public", res.getString(1));
    assertTrue(res.next());
    assertEquals("role1", res.getString(1));
    res.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ParseException(java.text.ParseException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 72 with SQLException

use of java.sql.SQLException in project hive by apache.

the class cbo_rp_TestJdbcDriver2 method testExecuteQueryException.

// executeQuery should always throw a SQLException,
// when it executes a non-ResultSet query (like create)
@Test
public void testExecuteQueryException() throws Exception {
    Statement stmt = con.createStatement();
    try {
        stmt.executeQuery("create table test_t2 (under_col int, value string)");
        fail("Expecting SQLException");
    } catch (SQLException e) {
        System.out.println("Caught an expected SQLException: " + e.getMessage());
    } finally {
        stmt.close();
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Test(org.junit.Test)

Example 73 with SQLException

use of java.sql.SQLException in project hive by apache.

the class TestJdbcMetadataApiAuth method testMetaApiDisAllowed.

/**
   * Call the HS2 metadata api's with authorizer disallowing those calls
   * @throws Exception
   */
@Test
public void testMetaApiDisAllowed() throws Exception {
    TestAuthValidator.allowActions = false;
    Connection hs2Conn = getConnection("user1");
    DatabaseMetaData dbmetadata = hs2Conn.getMetaData();
    try {
        dbmetadata.getCatalogs();
        fail("HiveAccessControlException expected");
    } catch (SQLException e) {
        assertErrorContains(e, TestAuthValidator.DENIED_ERR);
    } catch (Exception e) {
        fail("HiveAccessControlException expected");
    }
    try {
        dbmetadata.getSchemas();
        fail("HiveAccessControlException expected");
    } catch (SQLException e) {
        assertErrorContains(e, TestAuthValidator.DENIED_ERR);
    } catch (Exception e) {
        fail("HiveAccessControlException expected");
    }
    try {
        dbmetadata.getTypeInfo();
        fail("HiveAccessControlException expected");
    } catch (SQLException e) {
        assertErrorContains(e, TestAuthValidator.DENIED_ERR);
    } catch (Exception e) {
        fail("HiveAccessControlException expected");
    }
    try {
        dbmetadata.getTables(null, "default", "t%", null);
        fail("HiveAccessControlException expected");
    } catch (SQLException e) {
        assertErrorContains(e, TestAuthValidator.DENIED_ERR);
    } catch (Exception e) {
        fail("HiveAccessControlException expected");
    }
    try {
        dbmetadata.getTableTypes();
        fail("HiveAccessControlException expected");
    } catch (SQLException e) {
        assertErrorContains(e, TestAuthValidator.DENIED_ERR);
    } catch (Exception e) {
        fail("HiveAccessControlException expected");
    }
    try {
        dbmetadata.getColumns(null, "default", "nosuchtable", null);
        fail("HiveAccessControlException expected");
    } catch (SQLException e) {
        assertErrorContains(e, TestAuthValidator.DENIED_ERR);
    } catch (Exception e) {
        fail("HiveAccessControlException expected");
    }
    try {
        dbmetadata.getFunctions(null, null, "trim");
        fail("HiveAccessControlException expected");
    } catch (SQLException e) {
        assertErrorContains(e, TestAuthValidator.DENIED_ERR);
    } catch (Exception e) {
        fail("HiveAccessControlException expected");
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData) SQLException(java.sql.SQLException) HiveAccessControlException(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAccessControlException) HiveAuthzPluginException(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException) Test(org.junit.Test)

Example 74 with SQLException

use of java.sql.SQLException in project hive by apache.

the class TestJdbcWithSQLAuthorization method testConfigWhiteList.

@Test
public void testConfigWhiteList() throws Exception {
    // create tables as user1
    Connection hs2Conn = getConnection("user1");
    Statement stmt = hs2Conn.createStatement();
    try {
        stmt.execute("set hive.metastore.uris=x");
        fail("exception expected");
    } catch (SQLException e) {
        String msg = "Cannot modify hive.metastore.uris at runtime. " + "It is not in list of params that are allowed to be modified at runtime";
        assertTrue(e.getMessage().contains(msg));
    }
    stmt.execute("set hive.exec.reducers.bytes.per.reducer=10000");
    //no exception should be thrown
    stmt.close();
    hs2Conn.close();
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) Test(org.junit.Test)

Example 75 with SQLException

use of java.sql.SQLException in project hive by apache.

the class TestJdbcWithMiniHS2 method testUdfBlackListOverride.

/** Test UDF blacklist overrides whitelist
   * @throws Exception
   */
@Test
public void testUdfBlackListOverride() throws Exception {
    stopMiniHS2();
    // setup whitelist
    HiveConf testConf = new HiveConf();
    Set<String> funcNames = FunctionRegistry.getFunctionNames();
    String funcNameStr = "";
    for (String funcName : funcNames) {
        funcNameStr += "," + funcName;
    }
    // remove ',' at begining
    funcNameStr = funcNameStr.substring(1);
    testConf.setVar(ConfVars.HIVE_SERVER2_BUILTIN_UDF_WHITELIST, funcNameStr);
    testConf.setVar(ConfVars.HIVE_SERVER2_BUILTIN_UDF_BLACKLIST, "reflect");
    startMiniHS2(testConf);
    Connection conn = getConnection(miniHS2.getJdbcURL(testDbName), System.getProperty("user.name"), "bar");
    Statement stmt = conn.createStatement();
    // verify that udf in black list fails even though it's included in whitelist
    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();
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Test(org.junit.Test)

Aggregations

SQLException (java.sql.SQLException)6792 PreparedStatement (java.sql.PreparedStatement)3048 ResultSet (java.sql.ResultSet)2426 Connection (java.sql.Connection)1871 ArrayList (java.util.ArrayList)972 Test (org.junit.Test)873 Statement (java.sql.Statement)779 IOException (java.io.IOException)341 List (java.util.List)335 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)298 Properties (java.util.Properties)255 DatabaseException (net.jforum.exceptions.DatabaseException)249 HashMap (java.util.HashMap)232 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)184 Timestamp (java.sql.Timestamp)171 CallableStatement (java.sql.CallableStatement)165 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)160 DalHints (com.ctrip.platform.dal.dao.DalHints)159 Map (java.util.Map)125 Date (java.util.Date)123