Search in sources :

Example 46 with TException

use of org.apache.thrift.TException in project hive by apache.

the class EximUtil method readMetaData.

public static ReadMetaData readMetaData(FileSystem fs, Path metadataPath) throws IOException, SemanticException {
    FSDataInputStream mdstream = null;
    try {
        mdstream = fs.open(metadataPath);
        byte[] buffer = new byte[1024];
        ByteArrayOutputStream sb = new ByteArrayOutputStream();
        int read = mdstream.read(buffer);
        while (read != -1) {
            sb.write(buffer, 0, read);
            read = mdstream.read(buffer);
        }
        String md = new String(sb.toByteArray(), "UTF-8");
        JSONObject jsonContainer = new JSONObject(md);
        String version = jsonContainer.getString("version");
        String fcversion = getJSONStringEntry(jsonContainer, "fcversion");
        checkCompatibility(version, fcversion);
        String dbDesc = getJSONStringEntry(jsonContainer, "db");
        String tableDesc = getJSONStringEntry(jsonContainer, "table");
        TDeserializer deserializer = new TDeserializer(new TJSONProtocol.Factory());
        Database db = null;
        if (dbDesc != null) {
            db = new Database();
            deserializer.deserialize(db, dbDesc, "UTF-8");
        }
        Table table = null;
        List<Partition> partitionsList = null;
        if (tableDesc != null) {
            table = new Table();
            deserializer.deserialize(table, tableDesc, "UTF-8");
            // TODO : jackson-streaming-iterable-redo this
            JSONArray jsonPartitions = new JSONArray(jsonContainer.getString("partitions"));
            partitionsList = new ArrayList<Partition>(jsonPartitions.length());
            for (int i = 0; i < jsonPartitions.length(); ++i) {
                String partDesc = jsonPartitions.getString(i);
                Partition partition = new Partition();
                deserializer.deserialize(partition, partDesc, "UTF-8");
                partitionsList.add(partition);
            }
        }
        return new ReadMetaData(db, table, partitionsList, readReplicationSpec(jsonContainer));
    } catch (JSONException e) {
        throw new SemanticException(ErrorMsg.ERROR_SERIALIZE_METADATA.getMsg(), e);
    } catch (TException e) {
        throw new SemanticException(ErrorMsg.ERROR_SERIALIZE_METADATA.getMsg(), e);
    } finally {
        if (mdstream != null) {
            mdstream.close();
        }
    }
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) TDeserializer(org.apache.thrift.TDeserializer) Table(org.apache.hadoop.hive.metastore.api.Table) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) JSONObject(org.json.JSONObject) Database(org.apache.hadoop.hive.metastore.api.Database) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream)

Example 47 with TException

use of org.apache.thrift.TException in project hive by apache.

the class ThriftCLIService method ExecuteStatement.

@Override
public TExecuteStatementResp ExecuteStatement(TExecuteStatementReq req) throws TException {
    TExecuteStatementResp resp = new TExecuteStatementResp();
    try {
        SessionHandle sessionHandle = new SessionHandle(req.getSessionHandle());
        String statement = req.getStatement();
        Map<String, String> confOverlay = req.getConfOverlay();
        Boolean runAsync = req.isRunAsync();
        long queryTimeout = req.getQueryTimeout();
        OperationHandle operationHandle = runAsync ? cliService.executeStatementAsync(sessionHandle, statement, confOverlay, queryTimeout) : cliService.executeStatement(sessionHandle, statement, confOverlay, queryTimeout);
        resp.setOperationHandle(operationHandle.toTOperationHandle());
        resp.setStatus(OK_STATUS);
    } catch (Exception e) {
        // Note: it's rather important that this (and other methods) catch Exception, not Throwable;
        // in combination with HiveSessionProxy.invoke code, perhaps unintentionally, it used
        // to also catch all errors; and now it allows OOMs only to propagate.
        LOG.warn("Error executing statement: ", e);
        resp.setStatus(HiveSQLException.toTStatus(e));
    }
    return resp;
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) TExecuteStatementResp(org.apache.hive.service.rpc.thrift.TExecuteStatementResp) LoginException(javax.security.auth.login.LoginException) ServiceException(org.apache.hive.service.ServiceException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 48 with TException

use of org.apache.thrift.TException in project hive by apache.

the class ThriftCLIService method GetTableTypes.

@Override
public TGetTableTypesResp GetTableTypes(TGetTableTypesReq req) throws TException {
    TGetTableTypesResp resp = new TGetTableTypesResp();
    try {
        OperationHandle opHandle = cliService.getTableTypes(new SessionHandle(req.getSessionHandle()));
        resp.setOperationHandle(opHandle.toTOperationHandle());
        resp.setStatus(OK_STATUS);
    } catch (Exception e) {
        LOG.warn("Error getting table types: ", e);
        resp.setStatus(HiveSQLException.toTStatus(e));
    }
    return resp;
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) TGetTableTypesResp(org.apache.hive.service.rpc.thrift.TGetTableTypesResp) OperationHandle(org.apache.hive.service.cli.OperationHandle) LoginException(javax.security.auth.login.LoginException) ServiceException(org.apache.hive.service.ServiceException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 49 with TException

use of org.apache.thrift.TException in project hive by apache.

the class ThriftCLIService method GetPrimaryKeys.

@Override
public TGetPrimaryKeysResp GetPrimaryKeys(TGetPrimaryKeysReq req) throws TException {
    TGetPrimaryKeysResp resp = new TGetPrimaryKeysResp();
    try {
        OperationHandle opHandle = cliService.getPrimaryKeys(new SessionHandle(req.getSessionHandle()), req.getCatalogName(), req.getSchemaName(), req.getTableName());
        resp.setOperationHandle(opHandle.toTOperationHandle());
        resp.setStatus(OK_STATUS);
    } catch (Exception e) {
        LOG.warn("Error getting functions: ", e);
        resp.setStatus(HiveSQLException.toTStatus(e));
    }
    return resp;
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) TGetPrimaryKeysResp(org.apache.hive.service.rpc.thrift.TGetPrimaryKeysResp) OperationHandle(org.apache.hive.service.cli.OperationHandle) LoginException(javax.security.auth.login.LoginException) ServiceException(org.apache.hive.service.ServiceException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 50 with TException

use of org.apache.thrift.TException in project hive by apache.

the class ThriftCLIService method GetCatalogs.

@Override
public TGetCatalogsResp GetCatalogs(TGetCatalogsReq req) throws TException {
    TGetCatalogsResp resp = new TGetCatalogsResp();
    try {
        OperationHandle opHandle = cliService.getCatalogs(new SessionHandle(req.getSessionHandle()));
        resp.setOperationHandle(opHandle.toTOperationHandle());
        resp.setStatus(OK_STATUS);
    } catch (Exception e) {
        LOG.warn("Error getting catalogs: ", e);
        resp.setStatus(HiveSQLException.toTStatus(e));
    }
    return resp;
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) LoginException(javax.security.auth.login.LoginException) ServiceException(org.apache.hive.service.ServiceException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TGetCatalogsResp(org.apache.hive.service.rpc.thrift.TGetCatalogsResp)

Aggregations

TException (org.apache.thrift.TException)381 IOException (java.io.IOException)164 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)57 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)48 ArrayList (java.util.ArrayList)42 HashMap (java.util.HashMap)40 Table (org.apache.hadoop.hive.metastore.api.Table)38 Map (java.util.Map)30 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)29 AuthorizationException (org.apache.storm.generated.AuthorizationException)27 Test (org.junit.Test)26 List (java.util.List)25 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)24 UnknownHostException (java.net.UnknownHostException)23 TProtocol (org.apache.thrift.protocol.TProtocol)23 FileNotFoundException (java.io.FileNotFoundException)22 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)22 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)21 LoginException (javax.security.auth.login.LoginException)21 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)20