Search in sources :

Example 1 with TableDto

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

the class ConverterUtil method toTableDto.

/**
     * Converts from TableInfo to TableDto.
     *
     * @param tableInfo connector table info
     * @return table dto
     */
public TableDto toTableDto(final TableInfo tableInfo) {
    final TableDto result = this.mapper.map(tableInfo, TableDto.class);
    //TODO: Add this logic in the mapping
    final List<FieldDto> fields = result.getFields();
    if (fields != null) {
        int index = 0;
        for (final FieldDto field : fields) {
            field.setPos(index++);
        }
    }
    return result;
}
Also used : TableDto(com.netflix.metacat.common.dto.TableDto) FieldDto(com.netflix.metacat.common.dto.FieldDto)

Example 2 with TableDto

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

the class TagV1Resource method removeTableTags.

/**
     * {@inheritDoc}
     */
@Override
public void removeTableTags(final String catalogName, final String databaseName, final String tableName, final Boolean deleteAll, final Set<String> tags) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
    requestWrapper.processRequest(name, "TagV1Resource.removeTableTags", () -> {
        if (!tableService.exists(name)) {
            // Delete tags if exists
            tagService.delete(name, false);
            throw new TableNotFoundException(name);
        }
        final TableDto oldTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        tagService.removeTableTags(name, deleteAll, tags, true);
        final TableDto currentTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
        return null;
    });
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 3 with TableDto

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

the class TagV1Resource method setTableTags.

/**
     * {@inheritDoc}
     */
@Override
public Set<String> setTableTags(final String catalogName, final String databaseName, final String tableName, final Set<String> tags) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
    return requestWrapper.processRequest(name, "TagV1Resource.setTableTags", () -> {
        if (!tableService.exists(name)) {
            throw new TableNotFoundException(name);
        }
        final TableDto oldTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        final Set<String> result = tagService.setTableTags(name, tags, true);
        final TableDto currentTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
        return result;
    });
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 4 with TableDto

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

the class PartitionV1Resource method savePartitions.

/**
     * {@inheritDoc}
     */
@Override
public PartitionsSaveResponseDto savePartitions(final String catalogName, final String databaseName, final String tableName, final String viewName, final PartitionsSaveRequestDto partitionsSaveRequestDto) {
    final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofView(catalogName, databaseName, tableName, viewName));
    return requestWrapper.processRequest(name, "saveMViewPartition", () -> {
        final PartitionsSaveResponseDto result;
        if (partitionsSaveRequestDto == null || partitionsSaveRequestDto.getPartitions() == null || partitionsSaveRequestDto.getPartitions().isEmpty()) {
            result = new PartitionsSaveResponseDto();
        } else {
            result = mViewService.savePartitions(name, partitionsSaveRequestDto, true);
            // This metadata is actually for the view, if it is present update that
            if (partitionsSaveRequestDto.getDefinitionMetadata() != null || partitionsSaveRequestDto.getDataMetadata() != null) {
                final TableDto dto = v1.getMView(catalogName, databaseName, tableName, viewName);
                dto.setDefinitionMetadata(partitionsSaveRequestDto.getDefinitionMetadata());
                dto.setDataMetadata(partitionsSaveRequestDto.getDataMetadata());
                v1.updateMView(catalogName, databaseName, tableName, viewName, dto);
            }
        }
        return result;
    });
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto) PartitionsSaveResponseDto(com.netflix.metacat.common.dto.PartitionsSaveResponseDto)

Example 5 with TableDto

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

the class MetacatElasticSearchEventHandlers method metacatUpdateTablePostEventHandler.

/**
     * Subscriber.
     *
     * @param event event
     */
@EventListener
public void metacatUpdateTablePostEventHandler(final MetacatUpdateTablePostEvent event) {
    log.debug("Received UpdateTableEvent {}", event);
    registry.counter(Metrics.CounterElasticSearchTableUpdate.name()).increment();
    final TableDto dto = event.getCurrentTable();
    final ElasticSearchDoc doc = new ElasticSearchDoc(dto.getName().toString(), dto, event.getRequestContext().getUserName(), false);
    final ElasticSearchDoc oldDoc = es.get(ElasticSearchDoc.Type.table.name(), doc.getId());
    es.save(ElasticSearchDoc.Type.table.name(), doc.getId(), doc.toJsonString());
    if (oldDoc == null || oldDoc.getDto() == null || !Objects.equals(((TableDto) oldDoc.getDto()).getDataMetadata(), dto.getDataMetadata())) {
        updateEntitiesWithSameUri(ElasticSearchDoc.Type.table.name(), dto, event.getRequestContext());
    }
}
Also used : TableDto(com.netflix.metacat.common.dto.TableDto) EventListener(org.springframework.context.event.EventListener)

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