Search in sources :

Example 1 with ViewInfo

use of com.netflix.metacat.common.server.connectors.model.ViewInfo in project metacat by Netflix.

the class HiveConnectorInfoConverter method fromTableInfo.

/**
 * Converts from TableDto to the connector table.
 *
 * @param tableInfo Metacat table Info
 * @return connector table
 */
@Override
public Table fromTableInfo(final TableInfo tableInfo) {
    final QualifiedName name = tableInfo.getName();
    final String tableName = (name != null) ? name.getTableName() : "";
    final String databaseName = (name != null) ? name.getDatabaseName() : "";
    final StorageInfo storageInfo = tableInfo.getSerde();
    final String owner = (storageInfo != null && storageInfo.getOwner() != null) ? storageInfo.getOwner() : "";
    final AuditInfo auditInfo = tableInfo.getAudit();
    final int createTime = (auditInfo != null && auditInfo.getCreatedDate() != null) ? dateToEpochSeconds(auditInfo.getCreatedDate()) : 0;
    final Map<String, String> params = (tableInfo.getMetadata() != null) ? tableInfo.getMetadata() : new HashMap<>();
    final List<FieldInfo> fields = tableInfo.getFields();
    List<FieldSchema> partitionFields = Collections.emptyList();
    List<FieldSchema> nonPartitionFields = Collections.emptyList();
    if (fields != null) {
        nonPartitionFields = Lists.newArrayListWithCapacity(fields.size());
        partitionFields = Lists.newArrayListWithCapacity(fields.size());
        for (FieldInfo fieldInfo : fields) {
            if (fieldInfo.isPartitionKey()) {
                partitionFields.add(metacatToHiveField(fieldInfo));
            } else {
                nonPartitionFields.add(metacatToHiveField(fieldInfo));
            }
        }
    }
    final StorageDescriptor sd = fromStorageInfo(storageInfo, nonPartitionFields);
    final ViewInfo viewInfo = tableInfo.getView();
    final String tableType = (null != viewInfo && !Strings.isNullOrEmpty(viewInfo.getViewOriginalText())) ? TableType.VIRTUAL_VIEW.name() : TableType.EXTERNAL_TABLE.name();
    return new Table(tableName, databaseName, owner, createTime, 0, 0, sd, partitionFields, params, tableType.equals(TableType.VIRTUAL_VIEW.name()) ? tableInfo.getView().getViewOriginalText() : null, tableType.equals(TableType.VIRTUAL_VIEW.name()) ? tableInfo.getView().getViewExpandedText() : null, tableType);
}
Also used : AuditInfo(com.netflix.metacat.common.server.connectors.model.AuditInfo) Table(org.apache.hadoop.hive.metastore.api.Table) QualifiedName(com.netflix.metacat.common.QualifiedName) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) ViewInfo(com.netflix.metacat.common.server.connectors.model.ViewInfo) StorageInfo(com.netflix.metacat.common.server.connectors.model.StorageInfo) FieldInfo(com.netflix.metacat.common.server.connectors.model.FieldInfo)

Aggregations

QualifiedName (com.netflix.metacat.common.QualifiedName)1 AuditInfo (com.netflix.metacat.common.server.connectors.model.AuditInfo)1 FieldInfo (com.netflix.metacat.common.server.connectors.model.FieldInfo)1 StorageInfo (com.netflix.metacat.common.server.connectors.model.StorageInfo)1 ViewInfo (com.netflix.metacat.common.server.connectors.model.ViewInfo)1 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)1 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)1 Table (org.apache.hadoop.hive.metastore.api.Table)1