Search in sources :

Example 31 with Table

use of com.netflix.metacat.connector.s3.model.Table in project metacat by Netflix.

the class S3ConnectorTableService method rename.

@Override
public void rename(@Nonnull final ConnectorRequestContext 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 32 with Table

use of com.netflix.metacat.connector.s3.model.Table in project metacat by Netflix.

the class S3ConnectorTableService method create.

@Override
public void create(@Nonnull final ConnectorRequestContext context, @Nonnull final TableInfo tableInfo) {
    log.debug("Start: Create table {}", tableInfo.getName());
    Preconditions.checkArgument(tableInfo.getSerde() == null || !Strings.isNullOrEmpty(tableInfo.getSerde().getOwner()), "Table owner is null or empty");
    final QualifiedName tableName = tableInfo.getName();
    if (tableDao.getBySourceDatabaseTableName(catalogName, tableName.getDatabaseName(), tableName.getTableName()) != null) {
        throw new TableAlreadyExistsException(tableName);
    }
    final Database database = databaseDao.getBySourceDatabaseName(catalogName, tableName.getDatabaseName());
    if (database == null) {
        throw new DatabaseNotFoundException(QualifiedName.ofDatabase(catalogName, tableName.getDatabaseName()));
    }
    tableDao.save(infoConverter.fromTableInfo(database, tableInfo));
    log.debug("End: Create table {}", tableInfo.getName());
}
Also used : TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) Database(com.netflix.metacat.connector.s3.model.Database)

Aggregations

Table (com.netflix.metacat.connector.s3.model.Table)22 QualifiedName (com.netflix.metacat.common.QualifiedName)13 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)11 Partition (com.netflix.metacat.connector.s3.model.Partition)10 FilterPartition (com.netflix.metacat.common.server.partition.util.FilterPartition)9 Location (com.netflix.metacat.connector.s3.model.Location)8 PartitionNotFoundException (com.netflix.metacat.common.server.connectors.exception.PartitionNotFoundException)7 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)6 PartitionAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException)5 FieldInfo (com.netflix.metacat.common.server.connectors.model.FieldInfo)5 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)5 Info (com.netflix.metacat.connector.s3.model.Info)5 TableAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException)4 Field (com.netflix.metacat.connector.s3.model.Field)4 Schema (com.netflix.metacat.connector.s3.model.Schema)4 Strings (com.google.common.base.Strings)3 Lists (com.google.common.collect.Lists)3 Maps (com.google.common.collect.Maps)3 Transactional (com.google.inject.persist.Transactional)3 Pageable (com.netflix.metacat.common.dto.Pageable)3