Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would it not be easier to fix line 103 instead?

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading