diff --git a/polaris-core/src/main/java/org/apache/polaris/core/entity/CatalogEntity.java b/polaris-core/src/main/java/org/apache/polaris/core/entity/CatalogEntity.java index 99d8557f0b4..53097a61169 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/entity/CatalogEntity.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/entity/CatalogEntity.java @@ -106,25 +106,25 @@ public Catalog asCatalog() { CatalogProperties.builder(propertiesMap.get(DEFAULT_BASE_LOCATION_KEY)) .putAll(propertiesMap) .build(); - return catalogType == Catalog.TypeEnum.INTERNAL - ? PolarisCatalog.builder() - .setType(Catalog.TypeEnum.INTERNAL) + return catalogType == Catalog.TypeEnum.EXTERNAL + ? ExternalCatalog.builder() + .setType(Catalog.TypeEnum.EXTERNAL) .setName(getName()) .setProperties(catalogProps) .setCreateTimestamp(getCreateTimestamp()) .setLastUpdateTimestamp(getLastUpdateTimestamp()) .setEntityVersion(getEntityVersion()) .setStorageConfigInfo(getStorageInfo(internalProperties)) + .setConnectionConfigInfo(getConnectionInfo(internalProperties)) .build() - : ExternalCatalog.builder() - .setType(Catalog.TypeEnum.EXTERNAL) + : PolarisCatalog.builder() + .setType(Catalog.TypeEnum.INTERNAL) .setName(getName()) .setProperties(catalogProps) .setCreateTimestamp(getCreateTimestamp()) .setLastUpdateTimestamp(getLastUpdateTimestamp()) .setEntityVersion(getEntityVersion()) .setStorageConfigInfo(getStorageInfo(internalProperties)) - .setConnectionConfigInfo(getConnectionInfo(internalProperties)) .build(); } diff --git a/runtime/service/src/test/java/org/apache/polaris/service/quarkus/entity/CatalogEntityTest.java b/runtime/service/src/test/java/org/apache/polaris/service/quarkus/entity/CatalogEntityTest.java index aa477d0ac25..8fb591369e8 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/quarkus/entity/CatalogEntityTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/quarkus/entity/CatalogEntityTest.java @@ -266,4 +266,72 @@ public void testInvalidArn(String roleArn) { .isInstanceOf(IllegalArgumentException.class) .hasMessage(expectedMessage); } + + @Test + public void testCatalogTypeDefaultsToInternal() { + String baseLocation = "s3://test-bucket/path"; + AwsStorageConfigInfo storageConfigModel = + AwsStorageConfigInfo.builder() + .setRoleArn("arn:aws:iam::012345678901:role/test-role") + .setExternalId("externalId") + .setUserArn("aws::a:user:arn") + .setStorageType(StorageConfigInfo.StorageTypeEnum.S3) + .setAllowedLocations(List.of(baseLocation)) + .build(); + CatalogEntity catalogEntity = + new CatalogEntity.Builder() + .setName("test-catalog") + .setDefaultBaseLocation(baseLocation) + .setStorageConfigurationInfo(callContext, storageConfigModel, baseLocation) + .build(); + + Catalog catalog = catalogEntity.asCatalog(); + Assertions.assertThat(catalog.getType()).isEqualTo(Catalog.TypeEnum.INTERNAL); + } + + @Test + public void testCatalogTypeExternalPreserved() { + String baseLocation = "s3://test-bucket/path"; + AwsStorageConfigInfo storageConfigModel = + AwsStorageConfigInfo.builder() + .setRoleArn("arn:aws:iam::012345678901:role/test-role") + .setExternalId("externalId") + .setUserArn("aws::a:user:arn") + .setStorageType(StorageConfigInfo.StorageTypeEnum.S3) + .setAllowedLocations(List.of(baseLocation)) + .build(); + CatalogEntity catalogEntity = + new CatalogEntity.Builder() + .setName("test-external-catalog") + .setDefaultBaseLocation(baseLocation) + .setCatalogType(Catalog.TypeEnum.EXTERNAL.name()) + .setStorageConfigurationInfo(callContext, storageConfigModel, baseLocation) + .build(); + + Catalog catalog = catalogEntity.asCatalog(); + Assertions.assertThat(catalog.getType()).isEqualTo(Catalog.TypeEnum.EXTERNAL); + } + + @Test + public void testCatalogTypeInternalExplicitlySet() { + String baseLocation = "s3://test-bucket/path"; + AwsStorageConfigInfo storageConfigModel = + AwsStorageConfigInfo.builder() + .setRoleArn("arn:aws:iam::012345678901:role/test-role") + .setExternalId("externalId") + .setUserArn("aws::a:user:arn") + .setStorageType(StorageConfigInfo.StorageTypeEnum.S3) + .setAllowedLocations(List.of(baseLocation)) + .build(); + CatalogEntity catalogEntity = + new CatalogEntity.Builder() + .setName("test-internal-catalog") + .setDefaultBaseLocation(baseLocation) + .setCatalogType(Catalog.TypeEnum.INTERNAL.name()) + .setStorageConfigurationInfo(callContext, storageConfigModel, baseLocation) + .build(); + + Catalog catalog = catalogEntity.asCatalog(); + Assertions.assertThat(catalog.getType()).isEqualTo(Catalog.TypeEnum.INTERNAL); + } }