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 @@ -74,10 +74,11 @@ public class IcebergCatalogPropertiesMetadata extends BaseCatalogPropertiesMetad
false /* reserved */),
stringRequiredPropertyEntry(
URI, "Iceberg catalog uri config", false /* immutable */, false /* hidden */),
stringRequiredPropertyEntry(
stringOptionalPropertyEntry(
WAREHOUSE,
"Iceberg catalog warehouse config",
false /* immutable */,
null, /* defaultValue */

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.

We could have prevented this kind of obvious errors if we apply a stricter coding style.
Can you help also wrap line 76?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup

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.

Looks like that this is not updated yet?

false /* hidden */),
stringOptionalPropertyEntry(
IcebergConstants.IO_IMPL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,51 @@ void testCatalogProperty() {
throwable.getMessage().contains(IcebergCatalogPropertiesMetadata.CATALOG_BACKEND));
}
}

@Test
void testCatalogInstanciation() {
AuditInfo auditInfo =
AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build();

CatalogEntity entity =
CatalogEntity.builder()
.withId(1L)
.withName("catalog")
.withNamespace(Namespace.of("metalake"))
.withType(IcebergCatalog.Type.RELATIONAL)
.withProvider("iceberg")
.withAuditInfo(auditInfo)
.build();

Map<String, String> conf = Maps.newHashMap();

try (IcebergCatalogOperations ops = new IcebergCatalogOperations()) {
ops.initialize(conf, entity.toCatalogInfo(), ICEBERG_PROPERTIES_METADATA);
Map<String, String> map1 = Maps.newHashMap();
map1.put(IcebergCatalogPropertiesMetadata.CATALOG_BACKEND, "test");
PropertiesMetadata metadata = ICEBERG_PROPERTIES_METADATA.catalogPropertiesMetadata();
Assertions.assertThrows(
IllegalArgumentException.class,
() -> {
PropertiesMetadataHelpers.validatePropertyForCreate(metadata, map1);
});

Map<String, String> map2 = Maps.newHashMap();
map2.put(IcebergCatalogPropertiesMetadata.CATALOG_BACKEND, "rest");
map2.put(IcebergCatalogPropertiesMetadata.URI, "127.0.0.1");
Assertions.assertDoesNotThrow(
() -> {
PropertiesMetadataHelpers.validatePropertyForCreate(metadata, map2);
});

Map<String, String> map3 = Maps.newHashMap();
Throwable throwable =
Assertions.assertThrows(
IllegalArgumentException.class,
() -> PropertiesMetadataHelpers.validatePropertyForCreate(metadata, map3));

Assertions.assertTrue(
throwable.getMessage().contains(IcebergCatalogPropertiesMetadata.CATALOG_BACKEND));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class IcebergConfig extends Config implements OverwriteDefaultConfig {
.doc("Warehouse directory of catalog")
.version(ConfigConstants.VERSION_0_2_0)
.stringConf()
.checkValue(StringUtils::isNotBlank, ConfigConstants.NOT_BLANK_ERROR_MSG)
.create();

public static final ConfigEntry<String> CATALOG_URI =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.function.Supplier;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
import org.apache.gravitino.iceberg.common.IcebergCatalogBackend;
import org.apache.gravitino.iceberg.common.IcebergConfig;
Expand Down Expand Up @@ -82,9 +83,14 @@ public IcebergCatalogWrapper(IcebergConfig icebergConfig) {
this.catalogBackend =
IcebergCatalogBackend.valueOf(
icebergConfig.get(IcebergConfig.CATALOG_BACKEND).toUpperCase(Locale.ROOT));
if (!IcebergCatalogBackend.MEMORY.equals(catalogBackend)) {
if (!IcebergCatalogBackend.MEMORY.equals(catalogBackend)
&& !IcebergCatalogBackend.REST.equals(catalogBackend)) {
// check whether IcebergConfig.CATALOG_WAREHOUSE exists
icebergConfig.get(IcebergConfig.CATALOG_WAREHOUSE);
if (StringUtils.isBlank(icebergConfig.get(IcebergConfig.CATALOG_WAREHOUSE))) {
throw new IllegalArgumentException("The 'warehouse' parameter must have a value.");
}
}
if (!IcebergCatalogBackend.MEMORY.equals(catalogBackend)) {
this.catalogUri = icebergConfig.get(IcebergConfig.CATALOG_URI);
}
this.catalog = IcebergCatalogUtil.loadCatalogBackend(catalogBackend, icebergConfig);
Expand Down