Search in sources :

Example 41 with TableDto

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

the class TableServiceImpl method updateAndReturn.

/**
 * {@inheritDoc}
 */
@Override
public TableDto updateAndReturn(final QualifiedName name, final TableDto tableDto) {
    validate(name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorTableService service = connectorManager.getTableService(name);
    final TableDto oldTable = get(name, GetTableServiceParameters.builder().disableOnReadMetadataIntercetor(false).includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).build()).orElseThrow(() -> new TableNotFoundException(name));
    eventBus.postSync(new MetacatUpdateTablePreEvent(name, metacatRequestContext, this, oldTable, tableDto));
    // Ignore if the operation is not supported, so that we can at least go ahead and save the user metadata
    if (isTableInfoProvided(tableDto)) {
        try {
            log.info("Updating table {}", name);
            final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
            service.update(connectorRequestContext, converterUtil.fromTableDto(tableDto));
        } catch (UnsupportedOperationException ignored) {
        }
    }
    // Merge in metadata if the user sent any
    if (tableDto.getDataMetadata() != null || tableDto.getDefinitionMetadata() != null) {
        log.info("Saving user metadata for table {}", name);
        final long start = registry.clock().wallTime();
        userMetadataService.saveMetadata(metacatRequestContext.getUserName(), tableDto, true);
        final long duration = registry.clock().wallTime() - start;
        log.info("Time taken to save user metadata for table {} is {} ms", name, duration);
        registry.timer(registry.createId(Metrics.TimerSaveTableMetadata.getMetricName()).withTags(name.parts())).record(duration, TimeUnit.MILLISECONDS);
    }
    final TableDto updatedDto = get(name, GetTableServiceParameters.builder().disableOnReadMetadataIntercetor(false).includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).build()).orElseThrow(() -> new IllegalStateException("should exist"));
    eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, updatedDto));
    return updatedDto;
}
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) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) TableDto(com.netflix.metacat.common.dto.TableDto) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) MetacatUpdateTablePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent)

Example 42 with TableDto

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

the class ElasticSearchEventHandlers method metacatCreateTablePostEventHandler.

/**
 * Subscriber.
 *
 * @param event event
 */
@EventListener
public void metacatCreateTablePostEventHandler(final MetacatCreateTablePostEvent event) {
    log.debug("Received CreateTableEvent {}", event);
    this.tableCreateEventsDelayTimer.record(System.currentTimeMillis() - event.getRequestContext().getTimestamp(), TimeUnit.MILLISECONDS);
    this.tableCreateTimer.record(() -> {
        final TableDto dto = event.getTable();
        final ElasticSearchDoc doc = new ElasticSearchDoc(dto.getName().toString(), dto, event.getRequestContext().getUserName(), false);
        es.save(ElasticSearchDoc.Type.table.name(), doc.getId(), doc);
    });
}
Also used : TableDto(com.netflix.metacat.common.dto.TableDto) EventListener(org.springframework.context.event.EventListener)

Example 43 with TableDto

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

the class ElasticSearchEventHandlers method metacatUpdateTablePostEventHandler.

/**
 * Subscriber.
 *
 * @param event event
 */
@EventListener
public void metacatUpdateTablePostEventHandler(final MetacatUpdateTablePostEvent event) {
    log.debug("Received UpdateTableEvent {}", event);
    this.tableUpdateEventsDelayTimer.record(System.currentTimeMillis() - event.getRequestContext().getTimestamp(), TimeUnit.MILLISECONDS);
    this.tableUpdateTimer.record(() -> {
        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);
        if (oldDoc == null || oldDoc.getDto() == null || !Objects.equals(((TableDto) oldDoc.getDto()).getDataMetadata(), dto.getDataMetadata())) {
            updateEntitiesWithSameUri(ElasticSearchDoc.Type.table.name(), dto, event.getRequestContext().getUserName());
        }
    });
}
Also used : TableDto(com.netflix.metacat.common.dto.TableDto) EventListener(org.springframework.context.event.EventListener)

Example 44 with TableDto

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

the class ElasticSearchEventHandlers method updateEntitiesWithSameUri.

private void updateEntitiesWithSameUri(final String metadataType, final TableDto dto, final String userName) {
    if (dto.isDataExternal()) {
        final List<String> ids = es.getTableIdsByUri(metadataType, dto.getDataUri()).stream().filter(s -> !s.equals(dto.getName().toString())).collect(Collectors.toList());
        if (!ids.isEmpty()) {
            final ObjectNode node = metacatJsonLocator.emptyObjectNode();
            node.set(ElasticSearchDoc.Field.DATA_METADATA, dto.getDataMetadata());
            node.put(ElasticSearchDoc.Field.USER, userName);
            node.put(ElasticSearchDoc.Field.TIMESTAMP, java.time.Instant.now().toEpochMilli());
            es.updates(ElasticSearchDoc.Type.table.name(), ids, node);
        }
    }
}
Also used : MetacatDeleteTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent) MetacatDeleteTablePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent) MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatRenameTablePostEvent(com.netflix.metacat.common.server.events.MetacatRenameTablePostEvent) EventListener(org.springframework.context.event.EventListener) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) MetacatDeleteDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteDatabasePostEvent) Collectors(java.util.stream.Collectors) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MetacatJsonLocator(com.netflix.metacat.common.json.MetacatJsonLocator) MetacatCreateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatCreateDatabasePostEvent) Timer(com.netflix.spectator.api.Timer) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) MetacatCreateTablePostEvent(com.netflix.metacat.common.server.events.MetacatCreateTablePostEvent) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) Registry(com.netflix.spectator.api.Registry) MetacatSaveTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) Config(com.netflix.metacat.common.server.properties.Config) Metrics(com.netflix.metacat.common.server.monitoring.Metrics) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 45 with TableDto

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

the class CatalogThriftHiveMetastore method drop_partition_with_environment_context.

/**
 * {@inheritDoc}
 */
@Override
public boolean drop_partition_with_environment_context(final String dbName, final String tblName, final List<String> partVals, final boolean deleteData, @Nullable final EnvironmentContext environmentContext) throws TException {
    return requestWrapper("drop_partition_with_environment_context", new Object[] { dbName, tblName, partVals, deleteData, environmentContext }, () -> {
        final TableDto tableDto = getTableDto(dbName, tblName);
        final String partName = hiveConverters.getNameFromPartVals(tableDto, partVals);
        final QualifiedName partitionName = getPartitionDtoByName(tableDto, partName).getName();
        if (deleteData) {
            log.warn("Ignoring command to delete data for {}/{}/{}/{}", catalogName, tableDto.getName().getDatabaseName(), tableDto.getName().getTableName(), partitionName.getPartitionName());
        }
        partV1.deletePartitions(catalogName, tableDto.getName().getDatabaseName(), tableDto.getName().getTableName(), ImmutableList.of(partitionName.getPartitionName()));
        return true;
    });
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto)

Aggregations

TableDto (com.netflix.metacat.common.dto.TableDto)50 QualifiedName (com.netflix.metacat.common.QualifiedName)19 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)17 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)13 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)9 EventListener (org.springframework.context.event.EventListener)9 MetacatUpdateTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent)7 Partition (org.apache.hadoop.hive.metastore.api.Partition)7 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)6 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)5 MetacatDeleteTablePostEvent (com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent)5 Splitter (com.google.common.base.Splitter)4 Strings (com.google.common.base.Strings)4 Lists (com.google.common.collect.Lists)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 FieldDto (com.netflix.metacat.common.dto.FieldDto)3 PartitionsSaveRequestDto (com.netflix.metacat.common.dto.PartitionsSaveRequestDto)3