Search in sources :

Example 26 with OperationHandle

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

the class TestQueryDisplay method testWebUI.

/**
   * Test if webui captures information on current/historic SQL operations.
   */
@Test
public void testWebUI() throws Exception {
    HiveSession session = sessionManager.createSession(new SessionHandle(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8), TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8, "testuser", "", "", new HashMap<String, String>(), false, "");
    SessionState.start(conf);
    OperationHandle opHandle1 = session.executeStatement("show databases", null);
    SessionState.start(conf);
    OperationHandle opHandle2 = session.executeStatement("show tables", null);
    verifyDDLHtml("show databases", opHandle1.getHandleIdentifier().toString());
    verifyDDLHtml("show tables", opHandle2.getHandleIdentifier().toString());
    session.closeOperation(opHandle1);
    session.closeOperation(opHandle2);
    verifyDDLHtml("show databases", opHandle1.getHandleIdentifier().toString());
    verifyDDLHtml("show tables", opHandle2.getHandleIdentifier().toString());
    session.close();
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 27 with OperationHandle

use of org.apache.hive.service.cli.OperationHandle 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 28 with OperationHandle

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

the class OperationLoggingAPITestBase method testFetchResultsOfLogWithExecutionMode.

@Test
public void testFetchResultsOfLogWithExecutionMode() throws Exception {
    try {
        String queryString = "set hive.server2.logging.operation.level=execution";
        client.executeStatement(sessionHandle, queryString, null);
        // verify whether the sql operation log is generated and fetch correctly.
        OperationHandle operationHandle = client.executeStatement(sessionHandle, sqlCntStar, null);
        RowSet rowSetLog = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 1000, FetchType.LOG);
        verifyFetchedLog(rowSetLog, expectedLogsExecution);
        verifyMissingContentsInFetchedLog(rowSetLog, expectedLogsPerformance);
        verifyMissingContentsInFetchedLog(rowSetLog, expectedLogsVerbose);
    } finally {
        // Restore everything to default setup to avoid discrepancy between junit test runs
        String queryString2 = "set hive.server2.logging.operation.level=verbose";
        client.executeStatement(sessionHandle, queryString2, null);
    }
}
Also used : RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 29 with OperationHandle

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

the class OperationLoggingAPITestBase method setupSession.

private SessionHandle setupSession() throws Exception {
    // Open a session
    SessionHandle sessionHandle = client.openSession(null, null, null);
    // Change lock manager to embedded mode
    String queryString = "SET hive.lock.manager=" + "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
    client.executeStatement(sessionHandle, queryString, null);
    // Drop the table if it exists
    queryString = "DROP TABLE IF EXISTS " + tableName;
    client.executeStatement(sessionHandle, queryString, null);
    // Create a test table
    queryString = "create table " + tableName + " (key int, value string)";
    client.executeStatement(sessionHandle, queryString, null);
    // Load data
    queryString = "load data local inpath '" + dataFile + "' into table " + tableName;
    client.executeStatement(sessionHandle, queryString, null);
    // Precondition check: verify whether the table is created and data is fetched correctly.
    OperationHandle operationHandle = client.executeStatement(sessionHandle, sql, null);
    RowSet rowSetResult = client.fetchResults(operationHandle);
    Assert.assertEquals(500, rowSetResult.numRows());
    Assert.assertEquals(238, rowSetResult.iterator().next()[0]);
    Assert.assertEquals("val_238", rowSetResult.iterator().next()[1]);
    return sessionHandle;
}
Also used : RowSet(org.apache.hive.service.cli.RowSet) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 30 with OperationHandle

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

the class OperationLoggingAPITestBase method testFetchResultsOfLogWithPerformanceMode.

@Test
public void testFetchResultsOfLogWithPerformanceMode() throws Exception {
    try {
        String queryString = "set hive.server2.logging.operation.level=performance";
        client.executeStatement(sessionHandle, queryString, null);
        // verify whether the sql operation log is generated and fetch correctly.
        OperationHandle operationHandle = client.executeStatement(sessionHandle, sqlCntStar, null);
        RowSet rowSetLog = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 1000, FetchType.LOG);
        // rowSetLog should contain execution as well as performance logs
        verifyFetchedLog(rowSetLog, expectedLogsExecution);
        verifyFetchedLog(rowSetLog, expectedLogsPerformance);
        verifyMissingContentsInFetchedLog(rowSetLog, expectedLogsVerbose);
    } finally {
        // Restore everything to default setup to avoid discrepancy between junit test runs
        String queryString2 = "set hive.server2.logging.operation.level=verbose";
        client.executeStatement(sessionHandle, queryString2, null);
    }
}
Also used : RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Aggregations

OperationHandle (org.apache.hive.service.cli.OperationHandle)77 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)54 SessionHandle (org.apache.hive.service.cli.SessionHandle)38 TException (org.apache.thrift.TException)27 Test (org.junit.Test)22 IOException (java.io.IOException)18 RowSet (org.apache.hive.service.cli.RowSet)16 UnknownHostException (java.net.UnknownHostException)15 LoginException (javax.security.auth.login.LoginException)15 ServiceException (org.apache.hive.service.ServiceException)15 ExploreException (co.cask.cdap.explore.service.ExploreException)12 OperationManager (org.apache.hive.service.cli.operation.OperationManager)12 QueryHandle (co.cask.cdap.proto.QueryHandle)11 TProtocolVersion (org.apache.hive.service.rpc.thrift.TProtocolVersion)11 OperationStatus (org.apache.hive.service.cli.OperationStatus)5 HashMap (java.util.HashMap)4 CLIServiceClient (org.apache.hive.service.cli.CLIServiceClient)4 OperationState (org.apache.hive.service.cli.OperationState)4 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2 HandleNotFoundException (co.cask.cdap.explore.service.HandleNotFoundException)2