Search in sources :

Example 31 with ConnectorRequestContext

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

the class HiveConnectorPartitionService method savePartitions.

/**
 * By default(checkIfExists=true and aletrIfExists=false), this method adds the provided list of partitions.
 * If a partition already exists, it is dropped first before adding it.
 * If checkIfExists=false, the method adds the partitions to the table. If a partition already exists,
 * an AlreadyExistsException error is thrown.
 * If alterIfExists=true, the method updates existing partitions and adds non-existant partitions.
 * If a partition in the provided partition list has all the details, then it is used. If the details are missing,
 * then the table details are inherited. This is mostly for the storage information.
 */
@Override
public PartitionsSaveResponse savePartitions(final ConnectorRequestContext requestContext, final QualifiedName tableQName, final PartitionsSaveRequest partitionsSaveRequest) {
    final String databaseName = tableQName.getDatabaseName();
    final String tableName = tableQName.getTableName();
    final Table table;
    try {
        table = metacatHiveClient.getTableByName(databaseName, tableName);
    } catch (NoSuchObjectException exception) {
        throw new TableNotFoundException(tableQName, exception);
    } catch (TException e) {
        throw new ConnectorException(String.format("Failed getting hive table %s", tableQName), e);
    }
    // New partitions
    final List<PartitionInfo> addedPartitionInfos = Lists.newArrayList();
    final List<PartitionInfo> partitionInfos = partitionsSaveRequest.getPartitions();
    final List<String> partitionNames = partitionInfos.stream().map(part -> {
        final String partitionName = part.getName().getPartitionName();
        PartitionUtil.validatePartitionName(partitionName, getPartitionKeys(table.getPartitionKeys()));
        return partitionName;
    }).collect(Collectors.toList());
    // New partition names
    final List<String> addedPartitionNames = Lists.newArrayList();
    // Updated partition names
    final List<String> existingPartitionNames = Lists.newArrayList();
    // Existing partitions
    final List<PartitionHolder> existingPartitionHolders = Lists.newArrayList();
    // Existing partition map
    Map<String, PartitionHolder> existingPartitionMap = Collections.emptyMap();
    // 
    if (partitionsSaveRequest.getCheckIfExists() || partitionsSaveRequest.getAlterIfExists()) {
        existingPartitionMap = getPartitionsByNames(table, partitionNames);
    }
    for (PartitionInfo partitionInfo : partitionInfos) {
        final String partitionName = partitionInfo.getName().getPartitionName();
        final PartitionHolder existingPartitionHolder = existingPartitionMap.get(partitionName);
        if (existingPartitionHolder == null) {
            addedPartitionNames.add(partitionName);
            addedPartitionInfos.add(partitionInfo);
        } else {
            final String partitionUri = partitionInfo.getSerde() != null ? partitionInfo.getSerde().getUri() : null;
            final String existingPartitionUri = getPartitionUri(existingPartitionHolder);
            if (partitionUri == null || !partitionUri.equals(existingPartitionUri)) {
                existingPartitionNames.add(partitionName);
                // We need to copy the existing partition info and
                if (partitionInfo.getSerde() == null) {
                    partitionInfo.setSerde(new StorageInfo());
                }
                if (partitionInfo.getAudit() == null) {
                    partitionInfo.setAudit(new AuditInfo());
                }
                if (StringUtils.isBlank(partitionUri)) {
                    partitionInfo.getSerde().setUri(existingPartitionUri);
                }
                // unless we alterifExists
                if (partitionsSaveRequest.getAlterIfExists()) {
                    if (existingPartitionHolder.getPartition() != null) {
                        final Partition existingPartition = existingPartitionHolder.getPartition();
                        partitionInfo.getSerde().setParameters(existingPartition.getParameters());
                        partitionInfo.getAudit().setCreatedDate(HiveConnectorInfoConverter.epochSecondsToDate(existingPartition.getCreateTime()));
                        partitionInfo.getAudit().setLastModifiedDate(HiveConnectorInfoConverter.epochSecondsToDate(existingPartition.getLastAccessTime()));
                    } else {
                        final PartitionInfo existingPartitionInfo = existingPartitionHolder.getPartitionInfo();
                        if (existingPartitionInfo.getSerde() != null) {
                            partitionInfo.getSerde().setParameters(existingPartitionInfo.getSerde().getParameters());
                        }
                        if (existingPartitionInfo.getAudit() != null) {
                            partitionInfo.getAudit().setCreatedDate(existingPartitionInfo.getAudit().getCreatedDate());
                            partitionInfo.getAudit().setLastModifiedDate(existingPartitionInfo.getAudit().getLastModifiedDate());
                        }
                    }
                    existingPartitionHolder.setPartitionInfo(partitionInfo);
                    existingPartitionHolders.add(existingPartitionHolder);
                } else {
                    addedPartitionInfos.add(partitionInfo);
                }
            }
        }
    }
    final Set<String> deletePartitionNames = Sets.newHashSet();
    if (!partitionsSaveRequest.getAlterIfExists()) {
        deletePartitionNames.addAll(existingPartitionNames);
    }
    if (partitionsSaveRequest.getPartitionIdsForDeletes() != null) {
        deletePartitionNames.addAll(partitionsSaveRequest.getPartitionIdsForDeletes());
    }
    addUpdateDropPartitions(tableQName, table, partitionNames, addedPartitionInfos, existingPartitionHolders, deletePartitionNames);
    final PartitionsSaveResponse result = new PartitionsSaveResponse();
    result.setAdded(addedPartitionNames);
    result.setUpdated(existingPartitionNames);
    return result;
}
Also used : TException(org.apache.thrift.TException) StringUtils(org.apache.commons.lang.StringUtils) Getter(lombok.Getter) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) SortOrder(com.netflix.metacat.common.dto.SortOrder) AuditInfo(com.netflix.metacat.common.server.connectors.model.AuditInfo) HashMap(java.util.HashMap) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) Partition(org.apache.hadoop.hive.metastore.api.Partition) Function(java.util.function.Function) Warehouse(org.apache.hadoop.hive.metastore.Warehouse) ArrayList(java.util.ArrayList) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) Strings(com.google.common.base.Strings) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) Lists(com.google.common.collect.Lists) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) Map(java.util.Map) 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) PartitionUtil(com.netflix.metacat.common.server.partition.util.PartitionUtil) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) Nullable(javax.annotation.Nullable) PartitionHolder(com.netflix.metacat.connector.hive.sql.PartitionHolder) Pageable(com.netflix.metacat.common.dto.Pageable) TException(org.apache.thrift.TException) Set(java.util.Set) QualifiedName(com.netflix.metacat.common.QualifiedName) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Table(org.apache.hadoop.hive.metastore.api.Table) PartitionsSaveResponse(com.netflix.metacat.common.server.connectors.model.PartitionsSaveResponse) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) List(java.util.List) PartitionAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) PartitionsSaveRequest(com.netflix.metacat.common.server.connectors.model.PartitionsSaveRequest) PartitionListRequest(com.netflix.metacat.common.server.connectors.model.PartitionListRequest) ConnectorUtils(com.netflix.metacat.common.server.connectors.ConnectorUtils) PartitionNotFoundException(com.netflix.metacat.common.server.connectors.exception.PartitionNotFoundException) Collections(java.util.Collections) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Sort(com.netflix.metacat.common.dto.Sort) Partition(org.apache.hadoop.hive.metastore.api.Partition) PartitionHolder(com.netflix.metacat.connector.hive.sql.PartitionHolder) AuditInfo(com.netflix.metacat.common.server.connectors.model.AuditInfo) Table(org.apache.hadoop.hive.metastore.api.Table) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) StorageInfo(com.netflix.metacat.common.server.connectors.model.StorageInfo) PartitionsSaveResponse(com.netflix.metacat.common.server.connectors.model.PartitionsSaveResponse) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo)

Example 32 with ConnectorRequestContext

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

the class DirectSqlGetPartition method getPartitionCount.

/**
 * Number of partitions for the given table.
 *
 * @param requestContext request context
 * @param tableName      tableName
 * @return Number of partitions
 */
@Transactional(readOnly = true)
public int getPartitionCount(final ConnectorRequestContext requestContext, final QualifiedName tableName) {
    final long start = registry.clock().wallTime();
    // Handler for reading the result set
    final ResultSetExtractor<Integer> handler = rs -> {
        int count = 0;
        while (rs.next()) {
            count = rs.getInt("count");
        }
        return count;
    };
    try {
        final Optional<QualifiedName> sourceTable = getSourceTableName(tableName.getDatabaseName(), tableName.getTableName(), false);
        return sourceTable.map(qualifiedName -> jdbcTemplate.query(SQL.SQL_GET_AUDIT_TABLE_PARTITION_COUNT, new String[] { tableName.getDatabaseName(), tableName.getTableName(), qualifiedName.getDatabaseName(), qualifiedName.getTableName() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }, handler)).orElseGet(() -> jdbcTemplate.query(SQL.SQL_GET_PARTITION_COUNT, new String[] { tableName.getDatabaseName(), tableName.getTableName() }, new int[] { Types.VARCHAR, Types.VARCHAR }, handler));
    } catch (Exception e) {
        throw new ConnectorException("Failed getting the partition count", e);
    } finally {
        this.fastServiceMetric.recordTimer(HiveMetrics.TagGetPartitionCount.getMetricName(), registry.clock().wallTime() - start);
    }
}
Also used : HiveConfigConstants(com.netflix.metacat.connector.hive.util.HiveConfigConstants) HiveConnectorFastServiceMetric(com.netflix.metacat.connector.hive.util.HiveConnectorFastServiceMetric) PartitionKeyParserEval(com.netflix.metacat.common.server.partition.visitor.PartitionKeyParserEval) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException) PartitionFilterGenerator(com.netflix.metacat.connector.hive.util.PartitionFilterGenerator) PartitionParamParserEval(com.netflix.metacat.common.server.partition.visitor.PartitionParamParserEval) Matcher(java.util.regex.Matcher) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) Map(java.util.Map) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) StorageInfo(com.netflix.metacat.common.server.connectors.model.StorageInfo) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) Collection(java.util.Collection) Pageable(com.netflix.metacat.common.dto.Pageable) QualifiedName(com.netflix.metacat.common.QualifiedName) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) HiveMetrics(com.netflix.metacat.connector.hive.monitoring.HiveMetrics) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner) Sort(com.netflix.metacat.common.dto.Sort) Types(java.sql.Types) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AuditInfo(com.netflix.metacat.common.server.connectors.model.AuditInfo) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) ThreadServiceManager(com.netflix.metacat.common.server.util.ThreadServiceManager) ImmutableList(com.google.common.collect.ImmutableList) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PartitionParser(com.netflix.metacat.common.server.partition.parser.PartitionParser) Config(com.netflix.metacat.common.server.properties.Config) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Throwables(com.google.common.base.Throwables) Maps(com.google.common.collect.Maps) Table(org.apache.hadoop.hive.metastore.api.Table) SqlParameterValue(org.springframework.jdbc.core.SqlParameterValue) FilterPartition(com.netflix.metacat.common.server.partition.util.FilterPartition) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) Futures(com.google.common.util.concurrent.Futures) StringReader(java.io.StringReader) Registry(com.netflix.spectator.api.Registry) PartitionListRequest(com.netflix.metacat.common.server.connectors.model.PartitionListRequest) HiveFilterPartition(com.netflix.metacat.connector.hive.util.HiveFilterPartition) VisibleForTesting(com.google.common.annotations.VisibleForTesting) HivePartitionKeyParserEval(com.netflix.metacat.connector.hive.util.HivePartitionKeyParserEval) ResultSetExtractor(org.springframework.jdbc.core.ResultSetExtractor) Transactional(org.springframework.transaction.annotation.Transactional) QualifiedName(com.netflix.metacat.common.QualifiedName) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) TimeoutException(java.util.concurrent.TimeoutException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) ExecutionException(java.util.concurrent.ExecutionException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with ConnectorRequestContext

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

the class DirectSqlGetPartition method getPartitionNames.

/**
 * getPartitionNames.
 *
 * @param context      request context
 * @param uris         uris
 * @param prefixSearch prefixSearch
 * @return partition names
 */
@Transactional(readOnly = true)
public Map<String, List<QualifiedName>> getPartitionNames(@Nonnull final ConnectorRequestContext context, @Nonnull final List<String> uris, final boolean prefixSearch) {
    final long start = registry.clock().wallTime();
    final Map<String, List<QualifiedName>> result = Maps.newHashMap();
    // Create the sql
    final StringBuilder queryBuilder = new StringBuilder(SQL.SQL_GET_PARTITION_NAMES_BY_URI);
    final List<SqlParameterValue> params = Lists.newArrayList();
    if (prefixSearch) {
        queryBuilder.append(" 1=2");
        uris.forEach(uri -> {
            queryBuilder.append(" or location like ?");
            params.add(new SqlParameterValue(Types.VARCHAR, uri + "%"));
        });
    } else {
        queryBuilder.append(" location in (");
        Joiner.on(',').appendTo(queryBuilder, uris.stream().map(uri -> "?").collect(Collectors.toList()));
        queryBuilder.append(")");
        params.addAll(uris.stream().map(uri -> new SqlParameterValue(Types.VARCHAR, uri)).collect(Collectors.toList()));
    }
    final ResultSetExtractor<Map<String, List<QualifiedName>>> handler = rs -> {
        while (rs.next()) {
            final String schemaName = rs.getString("schema_name");
            final String tableName = rs.getString("table_name");
            final String partitionName = rs.getString("partition_name");
            final String uri = rs.getString("location");
            final List<QualifiedName> partitionNames = result.get(uri);
            final QualifiedName qualifiedName = QualifiedName.ofPartition(catalogName, schemaName, tableName, partitionName);
            if (partitionNames == null) {
                result.put(uri, Lists.newArrayList(qualifiedName));
            } else {
                partitionNames.add(qualifiedName);
            }
        }
        return result;
    };
    try {
        jdbcTemplate.query(queryBuilder.toString(), params.toArray(), handler);
    } finally {
        this.fastServiceMetric.recordTimer(HiveMetrics.TagGetPartitionNames.getMetricName(), registry.clock().wallTime() - start);
    }
    return result;
}
Also used : HiveConfigConstants(com.netflix.metacat.connector.hive.util.HiveConfigConstants) HiveConnectorFastServiceMetric(com.netflix.metacat.connector.hive.util.HiveConnectorFastServiceMetric) PartitionKeyParserEval(com.netflix.metacat.common.server.partition.visitor.PartitionKeyParserEval) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException) PartitionFilterGenerator(com.netflix.metacat.connector.hive.util.PartitionFilterGenerator) PartitionParamParserEval(com.netflix.metacat.common.server.partition.visitor.PartitionParamParserEval) Matcher(java.util.regex.Matcher) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) Map(java.util.Map) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) StorageInfo(com.netflix.metacat.common.server.connectors.model.StorageInfo) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) Collection(java.util.Collection) Pageable(com.netflix.metacat.common.dto.Pageable) QualifiedName(com.netflix.metacat.common.QualifiedName) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) HiveMetrics(com.netflix.metacat.connector.hive.monitoring.HiveMetrics) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner) Sort(com.netflix.metacat.common.dto.Sort) Types(java.sql.Types) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AuditInfo(com.netflix.metacat.common.server.connectors.model.AuditInfo) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) ThreadServiceManager(com.netflix.metacat.common.server.util.ThreadServiceManager) ImmutableList(com.google.common.collect.ImmutableList) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PartitionParser(com.netflix.metacat.common.server.partition.parser.PartitionParser) Config(com.netflix.metacat.common.server.properties.Config) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Throwables(com.google.common.base.Throwables) Maps(com.google.common.collect.Maps) Table(org.apache.hadoop.hive.metastore.api.Table) SqlParameterValue(org.springframework.jdbc.core.SqlParameterValue) FilterPartition(com.netflix.metacat.common.server.partition.util.FilterPartition) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) Futures(com.google.common.util.concurrent.Futures) StringReader(java.io.StringReader) Registry(com.netflix.spectator.api.Registry) PartitionListRequest(com.netflix.metacat.common.server.connectors.model.PartitionListRequest) HiveFilterPartition(com.netflix.metacat.connector.hive.util.HiveFilterPartition) VisibleForTesting(com.google.common.annotations.VisibleForTesting) HivePartitionKeyParserEval(com.netflix.metacat.connector.hive.util.HivePartitionKeyParserEval) ResultSetExtractor(org.springframework.jdbc.core.ResultSetExtractor) Transactional(org.springframework.transaction.annotation.Transactional) SqlParameterValue(org.springframework.jdbc.core.SqlParameterValue) QualifiedName(com.netflix.metacat.common.QualifiedName) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with ConnectorRequestContext

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

the class HiveConnectorDatabaseService method list.

/**
 * {@inheritDoc}.
 */
@Override
public List<DatabaseInfo> list(final ConnectorRequestContext requestContext, final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    try {
        final List<DatabaseInfo> databaseInfos = Lists.newArrayList();
        for (String databaseName : metacatHiveClient.getAllDatabases()) {
            final QualifiedName qualifiedName = QualifiedName.ofDatabase(name.getCatalogName(), databaseName);
            if (prefix != null && !qualifiedName.toString().startsWith(prefix.toString())) {
                continue;
            }
            databaseInfos.add(DatabaseInfo.builder().name(qualifiedName).build());
        }
        // supporting sort by name only
        if (sort != null) {
            ConnectorUtils.sort(databaseInfos, sort, Comparator.comparing(p -> p.getName().getDatabaseName()));
        }
        return ConnectorUtils.paginate(databaseInfos, pageable);
    } catch (MetaException exception) {
        throw new InvalidMetaException(name, exception);
    } catch (TException exception) {
        throw new ConnectorException(String.format("Failed list hive database %s", name), exception);
    }
}
Also used : ConnectorDatabaseService(com.netflix.metacat.common.server.connectors.ConnectorDatabaseService) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) 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) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) List(java.util.List) Lists(com.google.common.collect.Lists) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) MetacatNotSupportedException(com.netflix.metacat.common.exception.MetacatNotSupportedException) ConnectorUtils(com.netflix.metacat.common.server.connectors.ConnectorUtils) HiveConnectorInfoConverter(com.netflix.metacat.connector.hive.converters.HiveConnectorInfoConverter) Comparator(java.util.Comparator) Database(org.apache.hadoop.hive.metastore.api.Database) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Nullable(javax.annotation.Nullable) Sort(com.netflix.metacat.common.dto.Sort) TException(org.apache.thrift.TException) DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) QualifiedName(com.netflix.metacat.common.QualifiedName) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)

Example 35 with ConnectorRequestContext

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

the class PolarisConnectorTableService 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 String tableFilter = (prefix != null && prefix.isTableDefinition()) ? prefix.getTableName() : "";
        final List<PolarisTableEntity> tbls = polarisStoreService.getTableEntities(name.getDatabaseName(), tableFilter);
        if (sort != null) {
            ConnectorUtils.sort(tbls, sort, Comparator.comparing(t -> t.getTblName()));
        }
        return ConnectorUtils.paginate(tbls, pageable).stream().map(t -> polarisTableMapper.toInfo(t)).collect(Collectors.toList());
    } catch (Exception exception) {
        final String msg = String.format("Failed polaris list tables %s using prefix %s", name, prefix);
        log.error(msg, exception);
        throw new ConnectorException(msg, exception);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Cacheable(org.springframework.cache.annotation.Cacheable) PolarisTableEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity) TablePreconditionFailedException(com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException) DirectSqlTable(com.netflix.metacat.connector.hive.sql.DirectSqlTable) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) Lists(com.google.common.collect.Lists) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Map(java.util.Map) IcebergTableWrapper(com.netflix.metacat.connector.hive.iceberg.IcebergTableWrapper) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) HiveConnectorInfoConverter(com.netflix.metacat.connector.hive.converters.HiveConnectorInfoConverter) Config(com.netflix.metacat.common.server.properties.Config) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) Nullable(javax.annotation.Nullable) PolarisTableMapper(com.netflix.metacat.connector.polaris.mappers.PolarisTableMapper) MapUtils(org.apache.commons.collections.MapUtils) Pageable(com.netflix.metacat.common.dto.Pageable) QualifiedName(com.netflix.metacat.common.QualifiedName) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) IcebergTableHandler(com.netflix.metacat.connector.hive.iceberg.IcebergTableHandler) 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) ConnectorUtils(com.netflix.metacat.common.server.connectors.ConnectorUtils) Comparator(java.util.Comparator) PolarisStoreService(com.netflix.metacat.connector.polaris.store.PolarisStoreService) Sort(com.netflix.metacat.common.dto.Sort) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) PolarisTableEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity) TablePreconditionFailedException(com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException)

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