Search in sources :

Example 1 with TPrimitiveTypeEntry

use of org.apache.hive.service.rpc.thrift.TPrimitiveTypeEntry 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());
        StringBuilder namesSb = new StringBuilder();
        StringBuilder typesSb = new StringBuilder();
        TTableSchema schema = metadataResp.getSchema();
        if (schema == null || !schema.isSetColumns()) {
            // TODO: should probably throw an exception here.
            return;
        }
        setSchema(new TableSchema(schema));
        List<TColumnDesc> columns = schema.getColumns();
        for (int pos = 0; pos < schema.getColumnsSize(); pos++) {
            if (pos != 0) {
                namesSb.append(",");
                typesSb.append(",");
            }
            String columnName = columns.get(pos).getColumnName();
            columnNames.add(columnName);
            normalizedColumnNames.add(columnName.toLowerCase());
            TPrimitiveTypeEntry primitiveTypeEntry = columns.get(pos).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) {
        ex.printStackTrace();
        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 TPrimitiveTypeEntry

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

the class TypeDescriptor method toTTypeDesc.

public TTypeDesc toTTypeDesc() {
    TPrimitiveTypeEntry primitiveEntry = new TPrimitiveTypeEntry(type.toTType());
    if (getTypeQualifiers() != null) {
        primitiveEntry.setTypeQualifiers(getTypeQualifiers().toTTypeQualifiers());
    }
    TTypeEntry entry = TTypeEntry.primitiveEntry(primitiveEntry);
    TTypeDesc desc = new TTypeDesc();
    desc.addToTypes(entry);
    return desc;
}
Also used : TPrimitiveTypeEntry(org.apache.hive.service.rpc.thrift.TPrimitiveTypeEntry) TTypeDesc(org.apache.hive.service.rpc.thrift.TTypeDesc) TTypeEntry(org.apache.hive.service.rpc.thrift.TTypeEntry)

Aggregations

TPrimitiveTypeEntry (org.apache.hive.service.rpc.thrift.TPrimitiveTypeEntry)2 SQLException (java.sql.SQLException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 TableSchema (org.apache.hive.service.cli.TableSchema)1 TColumnDesc (org.apache.hive.service.rpc.thrift.TColumnDesc)1 TGetResultSetMetadataReq (org.apache.hive.service.rpc.thrift.TGetResultSetMetadataReq)1 TGetResultSetMetadataResp (org.apache.hive.service.rpc.thrift.TGetResultSetMetadataResp)1 TTableSchema (org.apache.hive.service.rpc.thrift.TTableSchema)1 TTypeDesc (org.apache.hive.service.rpc.thrift.TTypeDesc)1 TTypeEntry (org.apache.hive.service.rpc.thrift.TTypeEntry)1