Search in sources :

Example 41 with Connection

use of java.sql.Connection 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 42 with Connection

use of java.sql.Connection 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 43 with Connection

use of java.sql.Connection 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)

Example 44 with Connection

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

the class TestJdbcWithMiniLlap method getConnection.

private Connection getConnection(String jdbcURL, String user, String pwd) throws SQLException {
    Connection conn = DriverManager.getConnection(jdbcURL, user, pwd);
    conn.createStatement().execute("set hive.support.concurrency = false");
    return conn;
}
Also used : Connection(java.sql.Connection)

Example 45 with Connection

use of java.sql.Connection 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);
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection)

Aggregations

Connection (java.sql.Connection)6326 PreparedStatement (java.sql.PreparedStatement)2793 ResultSet (java.sql.ResultSet)2657 Test (org.junit.Test)2455 SQLException (java.sql.SQLException)2267 Properties (java.util.Properties)1188 Statement (java.sql.Statement)1078 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)689 ArrayList (java.util.ArrayList)397 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)232 DataSource (javax.sql.DataSource)211 BaseTest (org.apache.phoenix.query.BaseTest)201 CallableStatement (java.sql.CallableStatement)192 IOException (java.io.IOException)158 Reader (java.io.Reader)144 DatabaseMetaData (java.sql.DatabaseMetaData)144 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)134 HashMap (java.util.HashMap)123 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)114 Timestamp (java.sql.Timestamp)113