Search in sources :

Example 71 with HiveSQLException

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

the class HiveCommandOperation method runInternal.

@Override
public void runInternal() throws HiveSQLException {
    setState(OperationState.RUNNING);
    try {
        String command = getStatement().trim();
        String[] tokens = statement.split("\\s");
        String commandArgs = command.substring(tokens[0].length()).trim();
        CommandProcessorResponse response = commandProcessor.run(commandArgs);
        int returnCode = response.getResponseCode();
        if (returnCode != 0) {
            throw toSQLException("Error while processing statement", response);
        }
        Schema schema = response.getSchema();
        if (schema != null) {
            setHasResultSet(true);
            resultSchema = new TableSchema(schema);
        } else {
            setHasResultSet(false);
            resultSchema = new TableSchema();
        }
        if (response.getConsoleMessages() != null) {
            for (String consoleMsg : response.getConsoleMessages()) {
                LOG.info(consoleMsg);
            }
        }
    } catch (HiveSQLException e) {
        setState(OperationState.ERROR);
        throw e;
    } catch (Exception e) {
        setState(OperationState.ERROR);
        throw new HiveSQLException("Error running query: " + e.toString(), e);
    }
    setState(OperationState.FINISHED);
}
Also used : TableSchema(org.apache.hive.service.cli.TableSchema) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) TableSchema(org.apache.hive.service.cli.TableSchema) Schema(org.apache.hadoop.hive.metastore.api.Schema) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 72 with HiveSQLException

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

the class SQLOperation method getNextRowSet.

@Override
public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) throws HiveSQLException {
    validateDefaultFetchOrientation(orientation);
    assertState(new ArrayList<OperationState>(Arrays.asList(OperationState.FINISHED)));
    FetchTask fetchTask = driver.getFetchTask();
    boolean isBlobBased = false;
    if (fetchTask != null && fetchTask.getWork().isUsingThriftJDBCBinarySerDe()) {
        // Just fetch one blob if we've serialized thrift objects in final tasks
        maxRows = 1;
        isBlobBased = true;
    }
    driver.setMaxRows((int) maxRows);
    RowSet rowSet = RowSetFactory.create(resultSchema, getProtocolVersion(), isBlobBased);
    try {
        /* if client is requesting fetch-from-start and its not the first time reading from this operation
       * then reset the fetch position to beginning
       */
        if (orientation.equals(FetchOrientation.FETCH_FIRST) && fetchStarted) {
            driver.resetFetch();
        }
        fetchStarted = true;
        driver.setMaxRows((int) maxRows);
        if (driver.getResults(convey)) {
            return decode(convey, rowSet);
        }
        return rowSet;
    } catch (IOException e) {
        throw new HiveSQLException(e);
    } catch (Exception e) {
        throw new HiveSQLException(e);
    } finally {
        convey.clear();
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) RowSet(org.apache.hive.service.cli.RowSet) IOException(java.io.IOException) OperationState(org.apache.hive.service.cli.OperationState) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SQLException(java.sql.SQLException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) IOException(java.io.IOException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) FetchTask(org.apache.hadoop.hive.ql.exec.FetchTask)

Example 73 with HiveSQLException

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

the class HiveSessionImpl method getPrimaryKeys.

@Override
public OperationHandle getPrimaryKeys(String catalog, String schema, String table) throws HiveSQLException {
    acquire(true, true);
    OperationManager operationManager = getOperationManager();
    GetPrimaryKeysOperation operation = operationManager.newGetPrimaryKeysOperation(getSession(), catalog, schema, table);
    OperationHandle opHandle = operation.getHandle();
    try {
        addOpHandle(opHandle);
        operation.run();
        return opHandle;
    } catch (HiveSQLException e) {
        removeOpHandle(opHandle);
        operationManager.closeOperation(opHandle);
        throw e;
    } finally {
        release(true, true);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationManager(org.apache.hive.service.cli.operation.OperationManager) GetPrimaryKeysOperation(org.apache.hive.service.cli.operation.GetPrimaryKeysOperation) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 74 with HiveSQLException

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

the class HiveSessionImpl method getTables.

@Override
public OperationHandle getTables(String catalogName, String schemaName, String tableName, List<String> tableTypes) throws HiveSQLException {
    acquire(true, true);
    OperationManager operationManager = getOperationManager();
    MetadataOperation operation = operationManager.newGetTablesOperation(getSession(), catalogName, schemaName, tableName, tableTypes);
    OperationHandle opHandle = operation.getHandle();
    try {
        addOpHandle(opHandle);
        operation.run();
        return opHandle;
    } catch (HiveSQLException e) {
        removeOpHandle(opHandle);
        operationManager.closeOperation(opHandle);
        throw e;
    } finally {
        release(true, true);
    }
}
Also used : MetadataOperation(org.apache.hive.service.cli.operation.MetadataOperation) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationManager(org.apache.hive.service.cli.operation.OperationManager) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 75 with HiveSQLException

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

the class HiveSessionImpl method getSchemas.

@Override
public OperationHandle getSchemas(String catalogName, String schemaName) throws HiveSQLException {
    acquire(true, true);
    OperationManager operationManager = getOperationManager();
    GetSchemasOperation operation = operationManager.newGetSchemasOperation(getSession(), catalogName, schemaName);
    OperationHandle opHandle = operation.getHandle();
    try {
        addOpHandle(opHandle);
        operation.run();
        return opHandle;
    } catch (HiveSQLException e) {
        removeOpHandle(opHandle);
        operationManager.closeOperation(opHandle);
        throw e;
    } finally {
        release(true, true);
    }
}
Also used : GetSchemasOperation(org.apache.hive.service.cli.operation.GetSchemasOperation) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationManager(org.apache.hive.service.cli.operation.OperationManager) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Aggregations

HiveSQLException (org.apache.hive.service.cli.HiveSQLException)88 OperationHandle (org.apache.hive.service.cli.OperationHandle)39 TException (org.apache.thrift.TException)26 SessionHandle (org.apache.hive.service.cli.SessionHandle)20 ExploreException (co.cask.cdap.explore.service.ExploreException)14 IOException (java.io.IOException)12 QueryHandle (co.cask.cdap.proto.QueryHandle)11 TProtocolVersion (org.apache.hive.service.rpc.thrift.TProtocolVersion)11 OperationManager (org.apache.hive.service.cli.operation.OperationManager)10 TOperationHandle (org.apache.hive.service.rpc.thrift.TOperationHandle)10 QueryStatus (co.cask.cdap.proto.QueryStatus)7 SQLException (java.sql.SQLException)7 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)7 OperationStatus (org.apache.hive.service.cli.OperationStatus)5 TableSchema (org.apache.hive.service.cli.TableSchema)5 Test (org.junit.Test)5 FileNotFoundException (java.io.FileNotFoundException)4 ArrayList (java.util.ArrayList)4 Metrics (org.apache.hadoop.hive.common.metrics.common.Metrics)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)3