Search in sources :

Example 51 with MetacatRequestContext

use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.

the class ConnectorTableServiceProxy method delete.

/**
 * Calls the connector table service delete method.
 * @param name table name
 */
@CacheEvict(key = "'table.' + #name")
public void delete(final QualifiedName name) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorTableService service = connectorManager.getTableService(name);
    log.info("Drop table {}", name);
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    service.delete(connectorRequestContext, name);
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 52 with MetacatRequestContext

use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.

the class ConnectorTableServiceProxy method get.

/**
 * Returns table if <code>useCache</code> is true and object exists in the cache. If <code>useCache</code> is false
 * or object does not exists in the cache, it is retrieved from the store.
 * @param name table name
 * @param getTableServiceParameters  get table parameters
 * @param useCache true, if table can be retrieved from cache
 * @return table dto
 */
@Cacheable(key = "'table.' + #name", condition = "#useCache")
public TableInfo get(final QualifiedName name, final GetTableServiceParameters getTableServiceParameters, final boolean useCache) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    connectorRequestContext.setIncludeMetadata(getTableServiceParameters.isIncludeMetadataFromConnector());
    final ConnectorTableService service = connectorManager.getTableService(name);
    return service.get(connectorRequestContext, name);
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 53 with MetacatRequestContext

use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.

the class MViewServiceImpl method list.

/**
 * {@inheritDoc}
 */
@Override
public List<NameDateDto> list(final QualifiedName name) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName viewDbName = QualifiedName.ofDatabase(name.getCatalogName(), VIEW_DB_NAME);
    final ConnectorTableService service = connectorManager.getTableService(viewDbName);
    List<QualifiedName> tableNames = Lists.newArrayList();
    try {
        final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
        tableNames = service.listNames(connectorRequestContext, viewDbName, null, null, null);
    } catch (Exception ignored) {
    // ignore. Return an empty list if database 'franklinviews' does not exist
    }
    if (!name.isDatabaseDefinition() && name.isCatalogDefinition()) {
        return tableNames.stream().map(viewName -> {
            final NameDateDto dto = new NameDateDto();
            dto.setName(viewName);
            return dto;
        }).collect(Collectors.toList());
    } else {
        final String prefix = String.format("%s_%s_", name.getDatabaseName(), MoreObjects.firstNonNull(name.getTableName(), ""));
        return tableNames.stream().filter(qualifiedTableName -> qualifiedTableName.getTableName().startsWith(prefix)).map(qualifiedTableName -> {
            final NameDateDto dto = new NameDateDto();
            dto.setName(QualifiedName.ofView(qualifiedTableName.getCatalogName(), name.getDatabaseName(), name.getTableName(), qualifiedTableName.getTableName().substring(prefix.length())));
            return dto;
        }).collect(Collectors.toList());
    }
}
Also used : MViewService(com.netflix.metacat.main.services.MViewService) MetacatServiceHelper(com.netflix.metacat.main.services.MetacatServiceHelper) MetacatCreateMViewPreEvent(com.netflix.metacat.common.server.events.MetacatCreateMViewPreEvent) UserMetadataService(com.netflix.metacat.common.server.usermetadata.UserMetadataService) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatDeleteMViewPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPreEvent) MetacatEventBus(com.netflix.metacat.common.server.events.MetacatEventBus) MetacatSaveMViewPartitionPreEvent(com.netflix.metacat.common.server.events.MetacatSaveMViewPartitionPreEvent) ConverterUtil(com.netflix.metacat.common.server.converter.ConverterUtil) MetacatContextManager(com.netflix.metacat.common.server.util.MetacatContextManager) MetacatDeleteMViewPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPostEvent) PartitionService(com.netflix.metacat.main.services.PartitionService) MetacatUpdateMViewPostEvent(com.netflix.metacat.common.server.events.MetacatUpdateMViewPostEvent) StorageDto(com.netflix.metacat.common.dto.StorageDto) Function(java.util.function.Function) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PartitionsSaveResponseDto(com.netflix.metacat.common.dto.PartitionsSaveResponseDto) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) Lists(com.google.common.collect.Lists) TableService(com.netflix.metacat.main.services.TableService) Map(java.util.Map) MetacatCreateMViewPostEvent(com.netflix.metacat.common.server.events.MetacatCreateMViewPostEvent) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) MetacatDeleteMViewPartitionPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPreEvent) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) Nullable(javax.annotation.Nullable) MetacatDeleteMViewPartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPostEvent) NameDateDto(com.netflix.metacat.common.NameDateDto) GetPartitionsRequestDto(com.netflix.metacat.common.dto.GetPartitionsRequestDto) MetacatUpdateMViewPreEvent(com.netflix.metacat.common.server.events.MetacatUpdateMViewPreEvent) Pageable(com.netflix.metacat.common.dto.Pageable) MoreObjects(com.google.common.base.MoreObjects) MetacatSaveMViewPartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveMViewPartitionPostEvent) QualifiedName(com.netflix.metacat.common.QualifiedName) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) GetMetadataInterceptorParameters(com.netflix.metacat.common.server.usermetadata.GetMetadataInterceptorParameters) Optional(java.util.Optional) ConnectorManager(com.netflix.metacat.main.manager.ConnectorManager) GetTableServiceParameters(com.netflix.metacat.main.services.GetTableServiceParameters) Sort(com.netflix.metacat.common.dto.Sort) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) QualifiedName(com.netflix.metacat.common.QualifiedName) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) NameDateDto(com.netflix.metacat.common.NameDateDto) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)

Example 54 with MetacatRequestContext

use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.

the class MViewServiceImpl method createAndSnapshotPartitions.

/**
 * Creates the materialized view using the schema of the give table
 * Assumes that the "franklinviews" database name already exists in the given catalog.
 */
@Override
public TableDto createAndSnapshotPartitions(final QualifiedName name, final boolean snapshot, @Nullable final String filter) {
    final TableDto result;
    // Get the table
    log.info("Get the table {}", name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    eventBus.post(new MetacatCreateMViewPreEvent(name, metacatRequestContext, this, snapshot, filter));
    final Optional<TableDto> oTable = tableService.get(name, GetTableServiceParameters.builder().includeDataMetadata(false).includeDefinitionMetadata(false).disableOnReadMetadataIntercetor(// turn off for optimization
    true).includeInfo(true).build());
    if (oTable.isPresent()) {
        final TableDto table = oTable.get();
        final String viewName = createViewName(name);
        final QualifiedName targetName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, viewName);
        // Get the view table if it exists
        log.info("Check if the view table {} exists.", targetName);
        Optional<TableDto> oViewTable = Optional.empty();
        try {
            // read the original view back
            oViewTable = tableService.get(targetName, GetTableServiceParameters.builder().includeDataMetadata(false).includeDefinitionMetadata(false).disableOnReadMetadataIntercetor(false).includeInfo(true).build());
        } catch (NotFoundException ignored) {
        }
        if (!oViewTable.isPresent()) {
            log.info("Creating view {}.", targetName);
            // 
            if (MetacatServiceHelper.isIcebergTable(table)) {
                table.getFields().forEach(f -> f.setSource_type(null));
            }
            result = tableService.copy(table, targetName);
        } else {
            result = oViewTable.get();
        }
        if (snapshot) {
            snapshotPartitions(name, filter);
        }
        eventBus.post(new MetacatCreateMViewPostEvent(name, metacatRequestContext, this, result, snapshot, filter));
    } else {
        throw new TableNotFoundException(name);
    }
    return result;
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) 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) MetacatCreateMViewPostEvent(com.netflix.metacat.common.server.events.MetacatCreateMViewPostEvent) MetacatCreateMViewPreEvent(com.netflix.metacat.common.server.events.MetacatCreateMViewPreEvent)

Example 55 with MetacatRequestContext

use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.

the class DatabaseServiceImpl method create.

/**
 * {@inheritDoc}
 */
@Override
public DatabaseDto create(final QualifiedName name, final DatabaseDto dto) {
    validate(name);
    log.info("Creating schema {}", name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    eventBus.post(new MetacatCreateDatabasePreEvent(name, metacatRequestContext, this));
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    connectorManager.getDatabaseService(name).create(connectorRequestContext, converterUtil.fromDatabaseDto(dto));
    if (dto.getDefinitionMetadata() != null) {
        log.info("Saving user metadata for schema {}", name);
        userMetadataService.saveDefinitionMetadata(name, metacatRequestContext.getUserName(), Optional.of(dto.getDefinitionMetadata()), true);
    }
    final DatabaseDto createdDto = get(name, GetDatabaseServiceParameters.builder().disableOnReadMetadataIntercetor(true).includeUserMetadata(dto.getDefinitionMetadata() != null).includeTableNames(true).build());
    eventBus.post(new MetacatCreateDatabasePostEvent(name, metacatRequestContext, this, createdDto));
    return createdDto;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) MetacatCreateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatCreateDatabasePostEvent) MetacatCreateDatabasePreEvent(com.netflix.metacat.common.server.events.MetacatCreateDatabasePreEvent) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Aggregations

MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)65 QualifiedName (com.netflix.metacat.common.QualifiedName)28 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)24 TableDto (com.netflix.metacat.common.dto.TableDto)22 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)19 List (java.util.List)16 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)13 Collectors (java.util.stream.Collectors)12 Slf4j (lombok.extern.slf4j.Slf4j)12 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)11 Lists (com.google.common.collect.Lists)10 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)10 NotFoundException (com.netflix.metacat.common.server.connectors.exception.NotFoundException)10 Metrics (com.netflix.metacat.common.server.monitoring.Metrics)10 UserMetadataService (com.netflix.metacat.common.server.usermetadata.UserMetadataService)10 Registry (com.netflix.spectator.api.Registry)10 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)9 GetPartitionsRequestDto (com.netflix.metacat.common.dto.GetPartitionsRequestDto)9 MetacatUpdateTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent)9 Config (com.netflix.metacat.common.server.properties.Config)9