Search in sources :

Example 1 with CLIServiceClient

use of org.apache.hive.service.cli.CLIServiceClient in project oozie by apache.

the class MiniHS2 method waitForStartup.

private void waitForStartup() throws Exception {
    int waitTime = 0;
    long startupTimeout = 1000L * 1000000000L;
    CLIServiceClient hs2Client = getServiceClientInternal();
    SessionHandle sessionHandle = null;
    do {
        Thread.sleep(500L);
        waitTime += 500L;
        if (waitTime > startupTimeout) {
            throw new TimeoutException("Couldn't access new HiveServer2: " + getJdbcURL());
        }
        try {
            sessionHandle = hs2Client.openSession("foo", "bar");
        } catch (Exception e) {
            // service not started yet
            continue;
        }
        hs2Client.closeSession(sessionHandle);
        break;
    } while (true);
}
Also used : ThriftCLIServiceClient(org.apache.hive.service.cli.thrift.ThriftCLIServiceClient) CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) SessionHandle(org.apache.hive.service.cli.SessionHandle) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with CLIServiceClient

use of org.apache.hive.service.cli.CLIServiceClient in project hive by apache.

the class BeelineWithHS2ConnectionFileTestBase method createTable.

protected void createTable() throws HiveSQLException {
    CLIServiceClient serviceClient = miniHS2.getServiceClient();
    SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
    serviceClient.executeStatement(sessHandle, "DROP TABLE IF EXISTS " + tableName, confOverlay);
    serviceClient.executeStatement(sessHandle, "CREATE TABLE " + tableName + " (id INT)", confOverlay);
    OperationHandle opHandle = serviceClient.executeStatement(sessHandle, "SHOW TABLES", confOverlay);
    RowSet rowSet = serviceClient.fetchResults(opHandle);
    assertFalse(rowSet.numRows() == 0);
}
Also used : CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) RowSet(org.apache.hive.service.cli.RowSet) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 3 with CLIServiceClient

use of org.apache.hive.service.cli.CLIServiceClient in project hive by apache.

the class TestHiveServer2 method testGetVariableValue.

/**
 * Open a new session and execute a set command
 * @throws Exception
 */
@Test
public void testGetVariableValue() throws Exception {
    CLIServiceClient serviceClient = miniHS2.getServiceClient();
    SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
    OperationHandle opHandle = serviceClient.executeStatement(sessHandle, "set system:os.name", confOverlay);
    RowSet rowSet = serviceClient.fetchResults(opHandle);
    assertEquals(1, rowSet.numRows());
    serviceClient.closeSession(sessHandle);
}
Also used : CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) RowSet(org.apache.hive.service.cli.RowSet) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 4 with CLIServiceClient

use of org.apache.hive.service.cli.CLIServiceClient in project hive by apache.

the class MiniHS2 method waitForStartup.

private void waitForStartup() throws Exception {
    int waitTime = 0;
    long startupTimeout = 1000L * 1000L;
    CLIServiceClient hs2Client = getServiceClientInternal();
    SessionHandle sessionHandle = null;
    do {
        Thread.sleep(500L);
        waitTime += 500L;
        if (waitTime > startupTimeout) {
            throw new TimeoutException("Couldn't access new HiveServer2: " + getJdbcURL());
        }
        try {
            Map<String, String> sessionConf = new HashMap<String, String>();
            /**
             *        if (isUseMiniKdc()) {
             *          getMiniKdc().loginUser(getMiniKdc().getDefaultUserPrincipal());
             *          sessionConf.put("principal", serverPrincipal);
             *        }
             */
            sessionHandle = hs2Client.openSession("foo", "bar", sessionConf);
        } catch (Exception e) {
            if (e.getMessage().contains("Cannot open sessions on an inactive HS2")) {
                // Passive HS2 has started. TODO: seems fragile
                return;
            }
            // service not started yet
            continue;
        }
        hs2Client.closeSession(sessionHandle);
        break;
    } while (true);
}
Also used : ThriftCLIServiceClient(org.apache.hive.service.cli.thrift.ThriftCLIServiceClient) CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) HashMap(java.util.HashMap) SessionHandle(org.apache.hive.service.cli.SessionHandle) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with CLIServiceClient

use of org.apache.hive.service.cli.CLIServiceClient in project hive by apache.

the class InformationSchemaWithPrivilegeTestBase method test.

@Test
public void test() throws Exception {
    String db1Name = "testdb1";
    String db2Name = "testdb2";
    String table1Name = "testtable1";
    String table2Name = "testtable2";
    String table3Name = "testtable3";
    String table4Name = "testtable4";
    CLIServiceClient serviceClient = miniHS2.getServiceClient();
    SessionHandle sessHandle = serviceClient.openSession("hive_test_user", "");
    serviceClient.executeStatement(sessHandle, "DROP DATABASE IF EXISTS " + db1Name + " CASCADE", confOverlay);
    serviceClient.executeStatement(sessHandle, "CREATE DATABASE " + db1Name, confOverlay);
    serviceClient.executeStatement(sessHandle, "DROP TABLE IF EXISTS " + db1Name + "." + table1Name, confOverlay);
    serviceClient.executeStatement(sessHandle, "CREATE TABLE " + db1Name + "." + table1Name + "(key string, value double)", confOverlay);
    serviceClient.executeStatement(sessHandle, "DROP TABLE IF EXISTS " + db1Name + "." + table2Name, confOverlay);
    serviceClient.executeStatement(sessHandle, "CREATE TABLE " + db1Name + "." + table2Name + "(key string, value double)", confOverlay);
    serviceClient.executeStatement(sessHandle, "DROP VIEW IF EXISTS " + db1Name + "." + table3Name, confOverlay);
    serviceClient.executeStatement(sessHandle, "CREATE VIEW " + db1Name + "." + table3Name + " AS SELECT * FROM " + db1Name + "." + table1Name, confOverlay);
    serviceClient.executeStatement(sessHandle, "DROP TABLE IF EXISTS " + db1Name + "." + table4Name, confOverlay);
    serviceClient.executeStatement(sessHandle, "CREATE TABLE " + db1Name + "." + table4Name + "(key string, value double) PARTITIONED BY (p string)", confOverlay);
    serviceClient.executeStatement(sessHandle, "DROP DATABASE IF EXISTS " + db2Name + " CASCADE", confOverlay);
    serviceClient.executeStatement(sessHandle, "CREATE DATABASE " + db2Name, confOverlay);
    serviceClient.executeStatement(sessHandle, "DROP TABLE IF EXISTS " + db2Name + "." + table1Name, confOverlay);
    serviceClient.executeStatement(sessHandle, "CREATE TABLE " + db2Name + "." + table1Name + "(key string, value double)", confOverlay);
    // Just to trigger auto creation of needed metastore tables
    serviceClient.executeStatement(sessHandle, "SHOW GRANT USER hive_test_user ON ALL", confOverlay);
    serviceClient.closeSession(sessHandle);
    List<String> baseArgs = new ArrayList<String>();
    baseArgs.add("-d");
    baseArgs.add(BeeLine.BEELINE_DEFAULT_JDBC_DRIVER);
    baseArgs.add("-u");
    baseArgs.add(miniHS2.getBaseJdbcURL());
    baseArgs.add("-n");
    baseArgs.add("hive_test_user");
    List<String> args = new ArrayList<String>(baseArgs);
    args.add("-f");
    args.add("../../metastore/scripts/upgrade/hive/hive-schema-4.0.0.hive.sql");
    BeeLine beeLine = new BeeLine();
    int result = beeLine.begin(args.toArray(new String[] {}), null);
    beeLine.close();
    Assert.assertEquals(result, 0);
    boolean containsDb1 = false;
    boolean containsDb2 = false;
    boolean containsDb1Table1 = false;
    boolean containsDb1Table2 = false;
    boolean containsDb1Table3 = false;
    boolean containsDb1Table4 = false;
    boolean containsDb2Table1 = false;
    boolean containsDb1Table1SelectPriv = false;
    boolean containsDb1Table1UpdatePriv = false;
    boolean containsDb1Table2SelectPriv = false;
    boolean containsDb1Table3SelectPriv = false;
    boolean containsDb1Table4SelectPriv = false;
    boolean containsDb2Table1SelectPriv = false;
    boolean containsDb1Table1Key = false;
    boolean containsDb1Table1Value = false;
    boolean containsDb1Table2Key = false;
    boolean containsDb1Table2Value = false;
    boolean containsDb1Table3Key = false;
    boolean containsDb1Table3Value = false;
    boolean containsDb1Table4Key = false;
    boolean containsDb1Table4Value = false;
    boolean containsDb1Table4P = false;
    boolean containsDb2Table1Key = false;
    // We shall have enough time to synchronize privileges during loading
    // information schema
    // User1 privileges:
    // testdb1:            S
    // testtable1.*:     SU
    // testtable2.*:     S
    // testtable3.*:     S
    // testtable4.*:
    // testdb2:            S
    // testtable1.*:     S
    sessHandle = serviceClient.openSession("user1", "");
    OperationHandle opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.SCHEMATA", confOverlay);
    RowSet rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 2);
    Iterator<Object[]> iter = rowSet.iterator();
    while (iter.hasNext()) {
        Object[] cols = iter.next();
        if (cols[1].equals(db1Name)) {
            containsDb1 = true;
        } else if (cols[1].equals(db2Name)) {
            containsDb2 = true;
        }
    }
    Assert.assertTrue(containsDb1 && containsDb2);
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.TABLES", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 4);
    iter = rowSet.iterator();
    while (iter.hasNext()) {
        Object[] cols = iter.next();
        if (cols[1].equals(db1Name) && cols[2].equals(table1Name)) {
            containsDb1Table1 = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table2Name)) {
            containsDb1Table2 = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table3Name)) {
            containsDb1Table3 = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table4Name)) {
            containsDb1Table4 = true;
        } else if (cols[1].equals(db2Name) && cols[2].equals(table1Name)) {
            containsDb2Table1 = true;
        }
    }
    Assert.assertTrue(containsDb1Table1 && containsDb1Table2 && containsDb1Table3 && !containsDb1Table4 && containsDb2Table1);
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.VIEWS", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 1);
    iter = rowSet.iterator();
    while (iter.hasNext()) {
        Object[] cols = iter.next();
        if (cols[1].equals(db1Name) && cols[2].equals(table3Name)) {
            containsDb1Table3 = true;
        } else {
            containsDb1Table3 = false;
        }
    }
    Assert.assertTrue(containsDb1Table3);
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.TABLE_PRIVILEGES", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 5);
    iter = rowSet.iterator();
    while (iter.hasNext()) {
        Object[] cols = iter.next();
        if (cols[3].equals(db1Name) && cols[4].equals(table1Name) && cols[5].equals("SELECT")) {
            containsDb1Table1SelectPriv = true;
        }
        if (cols[3].equals(db1Name) && cols[4].equals(table1Name) && cols[5].equals("UPDATE")) {
            containsDb1Table1UpdatePriv = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table2Name) && cols[5].equals("SELECT")) {
            containsDb1Table2SelectPriv = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table3Name) && cols[5].equals("SELECT")) {
            containsDb1Table3SelectPriv = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table4Name) && cols[5].equals("SELECT")) {
            containsDb1Table4SelectPriv = true;
        } else if (cols[3].equals(db2Name) && cols[4].equals(table1Name) && cols[5].equals("SELECT")) {
            containsDb2Table1SelectPriv = true;
        }
    }
    Assert.assertTrue(containsDb1Table1SelectPriv && containsDb1Table1UpdatePriv && containsDb1Table2SelectPriv && containsDb1Table3SelectPriv && !containsDb1Table4SelectPriv && containsDb2Table1SelectPriv);
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.COLUMNS", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 7);
    iter = rowSet.iterator();
    while (iter.hasNext()) {
        Object[] cols = iter.next();
        if (cols[1].equals(db1Name) && cols[2].equals(table1Name) && cols[3].equals("key")) {
            containsDb1Table1Key = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table1Name) && cols[3].equals("value")) {
            containsDb1Table1Value = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table2Name) && cols[3].equals("key")) {
            containsDb1Table2Key = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table2Name) && cols[3].equals("value")) {
            containsDb1Table2Value = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table3Name) && cols[3].equals("key")) {
            containsDb1Table3Key = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table3Name) && cols[3].equals("value")) {
            containsDb1Table3Value = true;
        } else if (cols[1].equals(db2Name) && cols[2].equals(table1Name) && cols[3].equals("key")) {
            containsDb2Table1Key = true;
        }
    }
    Assert.assertTrue(containsDb1Table1Key && containsDb1Table1Value && containsDb1Table2Key && containsDb1Table2Value && containsDb1Table3Key && containsDb1Table3Value && containsDb2Table1Key);
    containsDb1Table1Key = false;
    containsDb1Table1Value = false;
    containsDb1Table2Key = false;
    containsDb1Table2Value = false;
    containsDb1Table3Key = false;
    containsDb1Table3Value = false;
    containsDb2Table1Key = false;
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.COLUMN_PRIVILEGES", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 7);
    iter = rowSet.iterator();
    while (iter.hasNext()) {
        Object[] cols = iter.next();
        if (cols[3].equals(db1Name) && cols[4].equals(table1Name) && cols[5].equals("key")) {
            containsDb1Table1Key = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table1Name) && cols[5].equals("value")) {
            containsDb1Table1Value = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table2Name) && cols[5].equals("key")) {
            containsDb1Table2Key = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table2Name) && cols[5].equals("value")) {
            containsDb1Table2Value = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table3Name) && cols[5].equals("key")) {
            containsDb1Table3Key = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table3Name) && cols[5].equals("value")) {
            containsDb1Table3Value = true;
        } else if (cols[3].equals(db2Name) && cols[4].equals(table1Name) && cols[5].equals("key")) {
            containsDb2Table1Key = true;
        }
    }
    Assert.assertTrue(containsDb1Table1Key && containsDb1Table1Value && containsDb1Table2Key && containsDb1Table2Value && containsDb1Table3Key && containsDb1Table3Value && containsDb2Table1Key);
    serviceClient.closeSession(sessHandle);
    // User2 privileges:
    // testdb1: S
    // testtable1.*: S
    // testtable2.*: S
    // testtable3.*: S
    // testtable4.*: S
    // testdb2:
    // testtable1.*:
    sessHandle = serviceClient.openSession("user2", "");
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.SCHEMATA", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 1);
    iter = rowSet.iterator();
    while (iter.hasNext()) {
        Object[] cols = iter.next();
        if (cols[1].equals(db1Name)) {
            containsDb1 = true;
        }
    }
    Assert.assertTrue(containsDb1);
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.TABLES", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 4);
    iter = rowSet.iterator();
    while (iter.hasNext()) {
        Object[] cols = iter.next();
        if (cols[1].equals(db1Name) && cols[2].equals(table1Name)) {
            containsDb1Table1 = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table2Name)) {
            containsDb1Table2 = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table3Name)) {
            containsDb1Table3 = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table4Name)) {
            containsDb1Table4 = true;
        }
    }
    Assert.assertTrue(containsDb1Table1 && containsDb1Table2 && containsDb1Table3 && containsDb1Table4);
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.VIEWS", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 1);
    iter = rowSet.iterator();
    while (iter.hasNext()) {
        Object[] cols = iter.next();
        if (cols[1].equals(db1Name) && cols[2].equals(table3Name)) {
            containsDb1Table3 = true;
        } else {
            containsDb1Table3 = false;
        }
    }
    Assert.assertTrue(containsDb1Table3);
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.TABLE_PRIVILEGES", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 4);
    iter = rowSet.iterator();
    while (iter.hasNext()) {
        Object[] cols = iter.next();
        if (cols[3].equals(db1Name) && cols[4].equals(table1Name) && cols[5].equals("SELECT")) {
            containsDb1Table1SelectPriv = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table2Name) && cols[5].equals("SELECT")) {
            containsDb1Table2SelectPriv = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table3Name) && cols[5].equals("SELECT")) {
            containsDb1Table3SelectPriv = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table4Name) && cols[5].equals("SELECT")) {
            containsDb1Table4SelectPriv = true;
        }
    }
    Assert.assertTrue(containsDb1Table1SelectPriv && containsDb1Table2SelectPriv && containsDb1Table3SelectPriv && containsDb1Table4SelectPriv);
    // db1.testtable3.p should also be in COLUMNS, will fix in separate ticket
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.COLUMNS", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 8);
    iter = rowSet.iterator();
    while (iter.hasNext()) {
        Object[] cols = iter.next();
        if (cols[1].equals(db1Name) && cols[2].equals(table1Name) && cols[3].equals("key")) {
            containsDb1Table1Key = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table1Name) && cols[3].equals("value")) {
            containsDb1Table1Value = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table2Name) && cols[3].equals("key")) {
            containsDb1Table2Key = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table2Name) && cols[3].equals("value")) {
            containsDb1Table2Value = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table3Name) && cols[3].equals("key")) {
            containsDb1Table3Key = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table3Name) && cols[3].equals("value")) {
            containsDb1Table3Value = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table4Name) && cols[3].equals("key")) {
            containsDb1Table4Key = true;
        } else if (cols[1].equals(db1Name) && cols[2].equals(table4Name) && cols[3].equals("value")) {
            containsDb1Table4Value = true;
        }
    }
    Assert.assertTrue(containsDb1Table1Key && containsDb1Table1Value && containsDb1Table2Key && containsDb1Table2Value && containsDb1Table3Key && containsDb1Table3Value && containsDb1Table4Key && containsDb1Table4Value);
    containsDb1Table1Key = false;
    containsDb1Table1Value = false;
    containsDb1Table2Key = false;
    containsDb1Table2Value = false;
    containsDb1Table3Key = false;
    containsDb1Table3Value = false;
    containsDb1Table4Key = false;
    containsDb1Table4Value = false;
    containsDb1Table4P = false;
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.COLUMN_PRIVILEGES", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 9);
    iter = rowSet.iterator();
    while (iter.hasNext()) {
        Object[] cols = iter.next();
        if (cols[3].equals(db1Name) && cols[4].equals(table1Name) && cols[5].equals("key")) {
            containsDb1Table1Key = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table1Name) && cols[5].equals("value")) {
            containsDb1Table1Value = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table2Name) && cols[5].equals("key")) {
            containsDb1Table2Key = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table2Name) && cols[5].equals("value")) {
            containsDb1Table2Value = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table3Name) && cols[5].equals("key")) {
            containsDb1Table3Key = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table3Name) && cols[5].equals("value")) {
            containsDb1Table3Value = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table4Name) && cols[5].equals("key")) {
            containsDb1Table4Key = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table4Name) && cols[5].equals("value")) {
            containsDb1Table4Value = true;
        } else if (cols[3].equals(db1Name) && cols[4].equals(table4Name) && cols[5].equals("p")) {
            containsDb1Table4P = true;
        }
    }
    Assert.assertTrue(containsDb1Table1Key && containsDb1Table1Value && containsDb1Table2Key && containsDb1Table2Value && containsDb1Table3Key && containsDb1Table3Value && containsDb1Table4Key && containsDb1Table4Value && containsDb1Table4P);
    serviceClient.closeSession(sessHandle);
    // Revert hive.server2.restrict_information_schema to false
    miniHS2.getHiveConf().set(ConfVars.HIVE_AUTHORIZATION_ENABLED.varname, "false");
    sessHandle = serviceClient.openSession("user1", "");
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.SCHEMATA", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 5);
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.TABLES", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertTrue(rowSet.numRows() > 50);
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.TABLE_PRIVILEGES", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertTrue(rowSet.numRows() > 200);
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.COLUMNS", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertTrue(rowSet.numRows() > 350);
    opHandle = serviceClient.executeStatement(sessHandle, "select * from INFORMATION_SCHEMA.COLUMN_PRIVILEGES", confOverlay);
    rowSet = serviceClient.fetchResults(opHandle);
    Assert.assertEquals(rowSet.numRows(), 12);
}
Also used : CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) ArrayList(java.util.ArrayList) RowSet(org.apache.hive.service.cli.RowSet) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) HivePrivilegeObject(org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject) BeeLine(org.apache.hive.beeline.BeeLine) Test(org.junit.Test)

Aggregations

CLIServiceClient (org.apache.hive.service.cli.CLIServiceClient)11 SessionHandle (org.apache.hive.service.cli.SessionHandle)11 Test (org.junit.Test)8 OperationHandle (org.apache.hive.service.cli.OperationHandle)6 RowSet (org.apache.hive.service.cli.RowSet)5 IOException (java.io.IOException)2 TimeoutException (java.util.concurrent.TimeoutException)2 CodahaleMetrics (org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics)2 ThriftCLIServiceClient (org.apache.hive.service.cli.thrift.ThriftCLIServiceClient)2 FileNotFoundException (java.io.FileNotFoundException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UtilsForTest (org.apache.hadoop.hive.UtilsForTest)1 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)1 HivePrivilegeObject (org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject)1 BeeLine (org.apache.hive.beeline.BeeLine)1 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)1