Search in sources :

Example 21 with TableDto

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

the class MViewServiceImpl method deleteAndReturn.

/**
 * {@inheritDoc}
 */
@Override
public TableDto deleteAndReturn(final QualifiedName name) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    eventBus.postSync(new MetacatDeleteMViewPreEvent(name, metacatRequestContext, this));
    final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
    log.info("Deleting view {}.", viewQName);
    final TableDto deletedDto = tableService.deleteAndReturn(viewQName, true);
    eventBus.postAsync(new MetacatDeleteMViewPostEvent(name, metacatRequestContext, this, deletedDto));
    return deletedDto;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatDeleteMViewPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPreEvent) QualifiedName(com.netflix.metacat.common.QualifiedName) MetacatDeleteMViewPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPostEvent) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 22 with TableDto

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

the class TableServiceImpl method saveMetadata.

/**
 * {@inheritDoc}
 */
@Override
public void saveMetadata(final QualifiedName name, final ObjectNode definitionMetadata, final ObjectNode dataMetadata) {
    validate(name);
    final Optional<TableDto> tableDtoOptional = get(name, GetTableServiceParameters.builder().includeInfo(true).disableOnReadMetadataIntercetor(true).includeDefinitionMetadata(false).includeDataMetadata(false).build());
    if (tableDtoOptional.isPresent()) {
        final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
        final TableDto tableDto = tableDtoOptional.get();
        // override the previous one
        tableDto.setDefinitionMetadata(definitionMetadata);
        tableDto.setDataMetadata(dataMetadata);
        log.info("Saving user metadata for table {}", name);
        userMetadataService.saveMetadata(metacatRequestContext.getUserName(), tableDto, true);
        tag(name, tableDto.getDefinitionMetadata());
    }
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 23 with TableDto

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

the class TableServiceImpl method rename.

/**
 * {@inheritDoc}
 */
@Override
public void rename(final QualifiedName oldName, final QualifiedName newName, final boolean isMView) {
    validate(oldName);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorTableService service = connectorManager.getTableService(oldName);
    final TableDto oldTable = get(oldName, GetTableServiceParameters.builder().includeInfo(true).disableOnReadMetadataIntercetor(false).includeDefinitionMetadata(true).includeDataMetadata(true).build()).orElseThrow(() -> new TableNotFoundException(oldName));
    if (oldTable != null) {
        // Ignore if the operation is not supported, so that we can at least go ahead and save the user metadata
        eventBus.postSync(new MetacatRenameTablePreEvent(oldName, metacatRequestContext, this, newName));
        try {
            log.info("Renaming {} {} to {}", isMView ? "view" : "table", oldName, newName);
            final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
            service.rename(connectorRequestContext, oldName, newName);
        } catch (UnsupportedOperationException ignored) {
        }
        userMetadataService.renameDefinitionMetadataKey(oldName, newName);
        tagService.rename(oldName, newName.getTableName());
        final TableDto dto = get(newName, GetTableServiceParameters.builder().includeInfo(true).disableOnReadMetadataIntercetor(false).includeDefinitionMetadata(true).includeDataMetadata(true).build()).orElseThrow(() -> new IllegalStateException("should exist"));
        eventBus.postAsync(new MetacatRenameTablePostEvent(oldName, metacatRequestContext, this, oldTable, dto, isMView));
    }
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) MetacatRenameTablePreEvent(com.netflix.metacat.common.server.events.MetacatRenameTablePreEvent) TableDto(com.netflix.metacat.common.dto.TableDto) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) MetacatRenameTablePostEvent(com.netflix.metacat.common.server.events.MetacatRenameTablePostEvent)

Example 24 with TableDto

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

the class TableServiceImpl method deleteAndReturn.

/**
 * {@inheritDoc}
 */
@Override
public TableDto deleteAndReturn(final QualifiedName name, final boolean isMView) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    eventBus.postSync(new MetacatDeleteTablePreEvent(name, metacatRequestContext, this));
    validate(name);
    final ConnectorTableService service = connectorManager.getTableService(name);
    final Optional<TableDto> oTable = get(name, GetTableServiceParameters.builder().includeInfo(true).disableOnReadMetadataIntercetor(false).includeDefinitionMetadata(true).includeDataMetadata(true).build());
    if (oTable.isPresent()) {
        log.info("Drop table {}", name);
        final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
        service.delete(connectorRequestContext, name);
    }
    final TableDto tableDto = oTable.orElseGet(() -> {
        // If the table doesn't exist construct a blank copy we can use to delete the definitionMetadata and tags
        final TableDto t = new TableDto();
        t.setName(name);
        return t;
    });
    if (canDeleteMetadata(name)) {
        // Delete the metadata.  Type doesn't matter since we discard the result
        log.info("Deleting user metadata for table {}", name);
        userMetadataService.deleteMetadata(metacatRequestContext.getUserName(), Lists.newArrayList(tableDto));
        log.info("Deleting tags for table {}", name);
        tagService.delete(name, false);
    } else {
        if (config.canSoftDeleteDataMetadata() && tableDto.isDataExternal()) {
            userMetadataService.softDeleteDataMetadata(metacatRequestContext.getUserName(), Lists.newArrayList(tableDto.getDataUri()));
        }
    }
    eventBus.postAsync(new MetacatDeleteTablePostEvent(name, metacatRequestContext, this, tableDto, isMView));
    return tableDto;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) MetacatDeleteTablePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent) TableDto(com.netflix.metacat.common.dto.TableDto) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) MetacatDeleteTablePreEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePreEvent)

Example 25 with TableDto

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

the class TableServiceImpl method copy.

/**
 * {@inheritDoc}
 */
@Override
public TableDto copy(final TableDto tableDto, final QualifiedName targetName) {
    final QualifiedName databaseName = QualifiedName.ofDatabase(targetName.getCatalogName(), targetName.getDatabaseName());
    if (!databaseService.exists(databaseName)) {
        final DatabaseDto databaseDto = new DatabaseDto();
        databaseDto.setName(databaseName);
        databaseService.create(databaseName, databaseDto);
    }
    final TableDto targetTableDto = new TableDto();
    targetTableDto.setName(targetName);
    targetTableDto.setFields(tableDto.getFields());
    targetTableDto.setPartition_keys(tableDto.getPartition_keys());
    final StorageDto storageDto = tableDto.getSerde();
    if (storageDto != null) {
        final StorageDto targetStorageDto = new StorageDto();
        targetStorageDto.setInputFormat(storageDto.getInputFormat());
        targetStorageDto.setOwner(storageDto.getOwner());
        targetStorageDto.setOutputFormat(storageDto.getOutputFormat());
        targetStorageDto.setParameters(storageDto.getParameters());
        targetStorageDto.setUri(storageDto.getUri());
        targetStorageDto.setSerializationLib(storageDto.getSerializationLib());
        targetTableDto.setSerde(targetStorageDto);
    }
    create(targetName, targetTableDto);
    return targetTableDto;
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) TableDto(com.netflix.metacat.common.dto.TableDto) StorageDto(com.netflix.metacat.common.dto.StorageDto)

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