Search in sources :

Example 51 with SessionHandle

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

the class ThriftCLIServiceTest method testGetFunctions.

@Test
public void testGetFunctions() throws Exception {
    SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>());
    assertNotNull("Session handle should not be null", sessHandle);
    String catalogName = null;
    String schemaName = null;
    String functionName = "*";
    OperationHandle opHandle = client.getFunctions(sessHandle, catalogName, schemaName, functionName);
    assertNotNull("Operation handle should not be null", opHandle);
    client.closeSession(sessHandle);
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 52 with SessionHandle

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

the class ThriftCLIServiceTest method testOpenSession.

@Test
public void testOpenSession() throws Exception {
    // Open a new client session
    SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>());
    // Session handle should not be null
    assertNotNull("Session handle should not be null", sessHandle);
    // Close client session
    client.closeSession(sessHandle);
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) Test(org.junit.Test)

Example 53 with SessionHandle

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

the class ThriftCliServiceTestWithCookie method testGetFunctions.

@Test
public void testGetFunctions() throws Exception {
    SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>());
    assertNotNull("Session handle should not be null", sessHandle);
    String catalogName = null;
    String schemaName = null;
    String functionName = "*";
    OperationHandle opHandle = client.getFunctions(sessHandle, catalogName, schemaName, functionName);
    assertNotNull("Operation handle should not be null", opHandle);
    client.closeSession(sessHandle);
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 54 with SessionHandle

use of org.apache.hive.service.cli.SessionHandle in project cdap by caskdata.

the class BaseHiveExploreService method getCatalogs.

@Override
public QueryHandle getCatalogs() throws ExploreException, SQLException {
    startAndWait();
    try {
        SessionHandle sessionHandle = null;
        OperationHandle operationHandle = null;
        Map<String, String> sessionConf = startSession();
        try {
            sessionHandle = openHiveSession(sessionConf);
            operationHandle = cliService.getCatalogs(sessionHandle);
            QueryHandle handle = saveReadOnlyOperation(operationHandle, sessionHandle, sessionConf, "", "");
            LOG.trace("Retrieving catalogs");
            return handle;
        } catch (Throwable e) {
            closeInternal(getQueryHandle(sessionConf), new ReadOnlyOperationInfo(sessionHandle, operationHandle, sessionConf, "", ""));
            throw e;
        }
    } catch (HiveSQLException e) {
        throw getSqlException(e);
    } catch (Throwable e) {
        throw new ExploreException(e);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) SessionHandle(org.apache.hive.service.cli.SessionHandle) QueryHandle(co.cask.cdap.proto.QueryHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) ExploreException(co.cask.cdap.explore.service.ExploreException)

Example 55 with SessionHandle

use of org.apache.hive.service.cli.SessionHandle in project cdap by caskdata.

the class BaseHiveExploreService method execute.

@Override
public QueryHandle execute(NamespaceId namespace, String[] statements) throws ExploreException, SQLException {
    Preconditions.checkArgument(statements.length > 0, "There must be at least one statement");
    startAndWait();
    try {
        SessionHandle sessionHandle = null;
        OperationHandle operationHandle = null;
        Map<String, String> sessionConf = startSession(namespace);
        String database = getHiveDatabase(namespace.getNamespace());
        try {
            sessionHandle = openHiveSession(sessionConf);
            // Switch database to the one being passed in.
            setCurrentDatabase(database);
            // synchronously execute all but the last statement
            for (int i = 0; i < statements.length - 1; i++) {
                String statement = statements[i];
                LOG.trace("Executing statement synchronously: {}", statement);
                operationHandle = executeSync(sessionHandle, statement);
                QueryStatus status = doFetchStatus(operationHandle);
                if (QueryStatus.OpStatus.ERROR == status.getStatus()) {
                    throw new HiveSQLException(status.getErrorMessage(), status.getSqlState());
                }
                if (QueryStatus.OpStatus.FINISHED != status.getStatus()) {
                    throw new ExploreException("Expected operation status FINISHED for statement '{}' but received " + status.getStatus());
                }
            }
            String statement = statements[statements.length - 1];
            operationHandle = executeAsync(sessionHandle, statement);
            QueryHandle handle = saveReadWriteOperation(operationHandle, sessionHandle, sessionConf, statement, database);
            LOG.trace("Executing statement: {} with handle {}", statement, handle);
            return handle;
        } catch (Throwable e) {
            closeInternal(getQueryHandle(sessionConf), new ReadWriteOperationInfo(sessionHandle, operationHandle, sessionConf, "", database));
            throw e;
        }
    } catch (HiveSQLException e) {
        throw getSqlException(e);
    } catch (Throwable e) {
        throw new ExploreException(e);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) SessionHandle(org.apache.hive.service.cli.SessionHandle) QueryHandle(co.cask.cdap.proto.QueryHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) QueryStatus(co.cask.cdap.proto.QueryStatus) ExploreException(co.cask.cdap.explore.service.ExploreException)

Aggregations

SessionHandle (org.apache.hive.service.cli.SessionHandle)67 OperationHandle (org.apache.hive.service.cli.OperationHandle)38 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)36 Test (org.junit.Test)27 IOException (java.io.IOException)16 TException (org.apache.thrift.TException)16 UnknownHostException (java.net.UnknownHostException)14 LoginException (javax.security.auth.login.LoginException)14 ServiceException (org.apache.hive.service.ServiceException)14 ExploreException (co.cask.cdap.explore.service.ExploreException)12 QueryHandle (co.cask.cdap.proto.QueryHandle)11 HashMap (java.util.HashMap)9 CLIServiceClient (org.apache.hive.service.cli.CLIServiceClient)8 RowSet (org.apache.hive.service.cli.RowSet)6 TimeoutException (java.util.concurrent.TimeoutException)4 HiveConf (org.apache.hadoop.hive.conf.HiveConf)4 ThriftCLIServiceClient (org.apache.hive.service.cli.thrift.ThriftCLIServiceClient)4 CLIService (org.apache.hive.service.cli.CLIService)3 OperationState (org.apache.hive.service.cli.OperationState)3 OperationStatus (org.apache.hive.service.cli.OperationStatus)3