Search in sources :

Example 1 with Table

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

the class S3ConnectorPartitionService method update.

@Override
public void update(@Nonnull final ConnectorContext context, @Nonnull final PartitionInfo partitionInfo) {
    final QualifiedName name = partitionInfo.getName();
    log.debug("Start: Update partition {}", name);
    final QualifiedName tableName = QualifiedName.ofTable(catalogName, name.getDatabaseName(), name.getTableName());
    // Table
    final Table table = getTable(tableName);
    final List<Partition> partitions = partitionDao.getPartitions(table.getId(), Lists.newArrayList(name.getPartitionName()), null, null, null, null);
    if (partitions.isEmpty()) {
        throw new PartitionNotFoundException(tableName, name.getPartitionName());
    }
    partitionDao.save(infoConverter.fromPartitionInfo(partitionInfo));
    log.debug("End: Update partition {}", name);
}
Also used : Partition(com.netflix.metacat.connector.s3.model.Partition) FilterPartition(com.netflix.metacat.common.server.partition.util.FilterPartition) PartitionNotFoundException(com.netflix.metacat.common.server.connectors.exception.PartitionNotFoundException) Table(com.netflix.metacat.connector.s3.model.Table) QualifiedName(com.netflix.metacat.common.QualifiedName)

Example 2 with Table

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

the class S3ConnectorPartitionService method exists.

@Override
public boolean exists(@Nonnull final ConnectorContext context, @Nonnull final QualifiedName name) {
    boolean result = false;
    final Table table = tableDao.getBySourceDatabaseTableName(catalogName, name.getDatabaseName(), name.getTableName());
    if (table != null) {
        result = !partitionDao.getPartitions(table.getId(), Lists.newArrayList(name.getPartitionName()), null, null, null, null).isEmpty();
    }
    return result;
}
Also used : Table(com.netflix.metacat.connector.s3.model.Table)

Example 3 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 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 Table

use of com.netflix.metacat.connector.s3.model.Table 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 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 ConnectorContext 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 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)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 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