Search in sources :

Example 51 with HiveSQLException

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

the class MetadataOperation method authorizeMetaGets.

protected void authorizeMetaGets(HiveOperationType opType, List<HivePrivilegeObject> inpObjs, String cmdString) throws HiveSQLException {
    SessionState ss = SessionState.get();
    HiveAuthzContext.Builder ctxBuilder = new HiveAuthzContext.Builder();
    ctxBuilder.setUserIpAddress(ss.getUserIpAddress());
    ctxBuilder.setForwardedAddresses(ss.getForwardedAddresses());
    ctxBuilder.setCommandString(cmdString);
    try {
        ss.getAuthorizerV2().checkPrivileges(opType, inpObjs, null, ctxBuilder.build());
    } catch (HiveAuthzPluginException | HiveAccessControlException e) {
        throw new HiveSQLException(e.getMessage(), e);
    }
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) HiveAccessControlException(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAccessControlException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) HiveAuthzContext(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzContext) HiveAuthzPluginException(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException)

Example 52 with HiveSQLException

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

the class GetPrimaryKeysOperation method runInternal.

@Override
public void runInternal() throws HiveSQLException {
    setState(OperationState.RUNNING);
    try {
        IMetaStoreClient metastoreClient = getParentSession().getMetaStoreClient();
        PrimaryKeysRequest sqlReq = new PrimaryKeysRequest(schemaName, tableName);
        List<SQLPrimaryKey> pks = metastoreClient.getPrimaryKeys(sqlReq);
        if (pks == null) {
            return;
        }
        for (SQLPrimaryKey pk : pks) {
            rowSet.addRow(new Object[] { catalogName, pk.getTable_db(), pk.getTable_name(), pk.getColumn_name(), pk.getKey_seq(), pk.getPk_name() });
        }
        setState(OperationState.FINISHED);
    } catch (Exception e) {
        setState(OperationState.ERROR);
        throw new HiveSQLException(e);
    }
}
Also used : SQLPrimaryKey(org.apache.hadoop.hive.metastore.api.SQLPrimaryKey) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) PrimaryKeysRequest(org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest)

Example 53 with HiveSQLException

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

the class GetSchemasOperation method runInternal.

@Override
public void runInternal() throws HiveSQLException {
    setState(OperationState.RUNNING);
    if (isAuthV2Enabled()) {
        String cmdStr = "catalog : " + catalogName + ", schemaPattern : " + schemaName;
        authorizeMetaGets(HiveOperationType.GET_SCHEMAS, null, cmdStr);
    }
    try {
        IMetaStoreClient metastoreClient = getParentSession().getMetaStoreClient();
        String schemaPattern = convertSchemaPattern(schemaName);
        for (String dbName : metastoreClient.getDatabases(schemaPattern)) {
            rowSet.addRow(new Object[] { dbName, DEFAULT_HIVE_CATALOG });
        }
        setState(OperationState.FINISHED);
    } catch (Exception e) {
        setState(OperationState.ERROR);
        throw new HiveSQLException(e);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) HiveSQLException(org.apache.hive.service.cli.HiveSQLException)

Example 54 with HiveSQLException

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

the class SessionManager method startTimeoutChecker.

private void startTimeoutChecker() {
    // minimum 3 seconds
    final long interval = Math.max(checkInterval, 3000l);
    final Runnable timeoutChecker = new Runnable() {

        @Override
        public void run() {
            sleepFor(interval);
            while (!shutdown) {
                long current = System.currentTimeMillis();
                for (HiveSession session : new ArrayList<HiveSession>(handleToSession.values())) {
                    if (shutdown) {
                        break;
                    }
                    if (sessionTimeout > 0 && session.getLastAccessTime() + sessionTimeout <= current && (!checkOperation || session.getNoOperationTime() > sessionTimeout)) {
                        SessionHandle handle = session.getSessionHandle();
                        LOG.warn("Session " + handle + " is Timed-out (last access : " + new Date(session.getLastAccessTime()) + ") and will be closed");
                        try {
                            closeSession(handle);
                        } catch (HiveSQLException e) {
                            LOG.warn("Exception is thrown closing session " + handle, e);
                        } finally {
                            Metrics metrics = MetricsFactory.getInstance();
                            if (metrics != null) {
                                metrics.incrementCounter(MetricsConstant.HS2_ABANDONED_SESSIONS);
                            }
                        }
                    } else {
                        session.closeExpiredOperations();
                    }
                }
                sleepFor(interval);
            }
        }

        private void sleepFor(long interval) {
            synchronized (timeoutCheckerLock) {
                try {
                    timeoutCheckerLock.wait(interval);
                } catch (InterruptedException e) {
                // Ignore, and break.
                }
            }
        }
    };
    backgroundOperationPool.execute(timeoutChecker);
}
Also used : Metrics(org.apache.hadoop.hive.common.metrics.common.Metrics) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) ArrayList(java.util.ArrayList) SessionHandle(org.apache.hive.service.cli.SessionHandle) Date(java.util.Date)

Example 55 with HiveSQLException

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

the class ThriftCLIServiceClient method renewDelegationToken.

@Override
public void renewDelegationToken(SessionHandle sessionHandle, HiveAuthFactory authFactory, String tokenStr) throws HiveSQLException {
    TRenewDelegationTokenReq cancelReq = new TRenewDelegationTokenReq(sessionHandle.toTSessionHandle(), tokenStr);
    try {
        TRenewDelegationTokenResp renewResp = cliService.RenewDelegationToken(cancelReq);
        checkStatus(renewResp.getStatus());
        return;
    } catch (Exception e) {
        throw new HiveSQLException(e);
    }
}
Also used : TRenewDelegationTokenResp(org.apache.hive.service.rpc.thrift.TRenewDelegationTokenResp) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TRenewDelegationTokenReq(org.apache.hive.service.rpc.thrift.TRenewDelegationTokenReq) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException)

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