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);
}
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()));
}
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());
}
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;
}
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);
}
}
Aggregations