Search in sources :

Example 1 with ConnectorRequestContext

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

the class CatalogServiceImpl method get.

/**
 * {@inheritDoc}
 */
@Nonnull
@Override
public CatalogDto get(final QualifiedName name) {
    final Set<MetacatCatalogConfig> configs = connectorManager.getCatalogConfigs(name.getCatalogName());
    final CatalogDto result = new CatalogDto();
    result.setName(name);
    final ConnectorRequestContext context = converterUtil.toConnectorContext(MetacatContextManager.getContext());
    final List<String> databases = Lists.newArrayList();
    configs.forEach(config -> {
        QualifiedName qName = name;
        if (config.getSchemaWhitelist().isEmpty()) {
            result.setType(config.getType());
        } else {
            qName = QualifiedName.ofDatabase(name.getCatalogName(), config.getSchemaWhitelist().get(0));
        }
        databases.addAll(connectorManager.getDatabaseService(qName).listNames(context, name, null, null, null).stream().map(QualifiedName::getDatabaseName).filter(s -> config.getSchemaBlacklist().isEmpty() || !config.getSchemaBlacklist().contains(s)).filter(s -> config.getSchemaWhitelist().isEmpty() || config.getSchemaWhitelist().contains(s)).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList()));
    });
    result.setDatabases(databases);
    userMetadataService.populateMetadata(result, false);
    return result;
}
Also used : UserMetadataService(com.netflix.metacat.common.server.usermetadata.UserMetadataService) CatalogService(com.netflix.metacat.main.services.CatalogService) CreateCatalogDto(com.netflix.metacat.common.dto.CreateCatalogDto) MetacatEventBus(com.netflix.metacat.common.server.events.MetacatEventBus) ConverterUtil(com.netflix.metacat.common.server.converter.ConverterUtil) MetacatContextManager(com.netflix.metacat.common.server.util.MetacatContextManager) MetacatUpdateDatabasePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePreEvent) Set(java.util.Set) CatalogMappingDto(com.netflix.metacat.common.dto.CatalogMappingDto) QualifiedName(com.netflix.metacat.common.QualifiedName) MetacatCatalogConfig(com.netflix.metacat.common.server.spi.MetacatCatalogConfig) MetacatUpdateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePostEvent) Collectors(java.util.stream.Collectors) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) CatalogDto(com.netflix.metacat.common.dto.CatalogDto) List(java.util.List) Lists(com.google.common.collect.Lists) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorManager(com.netflix.metacat.main.manager.ConnectorManager) Nonnull(javax.annotation.Nonnull) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) CreateCatalogDto(com.netflix.metacat.common.dto.CreateCatalogDto) CatalogDto(com.netflix.metacat.common.dto.CatalogDto) MetacatCatalogConfig(com.netflix.metacat.common.server.spi.MetacatCatalogConfig) QualifiedName(com.netflix.metacat.common.QualifiedName) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) Nonnull(javax.annotation.Nonnull)

Example 2 with ConnectorRequestContext

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

the class TableServiceImpl method getQualifiedNames.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, List<QualifiedName>> getQualifiedNames(final List<String> uris, final boolean prefixSearch) {
    final Map<String, List<QualifiedName>> result = Maps.newHashMap();
    connectorManager.getTableServices().forEach(service -> {
        final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
        final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
        try {
            final Map<String, List<QualifiedName>> names = service.getTableNames(connectorRequestContext, uris, prefixSearch);
            names.forEach((uri, qNames) -> {
                final List<QualifiedName> existingNames = result.get(uri);
                if (existingNames == null) {
                    result.put(uri, qNames);
                } else {
                    existingNames.addAll(qNames);
                }
            });
        } catch (final UnsupportedOperationException uoe) {
            log.debug("Table service doesn't support getting table names by URI. Skipping");
        }
    });
    return result;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) List(java.util.List) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 3 with ConnectorRequestContext

use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext 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 4 with ConnectorRequestContext

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

the class HiveConnectorTableService method getTableNames.

@Override
public List<QualifiedName> getTableNames(final ConnectorRequestContext context, final QualifiedName name, final String filter, @Nullable final Integer limit) {
    try {
        if (name.isDatabaseDefinition()) {
            return metacatHiveClient.getTableNames(name.getDatabaseName(), filter, limit == null ? -1 : limit).stream().map(n -> QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(), n)).collect(Collectors.toList());
        } else {
            int limitSize = limit == null || limit < 0 ? Integer.MAX_VALUE : limit;
            final List<String> databaseNames = metacatHiveClient.getAllDatabases();
            final List<QualifiedName> result = Lists.newArrayList();
            for (int i = 0; i < databaseNames.size() && limitSize > 0; i++) {
                final String databaseName = databaseNames.get(i);
                final List<String> tableNames = metacatHiveClient.getTableNames(databaseName, filter, limitSize);
                limitSize = limitSize - tableNames.size();
                result.addAll(tableNames.stream().map(n -> QualifiedName.ofTable(name.getCatalogName(), databaseName, n)).collect(Collectors.toList()));
            }
            return result;
        }
    } catch (TException e) {
        final String message = String.format("Failed getting the table names for database %s", name);
        log.error(message);
        throw new ConnectorException(message);
    }
}
Also used : Getter(lombok.Getter) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HiveConfigConstants(com.netflix.metacat.connector.hive.util.HiveConfigConstants) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) Strings(com.google.common.base.Strings) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) FieldInfo(com.netflix.metacat.common.server.connectors.model.FieldInfo) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) Map(java.util.Map) Path(org.apache.hadoop.fs.Path) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) StorageInfo(com.netflix.metacat.common.server.connectors.model.StorageInfo) HiveConnectorInfoConverter(com.netflix.metacat.connector.hive.converters.HiveConnectorInfoConverter) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) Nullable(javax.annotation.Nullable) ImmutableMap(com.google.common.collect.ImmutableMap) Pageable(com.netflix.metacat.common.dto.Pageable) TException(org.apache.thrift.TException) QualifiedName(com.netflix.metacat.common.QualifiedName) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) HiveTableUtil(com.netflix.metacat.connector.hive.util.HiveTableUtil) TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) TableType(org.apache.hadoop.hive.metastore.TableType) ConnectorUtils(com.netflix.metacat.common.server.connectors.ConnectorUtils) Comparator(java.util.Comparator) Collections(java.util.Collections) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Sort(com.netflix.metacat.common.dto.Sort) TException(org.apache.thrift.TException) QualifiedName(com.netflix.metacat.common.QualifiedName) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException)

Example 5 with ConnectorRequestContext

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

the class HiveConnectorTableService method list.

/**
 * {@inheritDoc}.
 */
@Override
public List<TableInfo> list(final ConnectorRequestContext requestContext, final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    try {
        final List<TableInfo> tableInfos = Lists.newArrayList();
        for (String tableName : metacatHiveClient.getAllTables(name.getDatabaseName())) {
            final QualifiedName qualifiedName = QualifiedName.ofDatabase(name.getCatalogName(), tableName);
            if (prefix != null && !qualifiedName.toString().startsWith(prefix.toString())) {
                continue;
            }
            final Table table = metacatHiveClient.getTableByName(name.getDatabaseName(), tableName);
            tableInfos.add(hiveMetacatConverters.toTableInfo(name, table));
        }
        // supporting sort by name only
        if (sort != null) {
            ConnectorUtils.sort(tableInfos, sort, Comparator.comparing(p -> p.getName().getTableName()));
        }
        return ConnectorUtils.paginate(tableInfos, pageable);
    } catch (MetaException exception) {
        throw new DatabaseNotFoundException(name, exception);
    } catch (TException exception) {
        throw new ConnectorException(String.format("Failed list hive table %s", name), exception);
    }
}
Also used : Getter(lombok.Getter) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HiveConfigConstants(com.netflix.metacat.connector.hive.util.HiveConfigConstants) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) Strings(com.google.common.base.Strings) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) FieldInfo(com.netflix.metacat.common.server.connectors.model.FieldInfo) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) Map(java.util.Map) Path(org.apache.hadoop.fs.Path) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) StorageInfo(com.netflix.metacat.common.server.connectors.model.StorageInfo) HiveConnectorInfoConverter(com.netflix.metacat.connector.hive.converters.HiveConnectorInfoConverter) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) Nullable(javax.annotation.Nullable) ImmutableMap(com.google.common.collect.ImmutableMap) Pageable(com.netflix.metacat.common.dto.Pageable) TException(org.apache.thrift.TException) QualifiedName(com.netflix.metacat.common.QualifiedName) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) HiveTableUtil(com.netflix.metacat.connector.hive.util.HiveTableUtil) TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) TableType(org.apache.hadoop.hive.metastore.TableType) ConnectorUtils(com.netflix.metacat.common.server.connectors.ConnectorUtils) Comparator(java.util.Comparator) Collections(java.util.Collections) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Sort(com.netflix.metacat.common.dto.Sort) TException(org.apache.thrift.TException) Table(org.apache.hadoop.hive.metastore.api.Table) QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)

Aggregations

ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)37 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)25 QualifiedName (com.netflix.metacat.common.QualifiedName)21 List (java.util.List)20 Lists (com.google.common.collect.Lists)15 Collectors (java.util.stream.Collectors)15 Pageable (com.netflix.metacat.common.dto.Pageable)14 Sort (com.netflix.metacat.common.dto.Sort)14 Nullable (javax.annotation.Nullable)14 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)13 Map (java.util.Map)12 Slf4j (lombok.extern.slf4j.Slf4j)12 Strings (com.google.common.base.Strings)10 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)10 Maps (com.google.common.collect.Maps)9 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)9 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)8 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)8 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)7 Throwables (com.google.common.base.Throwables)6