Search in sources :

Example 6 with TableNotFoundException

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

the class HiveConnectorPartitionService method getPartitions.

/**
 * {@inheritDoc}.
 */
@Override
public List<PartitionInfo> getPartitions(final ConnectorRequestContext requestContext, final QualifiedName tableName, final PartitionListRequest partitionsRequest) {
    try {
        final List<Partition> partitions = getPartitions(tableName, partitionsRequest.getFilter(), partitionsRequest.getPartitionNames(), partitionsRequest.getSort(), partitionsRequest.getPageable());
        final Table table = metacatHiveClient.getTableByName(tableName.getDatabaseName(), tableName.getTableName());
        final TableInfo tableInfo = hiveMetacatConverters.toTableInfo(tableName, table);
        final List<PartitionInfo> partitionInfos = new ArrayList<>();
        for (Partition partition : partitions) {
            partitionInfos.add(hiveMetacatConverters.toPartitionInfo(tableInfo, partition));
        }
        return partitionInfos;
    } catch (NoSuchObjectException exception) {
        throw new TableNotFoundException(tableName, exception);
    } catch (MetaException | InvalidObjectException e) {
        throw new InvalidMetaException("Invalid metadata for " + tableName, e);
    } catch (TException e) {
        throw new ConnectorException(String.format("Failed get partitions for hive table %s", tableName), e);
    }
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) ArrayList(java.util.ArrayList) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)

Example 7 with TableNotFoundException

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

the class HiveConnectorPartitionService method getPartitionKeys.

/**
 * {@inheritDoc}.
 */
@Override
public List<String> getPartitionKeys(final ConnectorRequestContext requestContext, final QualifiedName tableName, final PartitionListRequest partitionsRequest, final TableInfo tableInfo) {
    final String filterExpression = partitionsRequest.getFilter();
    final List<String> partitionIds = partitionsRequest.getPartitionNames();
    List<String> names = Lists.newArrayList();
    final Pageable pageable = partitionsRequest.getPageable();
    try {
        if (filterExpression != null || (partitionIds != null && !partitionIds.isEmpty())) {
            final Table table = metacatHiveClient.getTableByName(tableName.getDatabaseName(), tableName.getTableName());
            for (Partition partition : getPartitions(tableName, filterExpression, partitionIds, partitionsRequest.getSort(), pageable)) {
                names.add(getNameOfPartition(table, partition));
            }
        } else {
            names = metacatHiveClient.getPartitionNames(tableName.getDatabaseName(), tableName.getTableName());
            return ConnectorUtils.paginate(names, pageable);
        }
    } catch (NoSuchObjectException exception) {
        throw new TableNotFoundException(tableName, exception);
    } catch (MetaException | InvalidObjectException e) {
        throw new InvalidMetaException("Invalid metadata for " + tableName, e);
    } catch (TException e) {
        throw new ConnectorException(String.format("Failed get partitions keys for hive table %s", tableName), e);
    }
    return names;
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Pageable(com.netflix.metacat.common.dto.Pageable) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)

Example 8 with TableNotFoundException

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

the class HiveConnectorTableService method rename.

/**
 * {@inheritDoc}.
 */
@Override
public void rename(final ConnectorRequestContext context, final QualifiedName oldName, final QualifiedName newName) {
    if (!allowRenameTable) {
        throw new ConnectorException("Renaming tables is disabled in catalog " + catalogName, null);
    }
    try {
        if (onRenameConvertToExternal) {
            // 
            // If this is a managed table(EXTERNAL=FALSE), then convert it to an external table before renaming it.
            // We do not want the metastore to move the location/data.
            // 
            final Table table = metacatHiveClient.getTableByName(oldName.getDatabaseName(), oldName.getTableName());
            Map<String, String> parameters = table.getParameters();
            if (parameters == null) {
                parameters = Maps.newHashMap();
                table.setParameters(parameters);
            }
            if (!parameters.containsKey(PARAMETER_EXTERNAL) || parameters.get(PARAMETER_EXTERNAL).equalsIgnoreCase("FALSE")) {
                parameters.put(PARAMETER_EXTERNAL, "TRUE");
                metacatHiveClient.alterTable(oldName.getDatabaseName(), oldName.getTableName(), table);
            }
        }
        metacatHiveClient.rename(oldName.getDatabaseName(), oldName.getTableName(), newName.getDatabaseName(), newName.getTableName());
    } catch (NoSuchObjectException exception) {
        throw new TableNotFoundException(oldName, exception);
    } catch (MetaException exception) {
        throw new InvalidMetaException(newName, exception);
    } catch (TException exception) {
        throw new ConnectorException("Failed renaming from hive table" + oldName.toString() + " to hive talbe " + newName.toString(), exception);
    }
}
Also used : TException(org.apache.thrift.TException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Table(org.apache.hadoop.hive.metastore.api.Table) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) 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 9 with TableNotFoundException

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

the class DruidConnectorTableService method get.

/**
 * {@inheritDoc}
 */
@Override
public TableInfo get(@Nonnull final ConnectorRequestContext context, @Nonnull final QualifiedName name) {
    log.debug("Get table metadata for qualified name {} for request {}", name, context);
    try {
        final ObjectNode node = this.druidClient.getLatestDataByName(name.getTableName());
        final DataSource dataSource = DruidConverterUtil.getDatasourceFromLatestSegmentJsonObject(node);
        return this.druidConnectorInfoConverter.getTableInfoFromDatasource(dataSource);
    } catch (MetacatException e) {
        log.error(String.format("Table %s not found.", name), e);
        throw new TableNotFoundException(name);
    } catch (HttpClientErrorException e) {
        log.error(String.format("Failed getting table %s.", name), e);
        if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
            throw new TableNotFoundException(name);
        } else {
            throw new InvalidMetadataException(String.format("Invalid table %s. %s", name, e.getMessage()));
        }
    }
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MetacatException(com.netflix.metacat.common.exception.MetacatException) InvalidMetadataException(com.netflix.metacat.common.server.connectors.exception.InvalidMetadataException) DataSource(com.netflix.metacat.connector.druid.converter.DataSource)

Example 10 with TableNotFoundException

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

the class CassandraConnectorTableService method get.

/**
 * {@inheritDoc}
 */
@Override
public TableInfo get(@Nonnull @NonNull final ConnectorRequestContext context, @Nonnull @NonNull final QualifiedName name) {
    final String keyspace = name.getDatabaseName();
    final String table = name.getTableName();
    log.debug("Attempting to get metadata for Cassandra table {}.{} for request {}", keyspace, table, context);
    try {
        final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace);
        if (keyspaceMetadata == null) {
            throw new DatabaseNotFoundException(name);
        }
        final TableMetadata tableMetadata = keyspaceMetadata.getTable(table);
        if (tableMetadata == null) {
            throw new TableNotFoundException(name);
        }
        final TableInfo tableInfo = this.getTableInfo(name, tableMetadata);
        log.debug("Successfully got metadata for Cassandra table {}.{} for request {}", keyspace, table, context);
        return tableInfo;
    } catch (final DriverException de) {
        log.error(de.getMessage(), de);
        throw this.getExceptionMapper().toConnectorException(de, name);
    }
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) DriverException(com.datastax.driver.core.exceptions.DriverException) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Aggregations

TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)40 QualifiedName (com.netflix.metacat.common.QualifiedName)17 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)16 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)15 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)12 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)12 TException (org.apache.thrift.TException)12 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)11 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)11 Table (org.apache.hadoop.hive.metastore.api.Table)11 TableDto (com.netflix.metacat.common.dto.TableDto)10 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)9 Partition (org.apache.hadoop.hive.metastore.api.Partition)9 Table (com.netflix.metacat.connector.s3.model.Table)8 MetacatUpdateTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent)7 Pageable (com.netflix.metacat.common.dto.Pageable)6 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)6 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)5 ArrayList (java.util.ArrayList)4 Strings (com.google.common.base.Strings)3