Search in sources :

Example 1 with TGetResultSetMetadataResp

use of org.apache.hive.service.rpc.thrift.TGetResultSetMetadataResp in project hive by apache.

the class HiveQueryResultSet method retrieveSchema.

/**
 * Retrieve schema from the server
 */
private void retrieveSchema() throws SQLException {
    try {
        TGetResultSetMetadataReq metadataReq = new TGetResultSetMetadataReq(stmtHandle);
        // TODO need session handle
        TGetResultSetMetadataResp metadataResp;
        metadataResp = client.GetResultSetMetadata(metadataReq);
        Utils.verifySuccess(metadataResp.getStatus());
        TTableSchema schema = metadataResp.getSchema();
        if (schema == null || !schema.isSetColumns()) {
            // TODO: should probably throw an exception here.
            return;
        }
        setSchema(new TableSchema(schema));
        for (final TColumnDesc column : schema.getColumns()) {
            String columnName = column.getColumnName();
            columnNames.add(columnName);
            normalizedColumnNames.add(columnName.toLowerCase());
            TPrimitiveTypeEntry primitiveTypeEntry = column.getTypeDesc().getTypes().get(0).getPrimitiveEntry();
            String columnTypeName = TYPE_NAMES.get(primitiveTypeEntry.getType());
            columnTypes.add(columnTypeName);
            columnAttributes.add(getColumnAttributes(primitiveTypeEntry));
        }
    } catch (SQLException eS) {
        // rethrow the SQLException as is
        throw eS;
    } catch (Exception ex) {
        throw new SQLException("Could not create ResultSet: " + ex.getMessage(), ex);
    }
}
Also used : TGetResultSetMetadataReq(org.apache.hive.service.rpc.thrift.TGetResultSetMetadataReq) TableSchema(org.apache.hive.service.cli.TableSchema) TTableSchema(org.apache.hive.service.rpc.thrift.TTableSchema) TPrimitiveTypeEntry(org.apache.hive.service.rpc.thrift.TPrimitiveTypeEntry) SQLException(java.sql.SQLException) TGetResultSetMetadataResp(org.apache.hive.service.rpc.thrift.TGetResultSetMetadataResp) TColumnDesc(org.apache.hive.service.rpc.thrift.TColumnDesc) TTableSchema(org.apache.hive.service.rpc.thrift.TTableSchema) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException)

Example 2 with TGetResultSetMetadataResp

use of org.apache.hive.service.rpc.thrift.TGetResultSetMetadataResp in project hive by apache.

the class ThriftCLIService method GetResultSetMetadata.

@Override
public TGetResultSetMetadataResp GetResultSetMetadata(TGetResultSetMetadataReq req) throws TException {
    TGetResultSetMetadataResp resp = new TGetResultSetMetadataResp();
    try {
        TableSchema schema = cliService.getResultSetMetadata(new OperationHandle(req.getOperationHandle()));
        resp.setSchema(schema.toTTableSchema());
        resp.setStatus(OK_STATUS);
    } catch (Exception e) {
        LOG.error("Failed to get result set metadata [request: {}]", req, e);
        resp.setStatus(HiveSQLException.toTStatus(e));
    }
    return resp;
}
Also used : TableSchema(org.apache.hive.service.cli.TableSchema) TGetResultSetMetadataResp(org.apache.hive.service.rpc.thrift.TGetResultSetMetadataResp) OperationHandle(org.apache.hive.service.cli.OperationHandle) ServiceException(org.apache.hive.service.ServiceException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) LoginException(javax.security.auth.login.LoginException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException)

Example 3 with TGetResultSetMetadataResp

use of org.apache.hive.service.rpc.thrift.TGetResultSetMetadataResp in project hive by apache.

the class ThriftCLIServiceClient method getResultSetMetadata.

/* (non-Javadoc)
   * @see org.apache.hive.service.cli.ICLIService#getResultSetMetadata(org.apache.hive.service.cli.OperationHandle)
   */
@Override
public TableSchema getResultSetMetadata(OperationHandle opHandle) throws HiveSQLException {
    try {
        TGetResultSetMetadataReq req = new TGetResultSetMetadataReq(opHandle.toTOperationHandle());
        TGetResultSetMetadataResp resp = cliService.GetResultSetMetadata(req);
        checkStatus(resp.getStatus());
        return new TableSchema(resp.getSchema());
    } catch (HiveSQLException e) {
        throw e;
    } catch (Exception e) {
        throw new HiveSQLException(e);
    }
}
Also used : TGetResultSetMetadataReq(org.apache.hive.service.rpc.thrift.TGetResultSetMetadataReq) TableSchema(org.apache.hive.service.cli.TableSchema) TGetResultSetMetadataResp(org.apache.hive.service.rpc.thrift.TGetResultSetMetadataResp) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException)

Aggregations

TableSchema (org.apache.hive.service.cli.TableSchema)3 TGetResultSetMetadataResp (org.apache.hive.service.rpc.thrift.TGetResultSetMetadataResp)3 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)2 TGetResultSetMetadataReq (org.apache.hive.service.rpc.thrift.TGetResultSetMetadataReq)2 TException (org.apache.thrift.TException)2 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 SQLException (java.sql.SQLException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 LoginException (javax.security.auth.login.LoginException)1 ServiceException (org.apache.hive.service.ServiceException)1 OperationHandle (org.apache.hive.service.cli.OperationHandle)1 TColumnDesc (org.apache.hive.service.rpc.thrift.TColumnDesc)1 TPrimitiveTypeEntry (org.apache.hive.service.rpc.thrift.TPrimitiveTypeEntry)1 TTableSchema (org.apache.hive.service.rpc.thrift.TTableSchema)1