Search in sources :

Example 1 with PolarisTableEntity

use of com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity in project metacat by Netflix.

the class PolarisStoreConnectorTest method updateMetadataLocation.

/**
 * Test to verify that compare-and-swap update of the metadata location works as expected.
 */
@Test
public void updateMetadataLocation() {
    final String dbName = generateDatabaseName();
    createDB(dbName);
    final String tblName = generateTableName();
    final String metadataLocation = "s3/s3n://dataoven-prod/hive/dataoven_prod/warehouse/foo";
    final PolarisTableEntity e = new PolarisTableEntity(dbName, tblName);
    e.setMetadataLocation(metadataLocation);
    final PolarisTableEntity savedEntity = polarisConnector.saveTable(e);
    final String newLocation = "s3/s3n://dataoven-prod/hive/dataoven_prod/warehouse/bar";
    // update should fail since the expected location is not going to match.
    boolean updatedSuccess = polarisConnector.updateTableMetadataLocation(dbName, tblName, "unexpected_location", newLocation);
    Assert.assertFalse(updatedSuccess);
    // successful update should happen.
    updatedSuccess = polarisConnector.updateTableMetadataLocation(dbName, tblName, metadataLocation, newLocation);
    Assert.assertTrue(updatedSuccess);
    final PolarisTableEntity updatedEntity = polarisConnector.getTable(dbName, tblName).orElseThrow(() -> new RuntimeException("Expected to find saved entity"));
    Assert.assertEquals(updatedEntity.getPreviousMetadataLocation(), metadataLocation);
    // after the successful update, the same call should fail, since the current metadataLocation has changed.
    updatedSuccess = polarisConnector.updateTableMetadataLocation(dbName, tblName, metadataLocation, newLocation);
    Assert.assertFalse(updatedSuccess);
}
Also used : PolarisTableEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with PolarisTableEntity

use of com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity in project metacat by Netflix.

the class PolarisStoreConnectorTest method testTableCreationAndDeletion.

/**
 * Test table creation if database exists.
 * Verify table deletion
 */
@Test
public void testTableCreationAndDeletion() {
    final String dbName = generateDatabaseName();
    final String tblName = generateTableName();
    final PolarisDatabaseEntity dbEntity = createDB(dbName);
    final PolarisTableEntity tblEntity = createTable(dbName, tblName);
    polarisConnector.deleteTable(dbName, tblName);
    Assert.assertFalse(polarisConnector.tableExistsById(tblEntity.getTblId()));
}
Also used : PolarisTableEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity) PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with PolarisTableEntity

use of com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity in project metacat by Netflix.

the class PolarisStoreConnectorTest method testTableUpdate.

/**
 * Test to verify that table name can be updated.
 */
@Test
public void testTableUpdate() {
    // Create Table Entity in DB
    final String dbName = generateDatabaseName();
    final String tblName = generateTableName();
    final PolarisDatabaseEntity dbEntity = createDB(dbName);
    final PolarisTableEntity tblEntity = createTable(dbName, tblName);
    // Update table name
    final String newTblName = generateTableName();
    tblEntity.setTblName(newTblName);
    final PolarisTableEntity updatedTblEntity = polarisConnector.saveTable(tblEntity);
    Assert.assertEquals(newTblName, updatedTblEntity.getTblName());
}
Also used : PolarisTableEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity) PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with PolarisTableEntity

use of com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity in project metacat by Netflix.

the class PolarisTableMapper method toEntity.

/**
 * {@inheritDoc}.
 */
@Override
public PolarisTableEntity toEntity(final TableInfo info) {
    final Map<String, String> metadata = info.getMetadata();
    if (MapUtils.isEmpty(metadata)) {
        final String message = String.format("No parameters defined for iceberg table %s", info.getName());
        throw new InvalidMetaException(info.getName(), message, null);
    }
    final String location = metadata.get(DirectSqlTable.PARAM_METADATA_LOCATION);
    if (StringUtils.isEmpty(location)) {
        final String message = String.format("No metadata location defined for iceberg table %s", info.getName());
        throw new InvalidMetaException(info.getName(), message, null);
    }
    final PolarisTableEntity tableEntity = PolarisTableEntity.builder().dbName(info.getName().getDatabaseName()).tblName(info.getName().getTableName()).metadataLocation(location).build();
    return tableEntity;
}
Also used : PolarisTableEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)

Example 5 with PolarisTableEntity

use of com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity in project metacat by Netflix.

the class PolarisConnectorTableService method create.

/**
 * {@inheritDoc}.
 */
@Override
public void create(final ConnectorRequestContext requestContext, final TableInfo tableInfo) {
    final QualifiedName name = tableInfo.getName();
    // check exists then create in non-transactional optimistic manner
    if (exists(requestContext, name)) {
        throw new TableAlreadyExistsException(name);
    }
    try {
        final PolarisTableEntity entity = polarisTableMapper.toEntity(tableInfo);
        polarisStoreService.createTable(entity.getDbName(), entity.getTblName(), entity.getMetadataLocation());
    } catch (DataIntegrityViolationException | InvalidMetaException exception) {
        throw new InvalidMetaException(name, exception);
    } catch (Exception exception) {
        final String msg = String.format("Failed creating polaris table %s", name);
        log.error(msg, exception);
        throw new ConnectorException(msg, exception);
    }
}
Also used : TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) QualifiedName(com.netflix.metacat.common.QualifiedName) 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

PolarisTableEntity (com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity)13 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)6 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)5 TableAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException)5 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)5 TablePreconditionFailedException (com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException)5 Test (org.junit.jupiter.api.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)5 QualifiedName (com.netflix.metacat.common.QualifiedName)3 TableInfo (com.netflix.metacat.common.server.connectors.model.TableInfo)2 Config (com.netflix.metacat.common.server.properties.Config)2 PolarisDatabaseEntity (com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity)2 Lists (com.google.common.collect.Lists)1 Pageable (com.netflix.metacat.common.dto.Pageable)1 Sort (com.netflix.metacat.common.dto.Sort)1 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)1 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)1 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)1 ConnectorUtils (com.netflix.metacat.common.server.connectors.ConnectorUtils)1