diff --git a/metacat-connector-polaris/src/functionalTest/resources/application-polaris_functional_test.yml b/metacat-connector-polaris/src/functionalTest/resources/application-polaris_functional_test.yml index 5c6a59fe..c2c999ff 100644 --- a/metacat-connector-polaris/src/functionalTest/resources/application-polaris_functional_test.yml +++ b/metacat-connector-polaris/src/functionalTest/resources/application-polaris_functional_test.yml @@ -17,7 +17,7 @@ spring: ddl-auto: none properties: hibernate: - dialect: org.hibernate.dialect.PostgreSQLDialect + dialect: org.hibernate.dialect.PostgreSQLDialect show_sql: true sql: init: diff --git a/metacat-connector-polaris/src/main/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseService.java b/metacat-connector-polaris/src/main/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseService.java index 7b3a41ce..33bffce2 100644 --- a/metacat-connector-polaris/src/main/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseService.java +++ b/metacat-connector-polaris/src/main/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseService.java @@ -10,7 +10,6 @@ import com.netflix.metacat.common.server.connectors.exception.ConnectorException; import com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException; import com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException; -import com.netflix.metacat.common.server.connectors.exception.DatabasePreconditionFailedException; import com.netflix.metacat.common.server.connectors.exception.InvalidMetaException; import com.netflix.metacat.common.server.connectors.model.DatabaseInfo; import com.netflix.metacat.connector.polaris.common.PolarisUtils; @@ -88,13 +87,13 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na try { this.polarisStoreService.deleteDatabase(name.getDatabaseName()); } catch (DataIntegrityViolationException exception) { - if (exception.getCause() instanceof org.hibernate.exception.ConstraintViolationException) { - throw new DatabasePreconditionFailedException( - name, - String.format("Cannot delete database %s because it is not empty.", name.getDatabaseName()), - exception - ); - } +// if (exception.getCause() instanceof ConstraintViolationException) { +// throw new DatabasePreconditionFailedException( +// name, +// String.format("Cannot delete database %s because it is not empty.", name.getDatabaseName()), +// exception +// ); +// } throw new InvalidMetaException(name, exception); } catch (Exception exception) { throw new ConnectorException( diff --git a/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceTest.java b/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceTest.java index b765e773..787b5ddb 100644 --- a/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceTest.java +++ b/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceTest.java @@ -1,5 +1,6 @@ package com.netflix.metacat.connector.polaris; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.netflix.metacat.common.QualifiedName; import com.netflix.metacat.common.server.connectors.ConnectorContext; @@ -8,9 +9,18 @@ import com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException; import com.netflix.metacat.common.server.connectors.model.AuditInfo; import com.netflix.metacat.common.server.connectors.model.DatabaseInfo; +import com.netflix.metacat.common.server.connectors.model.TableInfo; import com.netflix.metacat.common.server.properties.DefaultConfigImpl; import com.netflix.metacat.common.server.properties.MetacatProperties; +import com.netflix.metacat.common.server.util.ThreadServiceManager; +import com.netflix.metacat.connector.hive.converters.HiveConnectorInfoConverter; +import com.netflix.metacat.connector.hive.converters.HiveTypeConverter; +import com.netflix.metacat.connector.hive.iceberg.IcebergTableCriteriaImpl; +import com.netflix.metacat.connector.hive.iceberg.IcebergTableHandler; +import com.netflix.metacat.connector.hive.iceberg.IcebergTableOpWrapper; +import com.netflix.metacat.connector.hive.iceberg.IcebergTableOpsProxy; import com.netflix.metacat.connector.polaris.configs.PolarisPersistenceConfig; +import com.netflix.metacat.connector.polaris.mappers.PolarisTableMapper; import com.netflix.metacat.connector.polaris.store.PolarisStoreService; import com.netflix.spectator.api.NoopRegistry; import lombok.Getter; @@ -19,9 +29,11 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.dao.DataIntegrityViolationException; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -55,17 +67,37 @@ public class PolarisConnectorDatabaseServiceTest { @Shared private ConnectorRequestContext requestContext = new ConnectorRequestContext(); + @Shared + private ThreadServiceManager serviceManager = Mockito.mock(ThreadServiceManager.class); + @Shared private PolarisConnectorDatabaseService polarisDBService; + @Shared + private PolarisConnectorTableService polarisTableService; + /** * Initialization. */ @BeforeEach public void init() { + final String location = "file://temp2"; + polarisStoreService.createDatabase(DB1_NAME, location, "metacat_user"); connectorContext = new ConnectorContext(CATALOG_NAME, CATALOG_NAME, "polaris", new DefaultConfigImpl(new MetacatProperties(null)), new NoopRegistry(), null, Maps.newHashMap()); polarisDBService = new PolarisConnectorDatabaseService(polarisStoreService, connectorContext); + + polarisTableService = new PolarisConnectorTableService( + polarisStoreService, + CATALOG_NAME, + polarisDBService, + new HiveConnectorInfoConverter(new HiveTypeConverter()), + new IcebergTableHandler(connectorContext, + new IcebergTableCriteriaImpl(connectorContext), + new IcebergTableOpWrapper(connectorContext, serviceManager), + new IcebergTableOpsProxy()), + new PolarisTableMapper(CATALOG_NAME), + connectorContext); } /** @@ -165,4 +197,23 @@ public void testDeleteDb() { polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); Assert.assertFalse(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); } + + @Test + public void testDeleteDbNoCascades() { + Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); + + final QualifiedName qualifiedName = QualifiedName.ofTable(CATALOG_NAME, DB1_QUALIFIED_NAME.getDatabaseName(), "table1"); + final TableInfo tableInfo = TableInfo.builder() + .name(qualifiedName) + .metadata(ImmutableMap.of("table_type", "ICEBERG", "metadata_location", "loc1")) + .build(); + polarisTableService.create(requestContext, tableInfo); + Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); + + polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); + + Assertions.assertThrows(DataIntegrityViolationException.class, () -> + polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); + Assert.assertTrue(polarisDBService.exists(requestContext, qualifiedName)); + } }