Search in sources :

Example 11 with TableNotFoundException

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

the class S3ConnectorTableService method update.

@Override
public void update(@Nonnull final ConnectorRequestContext context, @Nonnull final TableInfo tableInfo) {
    log.debug("Start: Update table {}", tableInfo.getName());
    final QualifiedName tableName = tableInfo.getName();
    final Table table = tableDao.getBySourceDatabaseTableName(catalogName, tableName.getDatabaseName(), tableName.getTableName());
    if (table == null) {
        throw new TableNotFoundException(tableName);
    }
    // we can update the fields, the uri, or the full serde
    final Location newLocation = infoConverter.toLocation(tableInfo);
    Location location = table.getLocation();
    if (location == null) {
        location = new Location();
        location.setTable(table);
        table.setLocation(location);
    }
    if (newLocation.getUri() != null) {
        location.setUri(newLocation.getUri());
    }
    final Info newInfo = newLocation.getInfo();
    if (newInfo != null) {
        final Info info = location.getInfo();
        if (info == null) {
            location.setInfo(newInfo);
            newInfo.setLocation(location);
        } else {
            if (newInfo.getInputFormat() != null) {
                info.setInputFormat(newInfo.getInputFormat());
            }
            if (newInfo.getOutputFormat() != null) {
                info.setOutputFormat(newInfo.getOutputFormat());
            }
            if (newInfo.getOwner() != null) {
                info.setOwner(newInfo.getOwner());
            }
            if (newInfo.getSerializationLib() != null) {
                info.setSerializationLib(newInfo.getSerializationLib());
            }
            if (newInfo.getParameters() != null && !newInfo.getParameters().isEmpty()) {
                info.setParameters(newInfo.getParameters());
            }
        }
    }
    final Schema newSchema = newLocation.getSchema();
    if (newSchema != null) {
        final List<Field> newFields = newSchema.getFields();
        if (newFields != null && !newFields.isEmpty()) {
            final Schema schema = location.getSchema();
            if (schema == null) {
                location.setSchema(newSchema);
                newSchema.setLocation(location);
            } else {
                final List<Field> fields = schema.getFields();
                if (fields.isEmpty()) {
                    newFields.forEach(field -> {
                        field.setSchema(schema);
                        fields.add(field);
                    });
                } else {
                    for (int i = 0; i < newFields.size(); i++) {
                        final Field newField = newFields.get(i);
                        newField.setPos(i);
                        newField.setSchema(schema);
                        if (newField.getType() == null) {
                            newField.setType(newField.getSourceType());
                        }
                    }
                    schema.setFields(null);
                    fieldDao.delete(fields);
                    tableDao.save(table, true);
                    schema.setFields(newFields);
                }
            }
        }
    }
    log.debug("End: Update table {}", tableInfo.getName());
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Field(com.netflix.metacat.connector.s3.model.Field) Table(com.netflix.metacat.connector.s3.model.Table) QualifiedName(com.netflix.metacat.common.QualifiedName) Schema(com.netflix.metacat.connector.s3.model.Schema) Info(com.netflix.metacat.connector.s3.model.Info) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) Location(com.netflix.metacat.connector.s3.model.Location)

Example 12 with TableNotFoundException

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

the class S3ConnectorTableService method delete.

@Override
public void delete(@Nonnull final ConnectorRequestContext context, @Nonnull final QualifiedName name) {
    log.debug("Start: Delete table {}", name);
    final Table table = tableDao.getBySourceDatabaseTableName(catalogName, name.getDatabaseName(), name.getTableName());
    if (table == null) {
        throw new TableNotFoundException(name);
    }
    tableDao.delete(table);
    log.debug("End: Delete table {}", name);
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Table(com.netflix.metacat.connector.s3.model.Table)

Example 13 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 ConnectorRequestContext 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 14 with TableNotFoundException

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

the class PolarisConnectorTableService method get.

/**
 * {@inheritDoc}.
 */
@Override
public TableInfo get(final ConnectorRequestContext requestContext, final QualifiedName name) {
    try {
        final PolarisTableEntity polarisTableEntity = polarisStoreService.getTable(name.getDatabaseName(), name.getTableName()).orElseThrow(() -> new TableNotFoundException(name));
        final TableInfo info = polarisTableMapper.toInfo(polarisTableEntity);
        final String tableLoc = HiveTableUtil.getIcebergTableMetadataLocation(info);
        return getIcebergTable(name, tableLoc, info, requestContext.isIncludeMetadata(), connectorContext.getConfig().isIcebergCacheEnabled());
    } catch (TableNotFoundException | IllegalArgumentException exception) {
        log.error(String.format("Not found exception for polaris table %s", name), exception);
        throw exception;
    } catch (ConnectorException connectorException) {
        log.error("Encountered connector exception for polaris table {}. {}", name, connectorException);
        throw connectorException;
    } catch (Exception exception) {
        final String msg = String.format("Failed getting polaris table %s", name);
        log.error(msg, exception);
        throw exception;
    }
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) PolarisTableEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) 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)

Example 15 with TableNotFoundException

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

the class PolarisConnectorTableService method rename.

/**
 * {@inheritDoc}.
 */
@Override
public void rename(final ConnectorRequestContext context, final QualifiedName oldName, final QualifiedName newName) {
    // check exists then rename in non-transactional optimistic manner
    if (exists(context, newName)) {
        throw new TableAlreadyExistsException(newName);
    }
    try {
        final PolarisTableEntity table = polarisStoreService.getTable(oldName.getDatabaseName(), oldName.getTableName()).orElseThrow(() -> new TableNotFoundException(oldName));
        polarisStoreService.saveTable(table.toBuilder().tblName(newName.getTableName()).build());
    } catch (TableNotFoundException exception) {
        log.error(String.format("Not found exception for polaris table %s", oldName), exception);
        throw exception;
    } catch (DataIntegrityViolationException exception) {
        throw new InvalidMetaException(oldName, exception);
    } catch (Exception exception) {
        final String msg = String.format("Failed renaming polaris table %s", oldName);
        log.error(msg, exception);
        throw new ConnectorException(msg, exception);
    }
}
Also used : TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) PolarisTableEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) 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) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

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