Search in sources :

Example 1 with PolarisDatabaseEntity

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

the class PolarisStoreConnectorTest method testPaginatedFetch.

/**
 * Test to verify that table names fetch works.
 */
@Test
public void testPaginatedFetch() {
    final String dbName = generateDatabaseName();
    final PolarisDatabaseEntity dbEntity = createDB(dbName);
    List<String> tblNames = polarisConnector.getTables(dbName, "");
    Assert.assertEquals(0, tblNames.size());
    final String tblNameA = "A_" + generateTableName();
    final String tblNameB = "B_" + generateTableName();
    final String tblNameC = "C_" + generateTableName();
    createTable(dbName, tblNameA);
    createTable(dbName, tblNameB);
    createTable(dbName, tblNameC);
    tblNames = polarisConnector.getTables(dbName, "");
    Assert.assertEquals(3, tblNames.size());
    Assert.assertEquals(tblNameA, tblNames.get(0));
    Assert.assertEquals(tblNameB, tblNames.get(1));
    Assert.assertEquals(tblNameC, tblNames.get(2));
}
Also used : PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with PolarisDatabaseEntity

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

the class PolarisStoreConnectorTest method createDB.

private PolarisDatabaseEntity createDB(final String dbName) {
    final String location = "file://temp";
    final PolarisDatabaseEntity entity = polarisConnector.createDatabase(dbName, location);
    // assert that database exists, post-creation.
    Assert.assertTrue(polarisConnector.databaseExistsById(entity.getDbId()));
    Assert.assertTrue(polarisConnector.databaseExists(dbName));
    Assert.assertEquals(0L, entity.getVersion().longValue());
    Assert.assertTrue(entity.getDbId().length() > 0);
    Assert.assertEquals(dbName, entity.getDbName());
    Assert.assertEquals(location, entity.getLocation());
    final Optional<PolarisDatabaseEntity> fetchedEntity = polarisConnector.getDatabase(dbName);
    Assert.assertTrue(fetchedEntity.isPresent());
    Assert.assertEquals(entity, fetchedEntity.get());
    return entity;
}
Also used : PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity)

Example 3 with PolarisDatabaseEntity

use of com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity 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 4 with PolarisDatabaseEntity

use of com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity 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 5 with PolarisDatabaseEntity

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

the class PolarisConnectorDatabaseService method update.

/**
 * {@inheritDoc}.
 */
@Override
public void update(final ConnectorRequestContext context, final DatabaseInfo databaseInfo) {
    final QualifiedName name = databaseInfo.getName();
    try {
        final PolarisDatabaseEntity db = polarisStoreService.getDatabase(name.getDatabaseName()).orElseThrow(() -> new DatabaseNotFoundException(name));
        // currently db objects have no mutable fields so this is noop
        polarisStoreService.saveDatabase(db.toBuilder().build());
    } catch (DatabaseNotFoundException exception) {
        log.error(String.format("Not found exception for polaris database %s", name), exception);
        throw exception;
    } catch (DataIntegrityViolationException exception) {
        throw new InvalidMetaException(name, exception);
    } catch (Exception exception) {
        throw new ConnectorException(String.format("Failed updating polaris database %s", databaseInfo.getName()), exception);
    }
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Aggregations

PolarisDatabaseEntity (com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity)8 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)3 DatabaseAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException)3 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)3 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)3 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)3 QualifiedName (com.netflix.metacat.common.QualifiedName)2 PolarisDatabaseMapper (com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper)2 PolarisTableEntity (com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity)2 ArrayList (java.util.ArrayList)2 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 ConnectorDatabaseService (com.netflix.metacat.common.server.connectors.ConnectorDatabaseService)1 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)1 ConnectorUtils (com.netflix.metacat.common.server.connectors.ConnectorUtils)1 DatabaseInfo (com.netflix.metacat.common.server.connectors.model.DatabaseInfo)1 PolarisStoreService (com.netflix.metacat.connector.polaris.store.PolarisStoreService)1