Search in sources :

Example 26 with TableDto

use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.

the class TableServiceImpl method get.

@Override
public Optional<TableDto> get(@Nonnull final QualifiedName name, final boolean includeInfo, final boolean includeDefinitionMetadata, final boolean includeDataMetadata) {
    validate(name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
    final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
    final TableDto table;
    if (includeInfo) {
        try {
            table = converterUtil.toTableDto(service.get(connectorContext, name));
        } catch (NotFoundException ignored) {
            return Optional.empty();
        }
    } else {
        table = new TableDto();
        table.setName(name);
    }
    if (includeDefinitionMetadata) {
        final Optional<ObjectNode> definitionMetadata = userMetadataService.getDefinitionMetadata(name);
        if (definitionMetadata.isPresent()) {
            table.setDefinitionMetadata(definitionMetadata.get());
        }
    }
    if (includeDataMetadata) {
        TableDto dto = table;
        if (!includeInfo) {
            try {
                dto = converterUtil.toTableDto(service.get(connectorContext, name));
            } catch (NotFoundException ignored) {
            }
        }
        if (dto != null && dto.getSerde() != null) {
            final Optional<ObjectNode> dataMetadata = userMetadataService.getDataMetadata(dto.getSerde().getUri());
            if (dataMetadata.isPresent()) {
                table.setDataMetadata(dataMetadata.get());
            }
        }
    }
    return Optional.of(table);
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 27 with TableDto

use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.

the class MViewServiceImpl method getOpt.

@Override
public Optional<TableDto> getOpt(@Nonnull final QualifiedName name) {
    final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
    final Optional<TableDto> result = tableService.get(viewQName, false);
    //
    if (result.isPresent()) {
        final TableDto table = result.get();
        table.setName(name);
        final QualifiedName tableName = QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(), name.getTableName());
        final Optional<ObjectNode> definitionMetadata = userMetadataService.getDefinitionMetadata(tableName);
        if (definitionMetadata.isPresent()) {
            userMetadataService.populateMetadata(table, definitionMetadata.get(), null);
        }
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 28 with TableDto

use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.

the class MetacatServiceHelper method postPostUpdateEvent.

/**
     * Calls the right method of the event bus for the given qualified name.
     *
     * @param name                  name
     * @param metacatRequestContext context
     * @param oldDTo                dto
     * @param currentDto            dto
     */
public void postPostUpdateEvent(final QualifiedName name, final MetacatRequestContext metacatRequestContext, final BaseDto oldDTo, final BaseDto currentDto) {
    if (name.isPartitionDefinition()) {
        final List<PartitionDto> dtos = Lists.newArrayList();
        if (currentDto != null) {
            dtos.add((PartitionDto) currentDto);
        }
        // This request neither added nor updated partitions
        final PartitionsSaveResponseDto partitionsSaveResponseDto = new PartitionsSaveResponseDto();
        this.eventBus.postAsync(new MetacatSaveTablePartitionPostEvent(name, metacatRequestContext, this, dtos, partitionsSaveResponseDto));
    } else if (name.isTableDefinition()) {
        final MetacatUpdateTablePostEvent event = new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, (TableDto) oldDTo, (TableDto) currentDto);
        this.eventBus.postAsync(event);
    } else if (name.isDatabaseDefinition()) {
        this.eventBus.postAsync(new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this));
    } else {
        throw new IllegalArgumentException(String.format("Invalid name %s", name));
    }
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) MetacatSaveTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent) MetacatUpdateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePostEvent) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) TableDto(com.netflix.metacat.common.dto.TableDto) PartitionsSaveResponseDto(com.netflix.metacat.common.dto.PartitionsSaveResponseDto)

Example 29 with TableDto

use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.

the class CatalogThriftHiveMetastore method get_partitions_by_filter.

/**
     * {@inheritDoc}
     */
@Override
public List<Partition> get_partitions_by_filter(final String dbName, final String tblName, final String filter, final short maxParts) throws TException {
    return requestWrapper("get_partitions_by_filter", new Object[] { dbName, tblName, filter, maxParts }, () -> {
        final String databaseName = normalizeIdentifier(dbName);
        final String tableName = normalizeIdentifier(tblName);
        final TableDto tableDto = v1.getTable(catalogName, databaseName, tableName, true, false, false);
        final Integer maxValues = maxParts > 0 ? Short.toUnsignedInt(maxParts) : null;
        final List<PartitionDto> metacatPartitions = partV1.getPartitions(catalogName, dbName, tblName, filter, null, null, null, maxValues, false);
        final List<Partition> result = Lists.newArrayListWithCapacity(metacatPartitions.size());
        for (PartitionDto partition : metacatPartitions) {
            result.add(hiveConverters.metacatToHivePartition(partition, tableDto));
        }
        return result;
    });
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 30 with TableDto

use of com.netflix.metacat.common.dto.TableDto in project metacat by Netflix.

the class HiveConvertersImpl method hiveToMetacatTable.

/**
     * {@inheritDoc}
     */
@Override
public TableDto hiveToMetacatTable(final QualifiedName name, final Table table) {
    final TableDto dto = new TableDto();
    dto.setSerde(toStorageDto(table.getSd(), table.getOwner()));
    dto.setAudit(new AuditDto());
    dto.setName(name);
    if (table.isSetCreateTime()) {
        dto.getAudit().setCreatedDate(epochSecondsToDate(table.getCreateTime()));
    }
    dto.setMetadata(table.getParameters());
    final List<FieldSchema> nonPartitionColumns = table.getSd().getCols();
    final List<FieldSchema> partitionColumns = table.getPartitionKeys();
    final List<FieldDto> allFields = Lists.newArrayListWithCapacity(nonPartitionColumns.size() + partitionColumns.size());
    nonPartitionColumns.stream().map(field -> this.hiveToMetacatField(field, false)).forEachOrdered(allFields::add);
    partitionColumns.stream().map(field -> this.hiveToMetacatField(field, true)).forEachOrdered(allFields::add);
    dto.setFields(allFields);
    return dto;
}
Also used : TableDto(com.netflix.metacat.common.dto.TableDto) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) Date(java.util.Date) HashMap(java.util.HashMap) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) StorageDto(com.netflix.metacat.common.dto.StorageDto) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) Partition(org.apache.hadoop.hive.metastore.api.Partition) Warehouse(org.apache.hadoop.hive.metastore.Warehouse) LinkedHashMap(java.util.LinkedHashMap) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) AuditDto(com.netflix.metacat.common.dto.AuditDto) Splitter(com.google.common.base.Splitter) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) Nullable(javax.annotation.Nullable) QualifiedName(com.netflix.metacat.common.QualifiedName) FieldDto(com.netflix.metacat.common.dto.FieldDto) Instant(java.time.Instant) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) List(java.util.List) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Database(org.apache.hadoop.hive.metastore.api.Database) Collections(java.util.Collections) AuditDto(com.netflix.metacat.common.dto.AuditDto) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) TableDto(com.netflix.metacat.common.dto.TableDto) FieldDto(com.netflix.metacat.common.dto.FieldDto)

Aggregations

TableDto (com.netflix.metacat.common.dto.TableDto)37 QualifiedName (com.netflix.metacat.common.QualifiedName)14 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)12 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)10 Partition (org.apache.hadoop.hive.metastore.api.Partition)7 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)6 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)5 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)5 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)4 MetacatUpdateTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent)4 EventListener (org.springframework.context.event.EventListener)4 Splitter (com.google.common.base.Splitter)3 Strings (com.google.common.base.Strings)3 Lists (com.google.common.collect.Lists)3 FieldDto (com.netflix.metacat.common.dto.FieldDto)3 StorageDto (com.netflix.metacat.common.dto.StorageDto)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2