Search in sources :

Example 1 with ConnectorTableService

use of com.netflix.metacat.common.server.connectors.ConnectorTableService in project metacat by Netflix.

the class TableServiceImpl method exists.

/**
 * {@inheritDoc}
 */
@Override
public boolean exists(final QualifiedName name) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorTableService service = connectorManager.getTableService(name);
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    return service.exists(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)

Example 2 with ConnectorTableService

use of com.netflix.metacat.common.server.connectors.ConnectorTableService in project metacat by Netflix.

the class ConnectorTableServiceProxy method create.

/**
 * Calls the connector table service create method.
 * @param name table name
 * @param tableInfo table object
 */
public void create(final QualifiedName name, final TableInfo tableInfo) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorTableService service = connectorManager.getTableService(name);
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    service.create(connectorRequestContext, tableInfo);
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 3 with ConnectorTableService

use of com.netflix.metacat.common.server.connectors.ConnectorTableService in project metacat by Netflix.

the class ConnectorTableServiceProxy method update.

/**
 * Calls the connector table service update method.
 * @param name table name
 * @param tableInfo table object
 * @return true if errors after this should be ignored.
 */
@CacheEvict(key = "'table.' + #name")
public boolean update(final QualifiedName name, final TableInfo tableInfo) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorTableService service = connectorManager.getTableService(name);
    boolean result = false;
    try {
        log.info("Updating table {}", name);
        final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
        service.update(connectorRequestContext, tableInfo);
        result = connectorRequestContext.isIgnoreErrorsAfterUpdate();
    } catch (UnsupportedOperationException ignored) {
        // Ignore if the operation is not supported, so that we can at least go ahead and save the user metadata.
        log.debug("Catalog {} does not support the table update operation.", name.getCatalogName());
    }
    return result;
}
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 4 with ConnectorTableService

use of com.netflix.metacat.common.server.connectors.ConnectorTableService in project metacat by Netflix.

the class DatabaseServiceImpl method get.

/**
 * {@inheritDoc}
 */
@Override
public DatabaseDto get(final QualifiedName name, final GetDatabaseServiceParameters getDatabaseServiceParameters) {
    validate(name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final MetacatCatalogConfig config = connectorManager.getCatalogConfig(name);
    final ConnectorDatabaseService service = connectorManager.getDatabaseService(name);
    final ConnectorTableService tableService = connectorManager.getTableService(name);
    // Prepare the connector request
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    connectorRequestContext.setIncludeMetadata(getDatabaseServiceParameters.isIncludeMetadataFromConnector());
    final DatabaseDto dto = converterUtil.toDatabaseDto(service.get(connectorRequestContext, name));
    dto.setType(config.getType());
    if (getDatabaseServiceParameters.isIncludeTableNames()) {
        final List<QualifiedName> tableNames = tableService.listNames(connectorRequestContext, name, null, null, null);
        List<QualifiedName> viewNames = Collections.emptyList();
        if (config.isIncludeViewsWithTables()) {
            // TODO JdbcMetadata returns ImmutableList.of() for views.  We should change it to fetch views.
            try {
                viewNames = service.listViewNames(connectorRequestContext, name);
            } catch (UnsupportedOperationException ignored) {
            }
        }
        // Check to see if schema exists
        if (tableNames.isEmpty() && viewNames.isEmpty() && !exists(name)) {
            throw new DatabaseNotFoundException(name);
        }
        dto.setTables(Stream.concat(tableNames.stream(), viewNames.stream()).map(QualifiedName::getTableName).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList()));
    }
    if (getDatabaseServiceParameters.isIncludeUserMetadata()) {
        log.info("Populate user metadata for schema {}", name);
        userMetadataService.populateMetadata(dto, getDatabaseServiceParameters.isDisableOnReadMetadataIntercetor());
    }
    return dto;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorDatabaseService(com.netflix.metacat.common.server.connectors.ConnectorDatabaseService) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) MetacatCatalogConfig(com.netflix.metacat.common.server.spi.MetacatCatalogConfig) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 5 with ConnectorTableService

use of com.netflix.metacat.common.server.connectors.ConnectorTableService 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)

Aggregations

MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)12 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)12 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)10 QualifiedName (com.netflix.metacat.common.QualifiedName)3 CacheEvict (org.springframework.cache.annotation.CacheEvict)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)2 TableDto (com.netflix.metacat.common.dto.TableDto)2 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)2 ConnectorDatabaseService (com.netflix.metacat.common.server.connectors.ConnectorDatabaseService)2 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)2 NotFoundException (com.netflix.metacat.common.server.connectors.exception.NotFoundException)2 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)2 MoreObjects (com.google.common.base.MoreObjects)1 Lists (com.google.common.collect.Lists)1 NameDateDto (com.netflix.metacat.common.NameDateDto)1 GetPartitionsRequestDto (com.netflix.metacat.common.dto.GetPartitionsRequestDto)1 Pageable (com.netflix.metacat.common.dto.Pageable)1 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)1 PartitionsSaveRequestDto (com.netflix.metacat.common.dto.PartitionsSaveRequestDto)1