From 4a5d863215060062c9051738a8eb24601fbceadb Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Mon, 2 Dec 2024 23:02:42 -0800 Subject: [PATCH 01/41] Build test --- .../src/functionalTest/resources/schema.sql | 2 +- .../PolarisConnectorDatabaseServiceTest.java | 50 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/metacat-connector-polaris/src/functionalTest/resources/schema.sql b/metacat-connector-polaris/src/functionalTest/resources/schema.sql index aae7a9c23..c92e58858 100644 --- a/metacat-connector-polaris/src/functionalTest/resources/schema.sql +++ b/metacat-connector-polaris/src/functionalTest/resources/schema.sql @@ -24,5 +24,5 @@ create table TBLS ( created_date TIMESTAMP not null, last_updated_by STRING(255), last_updated_date TIMESTAMP not null, - foreign key (db_name) references DBS(name) ON DELETE CASCADE ON UPDATE CASCADE + foreign key (db_name) references DBS(name) ON UPDATE CASCADE ); 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 e297704f8..40041cdcb 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,6 +1,7 @@ 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; @@ -9,9 +10,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; @@ -20,6 +30,7 @@ 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; @@ -32,7 +43,7 @@ /** - * Test PolarisConnectorTableService. + * Test PolarisConnectorDatabaseService. */ @ExtendWith(SpringExtension.class) @SpringBootTest(classes = {PolarisPersistenceConfig.class}) @@ -56,9 +67,15 @@ 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. */ @@ -67,6 +84,17 @@ public void init() { 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); } /** @@ -166,5 +194,25 @@ public void testDeleteDb() { polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); Assert.assertFalse(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); } + + /** + * Test delete database. + */ + @Test + public void testDeleteDbNoCascades() { + final DatabaseInfo info = DatabaseInfo.builder().name(DB1_QUALIFIED_NAME).build(); + polarisDBService.create(requestContext, info); + 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); + } } From 116a6c4b6749a84131f2b384168917d35deb77da Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Tue, 3 Dec 2024 13:34:32 -0800 Subject: [PATCH 02/41] fix checkstyle --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 40041cdcb..0c93eb43e 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 @@ -82,7 +82,7 @@ public class PolarisConnectorDatabaseServiceTest { @BeforeEach public void init() { connectorContext = new ConnectorContext(CATALOG_NAME, CATALOG_NAME, "polaris", - new DefaultConfigImpl(new MetacatProperties(null)), new NoopRegistry(), null, Maps.newHashMap()); + new DefaultConfigImpl(new MetacatProperties(null)), new NoopRegistry(), null, Maps.newHashMap()); polarisDBService = new PolarisConnectorDatabaseService(polarisStoreService, connectorContext); polarisTableService = new PolarisConnectorTableService( polarisStoreService, From 59b28b10e4c5a5970cd5c7082ab3ebae6a4c24b8 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Tue, 3 Dec 2024 14:44:38 -0800 Subject: [PATCH 03/41] fix checkstyle --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 0c93eb43e..0e1d066b0 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 @@ -204,7 +204,8 @@ public void testDeleteDbNoCascades() { polarisDBService.create(requestContext, info); Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); - final QualifiedName qualifiedName = QualifiedName.ofTable(CATALOG_NAME, DB1_QUALIFIED_NAME.getDatabaseName(), "table1"); + 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")) From 6eb29c320caa913add30c9eec18b5a3da801af61 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Tue, 3 Dec 2024 19:19:18 -0800 Subject: [PATCH 04/41] see if the test error is due to schema change --- .../src/functionalTest/resources/schema.sql | 2 +- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/metacat-connector-polaris/src/functionalTest/resources/schema.sql b/metacat-connector-polaris/src/functionalTest/resources/schema.sql index c92e58858..aae7a9c23 100644 --- a/metacat-connector-polaris/src/functionalTest/resources/schema.sql +++ b/metacat-connector-polaris/src/functionalTest/resources/schema.sql @@ -24,5 +24,5 @@ create table TBLS ( created_date TIMESTAMP not null, last_updated_by STRING(255), last_updated_date TIMESTAMP not null, - foreign key (db_name) references DBS(name) ON UPDATE CASCADE + foreign key (db_name) references DBS(name) ON DELETE CASCADE ON UPDATE CASCADE ); 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 0e1d066b0..4d683d7d4 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 @@ -214,6 +214,7 @@ public void testDeleteDbNoCascades() { Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); + Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); } } From 612b0b35c1f0ade31ac354154b69e740666c7f96 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Tue, 3 Dec 2024 22:57:10 -0800 Subject: [PATCH 05/41] check tests --- .../src/functionalTest/resources/schema.sql | 2 +- .../polaris/PolarisConnectorDatabaseService.java | 3 +++ .../polaris/PolarisConnectorDatabaseServiceTest.java | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/metacat-connector-polaris/src/functionalTest/resources/schema.sql b/metacat-connector-polaris/src/functionalTest/resources/schema.sql index aae7a9c23..c92e58858 100644 --- a/metacat-connector-polaris/src/functionalTest/resources/schema.sql +++ b/metacat-connector-polaris/src/functionalTest/resources/schema.sql @@ -24,5 +24,5 @@ create table TBLS ( created_date TIMESTAMP not null, last_updated_by STRING(255), last_updated_date TIMESTAMP not null, - foreign key (db_name) references DBS(name) ON DELETE CASCADE ON UPDATE CASCADE + foreign key (db_name) references DBS(name) ON UPDATE CASCADE ); 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 94d67780e..a2de24460 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 @@ -87,6 +87,9 @@ 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 InvalidMetaException(name, "Cannot delete database because it still contains tables.", 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 4d683d7d4..63f94a7eb 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 @@ -8,6 +8,7 @@ import com.netflix.metacat.common.server.connectors.ConnectorRequestContext; 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.InvalidMetaException; 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; @@ -213,7 +214,12 @@ public void testDeleteDbNoCascades() { polarisTableService.create(requestContext, tableInfo); Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); - polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); + // Expect an InvalidMetaException when trying to delete a non-empty database + Assertions.assertThrows(InvalidMetaException.class, () -> { + polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); + }); + + // Ensure the database still exists after the failed delete attempt Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); } } From f2326425fdf8f9d2907b1a0235b49fa05d1a3b2f Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Tue, 3 Dec 2024 23:16:42 -0800 Subject: [PATCH 06/41] check tests --- .../exception/ConnectorException.java | 2 +- .../DatabasePreconditionFailedException.java | 48 +++++++++++++++++++ .../PolarisConnectorDatabaseService.java | 7 ++- .../PolarisConnectorDatabaseServiceTest.java | 6 +-- 4 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 metacat-common-server/src/main/java/com/netflix/metacat/common/server/connectors/exception/DatabasePreconditionFailedException.java diff --git a/metacat-common-server/src/main/java/com/netflix/metacat/common/server/connectors/exception/ConnectorException.java b/metacat-common-server/src/main/java/com/netflix/metacat/common/server/connectors/exception/ConnectorException.java index ed4125774..d45dec070 100644 --- a/metacat-common-server/src/main/java/com/netflix/metacat/common/server/connectors/exception/ConnectorException.java +++ b/metacat-common-server/src/main/java/com/netflix/metacat/common/server/connectors/exception/ConnectorException.java @@ -50,7 +50,7 @@ public ConnectorException(final String message, @Nullable final Throwable cause) * * @param message message * @param cause cause - * @param enableSuppression eable suppression + * @param enableSuppression enable suppression * @param writableStackTrace stacktrace */ public ConnectorException( diff --git a/metacat-common-server/src/main/java/com/netflix/metacat/common/server/connectors/exception/DatabasePreconditionFailedException.java b/metacat-common-server/src/main/java/com/netflix/metacat/common/server/connectors/exception/DatabasePreconditionFailedException.java new file mode 100644 index 000000000..54b153ffe --- /dev/null +++ b/metacat-common-server/src/main/java/com/netflix/metacat/common/server/connectors/exception/DatabasePreconditionFailedException.java @@ -0,0 +1,48 @@ +package com.netflix.metacat.common.server.connectors.exception; + +/* + * + * Copyright 2024 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import com.netflix.metacat.common.QualifiedName; +import lombok.Getter; + +import javax.annotation.Nullable; + +/** + * Exception when database can't be deleted because ON DELETE CASCADE is + * disabled and a table still exists in the database. + * + * @author gtret + */ +@Getter +public class DatabasePreconditionFailedException extends ConnectorException { + /** + * Constructor. + * + * @param name qualified name of the database + * @param message error description + * @param error stacktrace + */ + public DatabasePreconditionFailedException(final QualifiedName name, + @Nullable final String message, + @Nullable final Throwable error) { + super(String.format("Precondition failed to update table %s. %s", name, message), error); + } +} + + 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 a2de24460..51e4e31ee 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,6 +10,7 @@ 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,7 +89,11 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na this.polarisStoreService.deleteDatabase(name.getDatabaseName()); } catch (DataIntegrityViolationException exception) { if (exception.getCause() instanceof org.hibernate.exception.ConstraintViolationException) { - throw new InvalidMetaException(name, "Cannot delete database because it still contains tables.", exception); + 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) { 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 63f94a7eb..1bc21d8bf 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 @@ -8,6 +8,7 @@ import com.netflix.metacat.common.server.connectors.ConnectorRequestContext; 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.AuditInfo; import com.netflix.metacat.common.server.connectors.model.DatabaseInfo; @@ -215,9 +216,8 @@ public void testDeleteDbNoCascades() { Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); // Expect an InvalidMetaException when trying to delete a non-empty database - Assertions.assertThrows(InvalidMetaException.class, () -> { - polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); - }); + Assertions.assertThrows(DatabasePreconditionFailedException.class, () -> + polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); // Ensure the database still exists after the failed delete attempt Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); From a1fd48505d60a1a2fa3bea60ea706fbb8f090be3 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Tue, 3 Dec 2024 23:26:49 -0800 Subject: [PATCH 07/41] checkstyle --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 1bc21d8bf..158835810 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 @@ -9,7 +9,6 @@ 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.AuditInfo; import com.netflix.metacat.common.server.connectors.model.DatabaseInfo; import com.netflix.metacat.common.server.connectors.model.TableInfo; @@ -198,7 +197,7 @@ public void testDeleteDb() { } /** - * Test delete database. + * Test delete database when ON DELETE CASCADE is disabled. */ @Test public void testDeleteDbNoCascades() { From 5e2824c1f489cd0279974a9142aa63ff7326dcde Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Tue, 3 Dec 2024 23:35:33 -0800 Subject: [PATCH 08/41] test --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 158835810..fcd8fad6b 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 @@ -214,7 +214,8 @@ public void testDeleteDbNoCascades() { polarisTableService.create(requestContext, tableInfo); Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); - // Expect an InvalidMetaException when trying to delete a non-empty database + polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); + // Expect an DatabasePreconditionFailedException when trying to delete a non-empty database Assertions.assertThrows(DatabasePreconditionFailedException.class, () -> polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); From 20d3853d2cb0ad8ce61bc74e621e28d962343dde Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Tue, 3 Dec 2024 23:45:58 -0800 Subject: [PATCH 09/41] test --- .../connector/polaris/PolarisConnectorDatabaseService.java | 4 ++++ .../polaris/PolarisConnectorDatabaseServiceTest.java | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) 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 51e4e31ee..f91e9a40e 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 @@ -86,8 +86,11 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na throw new DatabaseNotFoundException(name); } try { + System.out.println("BEFORE deleting polaris database " + name.getDatabaseName()); this.polarisStoreService.deleteDatabase(name.getDatabaseName()); + System.out.println("AFTER deleting polaris database " + name.getDatabaseName()); } catch (DataIntegrityViolationException exception) { + System.out.println("CAUGHT THE DB DELETE ERROR"); if (exception.getCause() instanceof org.hibernate.exception.ConstraintViolationException) { throw new DatabasePreconditionFailedException( name, @@ -100,6 +103,7 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na throw new ConnectorException( String.format("Failed deleting polaris database %s", name), exception); } + System.out.println("DID NOT CATCH THE DB DELETE ERROR"); } /** 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 fcd8fad6b..c3774762e 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 @@ -214,7 +214,6 @@ public void testDeleteDbNoCascades() { polarisTableService.create(requestContext, tableInfo); Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); - polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); // Expect an DatabasePreconditionFailedException when trying to delete a non-empty database Assertions.assertThrows(DatabasePreconditionFailedException.class, () -> polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); From 12bf322b864355c957bd76b44aa38d7f8e9d081f Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Tue, 3 Dec 2024 23:58:15 -0800 Subject: [PATCH 10/41] test --- metacat-connector-polaris/src/test/resources/h2db/schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metacat-connector-polaris/src/test/resources/h2db/schema.sql b/metacat-connector-polaris/src/test/resources/h2db/schema.sql index 93b389a56..46ed13ae2 100644 --- a/metacat-connector-polaris/src/test/resources/h2db/schema.sql +++ b/metacat-connector-polaris/src/test/resources/h2db/schema.sql @@ -24,7 +24,7 @@ create table TBLS ( created_date TIMESTAMP not null, last_updated_by varchar(255), last_updated_date TIMESTAMP not null, - foreign key (db_name) references DBS(name) ON DELETE CASCADE ON UPDATE CASCADE + foreign key (db_name) references DBS(name) ON UPDATE CASCADE ); CREATE INDEX DB_NAME_IDX ON TBLS(db_name); From 7808048c68b5d2a8c0606e33d21a2f399827850b Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 00:08:40 -0800 Subject: [PATCH 11/41] test --- .../polaris/PolarisConnectorDatabaseServiceTest.java | 4 ++-- .../metacat-test-cluster/datastores/crdb/sql/schema.sql | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 c3774762e..3cbb360aa 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 @@ -215,8 +215,8 @@ public void testDeleteDbNoCascades() { Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); // Expect an DatabasePreconditionFailedException when trying to delete a non-empty database - Assertions.assertThrows(DatabasePreconditionFailedException.class, () -> - polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); + // Assertions.assertThrows(DatabasePreconditionFailedException.class, () -> + polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); // Ensure the database still exists after the failed delete attempt Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); diff --git a/metacat-functional-tests/metacat-test-cluster/datastores/crdb/sql/schema.sql b/metacat-functional-tests/metacat-test-cluster/datastores/crdb/sql/schema.sql index 98887559b..f78a9d86e 100644 --- a/metacat-functional-tests/metacat-test-cluster/datastores/crdb/sql/schema.sql +++ b/metacat-functional-tests/metacat-test-cluster/datastores/crdb/sql/schema.sql @@ -24,5 +24,5 @@ create table TBLS ( last_updated_by STRING(255), last_updated_date TIMESTAMP not null, constraint uniq_name unique(db_name, tbl_name), - foreign key (db_name) references DBS(name) ON DELETE CASCADE ON UPDATE CASCADE + foreign key (db_name) references DBS(name) ON UPDATE CASCADE ); From 720b7e37aaaaddbe120abcf723825c84b252dffd Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 00:24:14 -0800 Subject: [PATCH 12/41] test --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 1 - 1 file changed, 1 deletion(-) 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 3cbb360aa..9a03cb3a5 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 @@ -8,7 +8,6 @@ import com.netflix.metacat.common.server.connectors.ConnectorRequestContext; 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.model.AuditInfo; import com.netflix.metacat.common.server.connectors.model.DatabaseInfo; import com.netflix.metacat.common.server.connectors.model.TableInfo; From 14c8ea45a3a61ca326130eb412ffd6377929dec4 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 00:44:08 -0800 Subject: [PATCH 13/41] test --- .../src/functionalTest/resources/schema.sql | 2 +- .../polaris/PolarisConnectorDatabaseServiceTest.java | 9 +++------ .../src/test/resources/h2db/schema.sql | 2 +- .../metacat-test-cluster/datastores/crdb/sql/schema.sql | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/metacat-connector-polaris/src/functionalTest/resources/schema.sql b/metacat-connector-polaris/src/functionalTest/resources/schema.sql index c92e58858..0f6ce05a6 100644 --- a/metacat-connector-polaris/src/functionalTest/resources/schema.sql +++ b/metacat-connector-polaris/src/functionalTest/resources/schema.sql @@ -24,5 +24,5 @@ create table TBLS ( created_date TIMESTAMP not null, last_updated_by STRING(255), last_updated_date TIMESTAMP not null, - foreign key (db_name) references DBS(name) ON UPDATE CASCADE + foreign key (db_name) references DBS(name) ON DELETE RESTRICT ON UPDATE CASCADE ); 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 9a03cb3a5..01041fb15 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 @@ -8,6 +8,7 @@ import com.netflix.metacat.common.server.connectors.ConnectorRequestContext; 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.model.AuditInfo; import com.netflix.metacat.common.server.connectors.model.DatabaseInfo; import com.netflix.metacat.common.server.connectors.model.TableInfo; @@ -212,12 +213,8 @@ public void testDeleteDbNoCascades() { .build(); polarisTableService.create(requestContext, tableInfo); Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); - - // Expect an DatabasePreconditionFailedException when trying to delete a non-empty database - // Assertions.assertThrows(DatabasePreconditionFailedException.class, () -> - polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); - - // Ensure the database still exists after the failed delete attempt + Assertions.assertThrows(DatabasePreconditionFailedException.class, () -> + polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); } } diff --git a/metacat-connector-polaris/src/test/resources/h2db/schema.sql b/metacat-connector-polaris/src/test/resources/h2db/schema.sql index 46ed13ae2..36d3bc6f9 100644 --- a/metacat-connector-polaris/src/test/resources/h2db/schema.sql +++ b/metacat-connector-polaris/src/test/resources/h2db/schema.sql @@ -24,7 +24,7 @@ create table TBLS ( created_date TIMESTAMP not null, last_updated_by varchar(255), last_updated_date TIMESTAMP not null, - foreign key (db_name) references DBS(name) ON UPDATE CASCADE + foreign key (db_name) references DBS(name) ON DELETE RESTRICT ON UPDATE CASCADE ); CREATE INDEX DB_NAME_IDX ON TBLS(db_name); diff --git a/metacat-functional-tests/metacat-test-cluster/datastores/crdb/sql/schema.sql b/metacat-functional-tests/metacat-test-cluster/datastores/crdb/sql/schema.sql index f78a9d86e..2d947fdb1 100644 --- a/metacat-functional-tests/metacat-test-cluster/datastores/crdb/sql/schema.sql +++ b/metacat-functional-tests/metacat-test-cluster/datastores/crdb/sql/schema.sql @@ -24,5 +24,5 @@ create table TBLS ( last_updated_by STRING(255), last_updated_date TIMESTAMP not null, constraint uniq_name unique(db_name, tbl_name), - foreign key (db_name) references DBS(name) ON UPDATE CASCADE + foreign key (db_name) references DBS(name) ON DELETE RESTRICT ON UPDATE CASCADE ); From b9ee9fdee9747c84fb02448c1f7aecae2cf5f663 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 00:57:36 -0800 Subject: [PATCH 14/41] test --- .../polaris/PolarisConnectorDatabaseServiceTest.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 01041fb15..998aa628e 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 @@ -35,6 +35,7 @@ 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.core.env.Environment; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -77,11 +78,16 @@ public class PolarisConnectorDatabaseServiceTest { @Shared private PolarisConnectorTableService polarisTableService; + @Shared + private Environment env = Mockito.mock(Environment.class); + /** * Initialization. */ @BeforeEach public void init() { + final String location = "file://temp"; + 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); From 6a3b2bcfc9017e4964a50371adf634ed92da30c6 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 01:12:05 -0800 Subject: [PATCH 15/41] test hopefully last --- .../PolarisConnectorDatabaseServiceTest.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) 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 998aa628e..eea6ca416 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 @@ -86,22 +86,9 @@ public class PolarisConnectorDatabaseServiceTest { */ @BeforeEach public void init() { - final String location = "file://temp"; - 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); } /** @@ -207,6 +194,20 @@ public void testDeleteDb() { */ @Test public void testDeleteDbNoCascades() { + final String location = "file://temp"; + polarisStoreService.createDatabase(DB1_NAME, location, "metacat_user"); + 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); + final DatabaseInfo info = DatabaseInfo.builder().name(DB1_QUALIFIED_NAME).build(); polarisDBService.create(requestContext, info); Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); From 725faa3ed1cfc87eeec910831448bcfa7f654c2e Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 01:33:46 -0800 Subject: [PATCH 16/41] test --- .../PolarisConnectorDatabaseServiceTest.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) 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 eea6ca416..fb6e1b8e3 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 @@ -86,9 +86,22 @@ public class PolarisConnectorDatabaseServiceTest { */ @BeforeEach public void init() { + final String location = "file://temp"; + polarisStoreService.createDatabase(DB2_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); } /** @@ -194,26 +207,12 @@ public void testDeleteDb() { */ @Test public void testDeleteDbNoCascades() { - final String location = "file://temp"; - polarisStoreService.createDatabase(DB1_NAME, location, "metacat_user"); - 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); - - final DatabaseInfo info = DatabaseInfo.builder().name(DB1_QUALIFIED_NAME).build(); + final DatabaseInfo info = DatabaseInfo.builder().name(DB2_QUALIFIED_NAME).build(); polarisDBService.create(requestContext, info); - Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); + Assert.assertTrue(polarisDBService.exists(requestContext, DB2_QUALIFIED_NAME)); final QualifiedName qualifiedName = QualifiedName.ofTable( - CATALOG_NAME, DB1_QUALIFIED_NAME.getDatabaseName(), "table1"); + CATALOG_NAME, DB2_QUALIFIED_NAME.getDatabaseName(), "table1"); final TableInfo tableInfo = TableInfo.builder() .name(qualifiedName) .metadata(ImmutableMap.of("table_type", "ICEBERG", "metadata_location", "loc1")) @@ -221,8 +220,8 @@ public void testDeleteDbNoCascades() { polarisTableService.create(requestContext, tableInfo); Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); Assertions.assertThrows(DatabasePreconditionFailedException.class, () -> - polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); - Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); + polarisDBService.delete(requestContext, DB2_QUALIFIED_NAME)); + Assert.assertTrue(polarisDBService.exists(requestContext, DB2_QUALIFIED_NAME)); } } From 79fa3e1512485766418c66ec1da7c4a5a9bd4e8a Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 01:37:38 -0800 Subject: [PATCH 17/41] checkstyle --- .../polaris/PolarisConnectorDatabaseServiceTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 fb6e1b8e3..5ec2b302d 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 @@ -89,7 +89,12 @@ public void init() { final String location = "file://temp"; polarisStoreService.createDatabase(DB2_NAME, location, "metacat_user"); connectorContext = new ConnectorContext(CATALOG_NAME, CATALOG_NAME, "polaris", - new DefaultConfigImpl(new MetacatProperties(null)), new NoopRegistry(), null, Maps.newHashMap()); + new DefaultConfigImpl( + new MetacatProperties(null) + ), + new NoopRegistry(), + null, + Maps.newHashMap()); polarisDBService = new PolarisConnectorDatabaseService(polarisStoreService, connectorContext); polarisTableService = new PolarisConnectorTableService( polarisStoreService, From 588bbda3ff76c569ad9b8abcd9b09fed3d7f3539 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 01:45:52 -0800 Subject: [PATCH 18/41] already exists --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 3 --- 1 file changed, 3 deletions(-) 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 5ec2b302d..2820e9e15 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 @@ -78,9 +78,6 @@ public class PolarisConnectorDatabaseServiceTest { @Shared private PolarisConnectorTableService polarisTableService; - @Shared - private Environment env = Mockito.mock(Environment.class); - /** * Initialization. */ From bc407d043ddb480b8737a98acb767cff40c09646 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 01:47:58 -0800 Subject: [PATCH 19/41] checkstyle --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 1 - 1 file changed, 1 deletion(-) 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 2820e9e15..069d84149 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 @@ -35,7 +35,6 @@ 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.core.env.Environment; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; From 89dabd1e14213eee73676ae364fffcc2ac434c17 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 01:55:09 -0800 Subject: [PATCH 20/41] test --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 2 -- 1 file changed, 2 deletions(-) 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 069d84149..bb3c5add2 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 @@ -82,8 +82,6 @@ public class PolarisConnectorDatabaseServiceTest { */ @BeforeEach public void init() { - final String location = "file://temp"; - polarisStoreService.createDatabase(DB2_NAME, location, "metacat_user"); connectorContext = new ConnectorContext(CATALOG_NAME, CATALOG_NAME, "polaris", new DefaultConfigImpl( new MetacatProperties(null) From 91a425d77378d5c49256c311ac7555bd47360dba Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 02:11:31 -0800 Subject: [PATCH 21/41] move test --- .../PolarisConnectorDatabaseServiceTest.java | 62 +------------------ .../store/PolarisStoreConnectorTest.java | 17 +++++ 2 files changed, 19 insertions(+), 60 deletions(-) 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 bb3c5add2..b765e7735 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,28 +1,16 @@ - 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; import com.netflix.metacat.common.server.connectors.ConnectorRequestContext; 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.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; @@ -31,7 +19,6 @@ 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; @@ -44,7 +31,7 @@ /** - * Test PolarisConnectorDatabaseService. + * Test PolarisConnectorTableService. */ @ExtendWith(SpringExtension.class) @SpringBootTest(classes = {PolarisPersistenceConfig.class}) @@ -68,39 +55,17 @@ 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() { connectorContext = new ConnectorContext(CATALOG_NAME, CATALOG_NAME, "polaris", - new DefaultConfigImpl( - new MetacatProperties(null) - ), - new NoopRegistry(), - null, - Maps.newHashMap()); + 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); } /** @@ -200,27 +165,4 @@ public void testDeleteDb() { polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); Assert.assertFalse(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); } - - /** - * Test delete database when ON DELETE CASCADE is disabled. - */ - @Test - public void testDeleteDbNoCascades() { - final DatabaseInfo info = DatabaseInfo.builder().name(DB2_QUALIFIED_NAME).build(); - polarisDBService.create(requestContext, info); - Assert.assertTrue(polarisDBService.exists(requestContext, DB2_QUALIFIED_NAME)); - - final QualifiedName qualifiedName = QualifiedName.ofTable( - CATALOG_NAME, DB2_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)); - Assertions.assertThrows(DatabasePreconditionFailedException.class, () -> - polarisDBService.delete(requestContext, DB2_QUALIFIED_NAME)); - Assert.assertTrue(polarisDBService.exists(requestContext, DB2_QUALIFIED_NAME)); - } } - diff --git a/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnectorTest.java b/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnectorTest.java index 9479c6e14..cec63761a 100644 --- a/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnectorTest.java +++ b/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnectorTest.java @@ -1,6 +1,7 @@ package com.netflix.metacat.connector.polaris.store; +import com.netflix.metacat.common.server.connectors.exception.DatabasePreconditionFailedException; import com.netflix.metacat.connector.polaris.common.PolarisUtils; import com.netflix.metacat.connector.polaris.configs.PolarisPersistenceConfig; import com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity; @@ -127,6 +128,22 @@ public void testTableCreationAndDeletion() { Assert.assertFalse(polarisConnector.tableExistsById(tblEntity.getTblId())); } + /** + * Test table creation if database exists. + * Verify table deletion + */ + @Test + public void testDbDeletionNoCascade() { + final String dbName = generateDatabaseName(); + final String tblName = generateTableName(); + final PolarisDatabaseEntity dbEntity = createDB(dbName); + final PolarisTableEntity tblEntity = createTable(dbName, tblName); + + Assertions.assertThrows(DatabasePreconditionFailedException.class, () -> + polarisConnector.deleteDatabase(dbName)); + Assert.assertFalse(polarisConnector.tableExistsById(tblEntity.getTblId())); + } + /** * Test to verify that table name can be updated. */ From 8275c096e899ceb0ed428b1afc26c56c553d75b1 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 02:12:49 -0800 Subject: [PATCH 22/41] fix moved test --- .../connector/polaris/store/PolarisStoreConnectorTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnectorTest.java b/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnectorTest.java index cec63761a..e3997fb3f 100644 --- a/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnectorTest.java +++ b/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnectorTest.java @@ -129,8 +129,7 @@ public void testTableCreationAndDeletion() { } /** - * Test table creation if database exists. - * Verify table deletion + * Test database deletion if table exists and ON DELETE CASCADE is disabled. */ @Test public void testDbDeletionNoCascade() { @@ -141,7 +140,7 @@ public void testDbDeletionNoCascade() { Assertions.assertThrows(DatabasePreconditionFailedException.class, () -> polarisConnector.deleteDatabase(dbName)); - Assert.assertFalse(polarisConnector.tableExistsById(tblEntity.getTblId())); + Assert.assertTrue(polarisConnector.databaseExists(dbName)); } /** From fd0085f6fa6806bf44c9154acae1ebdea69b5a20 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 02:21:01 -0800 Subject: [PATCH 23/41] fix test final --- .../connector/polaris/PolarisConnectorDatabaseService.java | 3 --- .../connector/polaris/store/PolarisStoreConnectorTest.java | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) 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 f91e9a40e..7b3a41ce3 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 @@ -86,11 +86,8 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na throw new DatabaseNotFoundException(name); } try { - System.out.println("BEFORE deleting polaris database " + name.getDatabaseName()); this.polarisStoreService.deleteDatabase(name.getDatabaseName()); - System.out.println("AFTER deleting polaris database " + name.getDatabaseName()); } catch (DataIntegrityViolationException exception) { - System.out.println("CAUGHT THE DB DELETE ERROR"); if (exception.getCause() instanceof org.hibernate.exception.ConstraintViolationException) { throw new DatabasePreconditionFailedException( name, diff --git a/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnectorTest.java b/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnectorTest.java index e3997fb3f..f31b58846 100644 --- a/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnectorTest.java +++ b/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnectorTest.java @@ -1,7 +1,6 @@ package com.netflix.metacat.connector.polaris.store; -import com.netflix.metacat.common.server.connectors.exception.DatabasePreconditionFailedException; import com.netflix.metacat.connector.polaris.common.PolarisUtils; import com.netflix.metacat.connector.polaris.configs.PolarisPersistenceConfig; import com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity; @@ -17,6 +16,7 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.dao.DataAccessException; +import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.OptimisticLockingFailureException; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -138,7 +138,7 @@ public void testDbDeletionNoCascade() { final PolarisDatabaseEntity dbEntity = createDB(dbName); final PolarisTableEntity tblEntity = createTable(dbName, tblName); - Assertions.assertThrows(DatabasePreconditionFailedException.class, () -> + Assertions.assertThrows(DataIntegrityViolationException.class, () -> polarisConnector.deleteDatabase(dbName)); Assert.assertTrue(polarisConnector.databaseExists(dbName)); } From 5efabf5f03db5deb12b6c5b8894da0455aac9049 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 02:47:30 -0800 Subject: [PATCH 24/41] minor changes --- .../application-polaris_functional_test.yml | 2 +- .../PolarisConnectorDatabaseService.java | 15 +++--- .../PolarisConnectorDatabaseServiceTest.java | 51 +++++++++++++++++++ 3 files changed, 59 insertions(+), 9 deletions(-) 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 5c6a59feb..c2c999ff0 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 7b3a41ce3..33bffce22 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 b765e7735..787b5ddbc 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)); + } } From 9a9e37255ec108257b525a4da800140f048d7c8a Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 03:06:25 -0800 Subject: [PATCH 25/41] minor changes --- .../DatabasePreconditionFailedException.java | 2 +- .../PolarisConnectorDatabaseService.java | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/metacat-common-server/src/main/java/com/netflix/metacat/common/server/connectors/exception/DatabasePreconditionFailedException.java b/metacat-common-server/src/main/java/com/netflix/metacat/common/server/connectors/exception/DatabasePreconditionFailedException.java index 54b153ffe..7feb99269 100644 --- a/metacat-common-server/src/main/java/com/netflix/metacat/common/server/connectors/exception/DatabasePreconditionFailedException.java +++ b/metacat-common-server/src/main/java/com/netflix/metacat/common/server/connectors/exception/DatabasePreconditionFailedException.java @@ -41,7 +41,7 @@ public class DatabasePreconditionFailedException extends ConnectorException { public DatabasePreconditionFailedException(final QualifiedName name, @Nullable final String message, @Nullable final Throwable error) { - super(String.format("Precondition failed to update table %s. %s", name, message), error); + super(String.format("Precondition failed to update database %s. %s", name, message), error); } } 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 33bffce22..0951a59d3 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,9 @@ 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.exception.TablePreconditionFailedException; import com.netflix.metacat.common.server.connectors.model.DatabaseInfo; import com.netflix.metacat.connector.polaris.common.PolarisUtils; import com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper; @@ -20,6 +22,7 @@ import org.springframework.dao.DataIntegrityViolationException; import javax.annotation.Nullable; +import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -87,19 +90,23 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na try { this.polarisStoreService.deleteDatabase(name.getDatabaseName()); } catch (DataIntegrityViolationException exception) { -// if (exception.getCause() instanceof ConstraintViolationException) { -// throw new DatabasePreconditionFailedException( -// name, -// String.format("Cannot delete database %s because it is not empty.", name.getDatabaseName()), -// exception -// ); -// } + String message = exception.getMessage(); + if (message.contains("violates foreign key constraint") || + (exception.getCause() instanceof SQLException && + "23503".equals(((SQLException) exception.getCause()).getSQLState()))) { + // Log the specific constraint violation details + String errorMessage = String.format( + "Failed to delete database %s due to foreign key constraint violation. " + + "Ensure all dependent tables are removed first. Error: %s", + name, message + ); + throw new DatabasePreconditionFailedException(name, errorMessage, exception); + } throw new InvalidMetaException(name, exception); } catch (Exception exception) { throw new ConnectorException( String.format("Failed deleting polaris database %s", name), exception); } - System.out.println("DID NOT CATCH THE DB DELETE ERROR"); } /** From 60f2522039c0889a4f9571eb072850b3c594516d Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 03:14:06 -0800 Subject: [PATCH 26/41] minor changes --- .../connector/polaris/PolarisConnectorDatabaseService.java | 1 - 1 file changed, 1 deletion(-) 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 0951a59d3..16fee2a78 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 @@ -12,7 +12,6 @@ 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.exception.TablePreconditionFailedException; import com.netflix.metacat.common.server.connectors.model.DatabaseInfo; import com.netflix.metacat.connector.polaris.common.PolarisUtils; import com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper; From 6d5c38245beb4b925ba30693696f430317d97dd8 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 03:20:17 -0800 Subject: [PATCH 27/41] minor changes --- .../polaris/PolarisConnectorDatabaseService.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 16fee2a78..f63c56238 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 @@ -90,13 +90,13 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na this.polarisStoreService.deleteDatabase(name.getDatabaseName()); } catch (DataIntegrityViolationException exception) { String message = exception.getMessage(); - if (message.contains("violates foreign key constraint") || - (exception.getCause() instanceof SQLException && - "23503".equals(((SQLException) exception.getCause()).getSQLState()))) { - // Log the specific constraint violation details - String errorMessage = String.format( - "Failed to delete database %s due to foreign key constraint violation. " + - "Ensure all dependent tables are removed first. Error: %s", + if (message.contains("violates foreign key constraint") + || (exception.getCause() instanceof SQLException + && "23503".equals(((SQLException) exception.getCause()).getSQLState()))) { + + final String errorMessage = String.format( + "Failed to delete database %s due to foreign key constraint violation. " + + "Ensure all dependent tables are removed first. Error: %s", name, message ); throw new DatabasePreconditionFailedException(name, errorMessage, exception); @@ -177,7 +177,7 @@ public List listNames( try { final String dbPrefix = prefix == null ? "" : prefix.getDatabaseName(); final List qualifiedNames = polarisStoreService.getDatabaseNames( - dbPrefix, sort, this.connectorContext.getConfig().getListDatabaseNamesPageSize()) + dbPrefix, sort, this.connectorContext.getConfig().getListDatabaseNamesPageSize()) .stream() .map(dbName -> QualifiedName.ofDatabase(name.getCatalogName(), dbName)) .collect(Collectors.toCollection(ArrayList::new)); From fdb9a143af2b4047150568edcf6fb4b7a359fc54 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 03:25:28 -0800 Subject: [PATCH 28/41] minor changes --- .../connector/polaris/PolarisConnectorDatabaseService.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 f63c56238..8b5b5eddc 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 @@ -89,15 +89,14 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na try { this.polarisStoreService.deleteDatabase(name.getDatabaseName()); } catch (DataIntegrityViolationException exception) { - String message = exception.getMessage(); - if (message.contains("violates foreign key constraint") + if (exception.getMessage().contains("violates foreign key constraint") || (exception.getCause() instanceof SQLException && "23503".equals(((SQLException) exception.getCause()).getSQLState()))) { final String errorMessage = String.format( "Failed to delete database %s due to foreign key constraint violation. " + "Ensure all dependent tables are removed first. Error: %s", - name, message + name, exception.getMessage() ); throw new DatabasePreconditionFailedException(name, errorMessage, exception); } From c75b3adf059d9a30c1059391adf8ca059505246e Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 03:52:51 -0800 Subject: [PATCH 29/41] minor changes --- .../polaris/PolarisConnectorDatabaseServiceTest.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 787b5ddbc..e05c30e46 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 @@ -84,7 +84,13 @@ 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()); + new DefaultConfigImpl( + new MetacatProperties(null) + ), + new NoopRegistry(), + null, + Maps.newHashMap() + ); polarisDBService = new PolarisConnectorDatabaseService(polarisStoreService, connectorContext); polarisTableService = new PolarisConnectorTableService( @@ -202,7 +208,8 @@ public void testDeleteDb() { public void testDeleteDbNoCascades() { Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); - final QualifiedName qualifiedName = QualifiedName.ofTable(CATALOG_NAME, DB1_QUALIFIED_NAME.getDatabaseName(), "table1"); + 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")) From ae6f57f272f317cdd7e34918c23b45fd57a57509 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 03:59:18 -0800 Subject: [PATCH 30/41] comment out catch --- .../PolarisConnectorDatabaseService.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 8b5b5eddc..2a76a342e 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 @@ -89,17 +89,17 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na try { this.polarisStoreService.deleteDatabase(name.getDatabaseName()); } catch (DataIntegrityViolationException exception) { - if (exception.getMessage().contains("violates foreign key constraint") - || (exception.getCause() instanceof SQLException - && "23503".equals(((SQLException) exception.getCause()).getSQLState()))) { - - final String errorMessage = String.format( - "Failed to delete database %s due to foreign key constraint violation. " - + "Ensure all dependent tables are removed first. Error: %s", - name, exception.getMessage() - ); - throw new DatabasePreconditionFailedException(name, errorMessage, exception); - } +// if (exception.getMessage().contains("violates foreign key constraint") +// || (exception.getCause() instanceof SQLException +// && "23503".equals(((SQLException) exception.getCause()).getSQLState()))) { +// +// final String errorMessage = String.format( +// "Failed to delete database %s due to foreign key constraint violation. " +// + "Ensure all dependent tables are removed first. Error: %s", +// name, exception.getMessage() +// ); +// throw new DatabasePreconditionFailedException(name, errorMessage, exception); +// } throw new InvalidMetaException(name, exception); } catch (Exception exception) { throw new ConnectorException( From d5c33c21a30171c052e4070e9f6d5916771cb78e Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 04:06:13 -0800 Subject: [PATCH 31/41] comment out catch --- .../connector/polaris/PolarisConnectorDatabaseService.java | 2 -- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) 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 2a76a342e..c94663fdc 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; @@ -21,7 +20,6 @@ import org.springframework.dao.DataIntegrityViolationException; import javax.annotation.Nullable; -import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; 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 e05c30e46..555c11316 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 @@ -7,6 +7,7 @@ import com.netflix.metacat.common.server.connectors.ConnectorRequestContext; 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.InvalidMetaException; 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; @@ -219,7 +220,7 @@ public void testDeleteDbNoCascades() { polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); - Assertions.assertThrows(DataIntegrityViolationException.class, () -> + Assertions.assertThrows(InvalidMetaException.class, () -> polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); Assert.assertTrue(polarisDBService.exists(requestContext, qualifiedName)); } From eb95f84cd34d2cea180b12a8ec79976bb4f08c07 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 04:13:14 -0800 Subject: [PATCH 32/41] comment out catch --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 1 - 1 file changed, 1 deletion(-) 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 555c11316..163ad3ab5 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 @@ -34,7 +34,6 @@ 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; From 231aa96838d39408c42a9172db8ce923557273c4 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Wed, 4 Dec 2024 11:09:58 -0800 Subject: [PATCH 33/41] final supposed structure --- .../PolarisConnectorDatabaseService.java | 24 ++++++++++--------- .../PolarisConnectorDatabaseServiceTest.java | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) 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 c94663fdc..8b5b5eddc 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,6 +10,7 @@ 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; @@ -20,6 +21,7 @@ import org.springframework.dao.DataIntegrityViolationException; import javax.annotation.Nullable; +import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -87,17 +89,17 @@ public void delete(final ConnectorRequestContext context, final QualifiedName na try { this.polarisStoreService.deleteDatabase(name.getDatabaseName()); } catch (DataIntegrityViolationException exception) { -// if (exception.getMessage().contains("violates foreign key constraint") -// || (exception.getCause() instanceof SQLException -// && "23503".equals(((SQLException) exception.getCause()).getSQLState()))) { -// -// final String errorMessage = String.format( -// "Failed to delete database %s due to foreign key constraint violation. " -// + "Ensure all dependent tables are removed first. Error: %s", -// name, exception.getMessage() -// ); -// throw new DatabasePreconditionFailedException(name, errorMessage, exception); -// } + if (exception.getMessage().contains("violates foreign key constraint") + || (exception.getCause() instanceof SQLException + && "23503".equals(((SQLException) exception.getCause()).getSQLState()))) { + + final String errorMessage = String.format( + "Failed to delete database %s due to foreign key constraint violation. " + + "Ensure all dependent tables are removed first. Error: %s", + name, exception.getMessage() + ); + throw new DatabasePreconditionFailedException(name, errorMessage, 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 163ad3ab5..f639a8538 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 @@ -81,8 +81,6 @@ public class PolarisConnectorDatabaseServiceTest { */ @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) @@ -206,6 +204,8 @@ public void testDeleteDb() { @Test public void testDeleteDbNoCascades() { + final DatabaseInfo info = DatabaseInfo.builder().name(DB1_QUALIFIED_NAME).build(); + polarisDBService.create(requestContext, info); Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); final QualifiedName qualifiedName = QualifiedName.ofTable( From 94ccd3d8a11302036b41f348cae79d81fe948244 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Fri, 6 Dec 2024 22:49:30 -0800 Subject: [PATCH 34/41] check if table still exists after db deletion --- .../polaris/PolarisConnectorDatabaseServiceTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 f639a8538..f9a3034be 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 @@ -219,8 +219,10 @@ public void testDeleteDbNoCascades() { polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); - Assertions.assertThrows(InvalidMetaException.class, () -> - polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); - Assert.assertTrue(polarisDBService.exists(requestContext, qualifiedName)); +// Assertions.assertThrows(InvalidMetaException.class, () -> +// polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); + Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); + Assert.assertFalse(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); + } } From 9c137dcaf4971c5edc14143bdbb7545f83f79a51 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Fri, 6 Dec 2024 22:54:13 -0800 Subject: [PATCH 35/41] check if table still exists after db deletion --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 1 - 1 file changed, 1 deletion(-) 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 f9a3034be..96f66fe6f 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 @@ -7,7 +7,6 @@ import com.netflix.metacat.common.server.connectors.ConnectorRequestContext; 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.InvalidMetaException; 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; From 41d021a5d4a84f4bac52e9cea245293dc179ce09 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Fri, 6 Dec 2024 23:02:29 -0800 Subject: [PATCH 36/41] check if table exist and db exists after db delete was blocked --- .../polaris/PolarisConnectorDatabaseServiceTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 96f66fe6f..b988fcc0d 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 @@ -7,6 +7,7 @@ import com.netflix.metacat.common.server.connectors.ConnectorRequestContext; 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.InvalidMetaException; 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; @@ -218,10 +219,11 @@ public void testDeleteDbNoCascades() { polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); -// Assertions.assertThrows(InvalidMetaException.class, () -> -// polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); + Assertions.assertThrows(InvalidMetaException.class, () -> + polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); + Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); - Assert.assertFalse(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); + Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); } } From 7ee77fe1cabdb820a9a2be304ec51e2461798f19 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Sat, 7 Dec 2024 12:17:13 -0800 Subject: [PATCH 37/41] check if table exist and db exists after db delete was blocked --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 2 -- 1 file changed, 2 deletions(-) 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 b988fcc0d..fb6e88f6b 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 @@ -217,8 +217,6 @@ public void testDeleteDbNoCascades() { polarisTableService.create(requestContext, tableInfo); Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); - polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); - Assertions.assertThrows(InvalidMetaException.class, () -> polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); From 839599cc5816d2d01dca23980d056749a34531fb Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Sat, 7 Dec 2024 12:23:28 -0800 Subject: [PATCH 38/41] check if table exist and db exists after db delete was blocked --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 fb6e88f6b..08a16a38d 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 @@ -217,8 +217,7 @@ public void testDeleteDbNoCascades() { polarisTableService.create(requestContext, tableInfo); Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); - Assertions.assertThrows(InvalidMetaException.class, () -> - polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME)); + polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); From ef7db85478810ffa108b908015ec1a5770309e0a Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Sat, 7 Dec 2024 12:29:47 -0800 Subject: [PATCH 39/41] checkstyle: check if table exist and db exists after db delete was blocked --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 1 - 1 file changed, 1 deletion(-) 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 08a16a38d..d54900f6b 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 @@ -7,7 +7,6 @@ import com.netflix.metacat.common.server.connectors.ConnectorRequestContext; 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.InvalidMetaException; 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; From bfc6da8a97026b33962cb5ddcd0f9e9b1b18b036 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Sat, 7 Dec 2024 12:42:27 -0800 Subject: [PATCH 40/41] print: check if table exist and db exists after db delete was blocked --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 2 ++ 1 file changed, 2 insertions(+) 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 d54900f6b..7b79db078 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 @@ -219,6 +219,8 @@ public void testDeleteDbNoCascades() { polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); + System.out.println("testDeleteDbNoCascades Table: "); + System.out.println(polarisTableService.get(requestContext, qualifiedName)); Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); } From 81d3fc471f81512bde661248001bb1da2c224645 Mon Sep 17 00:00:00 2001 From: Giorgio Trettenero Date: Sat, 7 Dec 2024 12:54:32 -0800 Subject: [PATCH 41/41] check reproduceable: check if table exist and db exists after db delete was blocked --- .../connector/polaris/PolarisConnectorDatabaseServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7b79db078..5011e0b2b 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 @@ -219,7 +219,7 @@ public void testDeleteDbNoCascades() { polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); Assert.assertTrue(polarisTableService.exists(requestContext, qualifiedName)); - System.out.println("testDeleteDbNoCascades Table: "); + System.out.println("testDeleteDbNoCascades Table:"); System.out.println(polarisTableService.get(requestContext, qualifiedName)); Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME));