Search in sources :

Example 1 with TableNotFoundException

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

the class TagV1Resource method removeTableTags.

/**
     * {@inheritDoc}
     */
@Override
public void removeTableTags(final String catalogName, final String databaseName, final String tableName, final Boolean deleteAll, final Set<String> tags) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
    requestWrapper.processRequest(name, "TagV1Resource.removeTableTags", () -> {
        if (!tableService.exists(name)) {
            // Delete tags if exists
            tagService.delete(name, false);
            throw new TableNotFoundException(name);
        }
        final TableDto oldTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        tagService.removeTableTags(name, deleteAll, tags, true);
        final TableDto currentTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
        return null;
    });
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 2 with TableNotFoundException

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

the class TagV1Resource method setTableTags.

/**
     * {@inheritDoc}
     */
@Override
public Set<String> setTableTags(final String catalogName, final String databaseName, final String tableName, final Set<String> tags) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
    return requestWrapper.processRequest(name, "TagV1Resource.setTableTags", () -> {
        if (!tableService.exists(name)) {
            throw new TableNotFoundException(name);
        }
        final TableDto oldTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        final Set<String> result = tagService.setTableTags(name, tags, true);
        final TableDto currentTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
        return result;
    });
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 3 with TableNotFoundException

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

the class S3ConnectorTableService method rename.

@Override
public void rename(@Nonnull final ConnectorContext context, @Nonnull final QualifiedName oldName, @Nonnull final QualifiedName newName) {
    log.debug("Start: Rename table {} with {}", oldName, newName);
    final Table oldTable = tableDao.getBySourceDatabaseTableName(catalogName, oldName.getDatabaseName(), oldName.getTableName());
    if (oldTable == null) {
        throw new TableNotFoundException(oldName);
    }
    final Table newTable = tableDao.getBySourceDatabaseTableName(catalogName, newName.getDatabaseName(), newName.getTableName());
    if (newTable == null) {
        oldTable.setName(newName.getTableName());
        tableDao.save(oldTable);
    } else {
        throw new TableAlreadyExistsException(newName);
    }
    log.debug("End: Rename table {} with {}", oldName, newName);
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) Table(com.netflix.metacat.connector.s3.model.Table)

Example 4 with TableNotFoundException

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

the class S3ConnectorTableService method get.

@Override
public TableInfo get(@Nonnull final ConnectorContext context, @Nonnull final QualifiedName name) {
    final Table table = tableDao.getBySourceDatabaseTableName(catalogName, name.getDatabaseName(), name.getTableName());
    if (table == null) {
        throw new TableNotFoundException(name);
    }
    log.debug("Get table {}", name);
    return infoConverter.toTableInfo(name, table);
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Table(com.netflix.metacat.connector.s3.model.Table)

Example 5 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 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)

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