Search in sources :

Example 61 with QualifiedName

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

the class DatabaseServiceImpl method get.

@Override
public DatabaseDto get(@Nonnull final QualifiedName name, final boolean includeUserMetadata) {
    validate(name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final MetacatCatalogConfig config = connectorManager.getCatalogConfig(name.getCatalogName());
    final ConnectorDatabaseService service = connectorManager.getDatabaseService(name.getCatalogName());
    final ConnectorTableService tableService = connectorManager.getTableService(name.getCatalogName());
    final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
    final List<QualifiedName> tableNames = tableService.listNames(connectorContext, 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(connectorContext, name);
        } catch (UnsupportedOperationException ignored) {
        }
    }
    // Check to see if schema exists
    if (tableNames.isEmpty() && viewNames.isEmpty() && !exists(name)) {
        throw new DatabaseNotFoundException(name);
    }
    final DatabaseDto dto = converterUtil.toDatabaseDto(service.get(connectorContext, name));
    dto.setType(connectorManager.getCatalogConfig(name).getType());
    dto.setTables(Stream.concat(tableNames.stream(), viewNames.stream()).map(QualifiedName::getTableName).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList()));
    if (includeUserMetadata) {
        log.info("Populate user metadata for schema {}", name);
        userMetadataService.populateMetadata(dto);
    }
    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.main.spi.MetacatCatalogConfig) QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext)

Example 62 with QualifiedName

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

the class MViewServiceImpl method deletePartitions.

@Override
public void deletePartitions(@Nonnull final QualifiedName name, final List<String> partitionIds) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final PartitionsSaveRequestDto dto = new PartitionsSaveRequestDto();
    dto.setPartitionIdsForDeletes(partitionIds);
    eventBus.postSync(new MetacatDeleteMViewPartitionPreEvent(name, metacatRequestContext, this, dto));
    final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
    partitionService.delete(viewQName, partitionIds);
    eventBus.postAsync(new MetacatDeleteMViewPartitionPostEvent(name, metacatRequestContext, this, partitionIds));
}
Also used : PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatDeleteMViewPartitionPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPreEvent) MetacatDeleteMViewPartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPostEvent) QualifiedName(com.netflix.metacat.common.QualifiedName)

Example 63 with QualifiedName

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

the class MViewServiceImpl method rename.

@Override
public void rename(@Nonnull final QualifiedName name, @Nonnull final QualifiedName newViewName) {
    final QualifiedName oldViewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
    final QualifiedName newViewQName = QualifiedName.ofTable(newViewName.getCatalogName(), VIEW_DB_NAME, createViewName(newViewName));
    tableService.rename(oldViewQName, newViewQName, true);
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName)

Example 64 with QualifiedName

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

the class MViewServiceImpl method getOpt.

@Override
public Optional<TableDto> getOpt(@Nonnull final QualifiedName name) {
    final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
    final Optional<TableDto> result = tableService.get(viewQName, false);
    //
    if (result.isPresent()) {
        final TableDto table = result.get();
        table.setName(name);
        final QualifiedName tableName = QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(), name.getTableName());
        final Optional<ObjectNode> definitionMetadata = userMetadataService.getDefinitionMetadata(tableName);
        if (definitionMetadata.isPresent()) {
            userMetadataService.populateMetadata(table, definitionMetadata.get(), null);
        }
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 65 with QualifiedName

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

the class MViewServiceImpl method delete.

@Override
public void delete(@Nonnull final QualifiedName name) {
    final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
    tableService.deleteAndReturn(viewQName, true);
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName)

Aggregations

QualifiedName (com.netflix.metacat.common.QualifiedName)85 List (java.util.List)31 Lists (com.google.common.collect.Lists)25 Collectors (java.util.stream.Collectors)24 Map (java.util.Map)23 Nonnull (javax.annotation.Nonnull)23 Strings (com.google.common.base.Strings)20 Slf4j (lombok.extern.slf4j.Slf4j)20 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)19 TableDto (com.netflix.metacat.common.dto.TableDto)19 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)17 Pageable (com.netflix.metacat.common.dto.Pageable)16 Sort (com.netflix.metacat.common.dto.Sort)16 Maps (com.google.common.collect.Maps)14 Connection (java.sql.Connection)14 SQLException (java.sql.SQLException)14 NonNull (lombok.NonNull)14 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)13 Nullable (javax.annotation.Nullable)13 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)12