Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#415] feat(core, server, catalogs): Add property validation logic for catalog (#452)

Qi Yu7b187a0960ee
diff --git a/build.gradle.kts b/build.gradle.kts
index 043dc3b712..aff3c15af0 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -127,6 +127,7 @@ tasks.rat {
// Ignore files we track but do not distribute
"**/.github/**/*",
"dev/docker/**/*.xml",
+ "**/*.log",
)
// Add .gitignore excludes to the Apache Rat exclusion list.
diff --git a/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java b/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java
index 9023f2a855..3c0c3724ca 100644
--- a/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java
+++ b/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java
@@ -32,6 +32,7 @@ import com.datastrato.graviton.rel.transforms.Transform;
import com.datastrato.graviton.rel.transforms.Transforms;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
import java.io.IOException;
import java.time.Instant;
import java.util.Arrays;
@@ -742,4 +743,10 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemas
public PropertiesMetadata tablePropertiesMetadata() throws UnsupportedOperationException {
return tablePropertiesMetadata;
}
+
+ @Override
+ public PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException {
+ // TODO(yuqi): We will implement this in next PR
+ return Maps::newHashMap;
+ }
}
diff --git a/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveTablePropertiesMetadata.java b/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveTablePropertiesMetadata.java
index 175e7cc17d..9bba53bc3f 100644
--- a/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveTablePropertiesMetadata.java
+++ b/catalogs/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveTablePropertiesMetadata.java
@@ -4,14 +4,14 @@
*/
package com.datastrato.graviton.catalog.hive;
+import com.datastrato.graviton.catalog.BasePropertiesMetadata;
import com.datastrato.graviton.catalog.PropertyEntry;
-import com.datastrato.graviton.catalog.TablePropertiesMetadata;
import com.google.common.collect.Maps;
import java.util.Map;
-public class HiveTablePropertiesMetadata extends TablePropertiesMetadata {
+public class HiveTablePropertiesMetadata extends BasePropertiesMetadata {
@Override
- protected Map<String, PropertyEntry<?>> tablePropertyEntries() {
+ protected Map<String, PropertyEntry<?>> specificPropertyEntries() {
// TODO(Minghuang): support Hive table property specs
return Maps.newHashMap();
}
diff --git a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/IcebergCatalogOperations.java b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/IcebergCatalogOperations.java
index 30d39750e7..61a4876ac0 100644
--- a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/IcebergCatalogOperations.java
+++ b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/IcebergCatalogOperations.java
@@ -29,6 +29,7 @@ import com.datastrato.graviton.rel.TableChange;
import com.datastrato.graviton.rel.transforms.Transform;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
@@ -384,4 +385,9 @@ public class IcebergCatalogOperations implements CatalogOperations, SupportsSche
public PropertiesMetadata tablePropertiesMetadata() throws UnsupportedOperationException {
return tablePropertiesMetadata;
}
+
+ @Override
+ public PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException {
+ return Maps::newHashMap;
+ }
}
diff --git a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/IcebergTablePropertiesMetadata.java b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/IcebergTablePropertiesMetadata.java
index b86eaee6ec..3c107f75e1 100644
--- a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/IcebergTablePropertiesMetadata.java
+++ b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/graviton/catalog/lakehouse/iceberg/IcebergTablePropertiesMetadata.java
@@ -4,14 +4,14 @@
*/
package com.datastrato.graviton.catalog.lakehouse.iceberg;
+import com.datastrato.graviton.catalog.BasePropertiesMetadata;
import com.datastrato.graviton.catalog.PropertyEntry;
-import com.datastrato.graviton.catalog.TablePropertiesMetadata;
import com.google.common.collect.Maps;
import java.util.Map;
-public class IcebergTablePropertiesMetadata extends TablePropertiesMetadata {
+public class IcebergTablePropertiesMetadata extends BasePropertiesMetadata {
@Override
- protected Map<String, PropertyEntry<?>> tablePropertyEntries() {
+ protected Map<String, PropertyEntry<?>> specificPropertyEntries() {
// TODO: support Iceberg table property specs
return Maps.newHashMap();
}
diff --git a/core/src/main/java/com/datastrato/graviton/Entity.java b/core/src/main/java/com/datastrato/graviton/Entity.java
index 74b5f560e1..cad4150d66 100644
--- a/core/src/main/java/com/datastrato/graviton/Entity.java
+++ b/core/src/main/java/com/datastrato/graviton/Entity.java
@@ -22,7 +22,7 @@ public interface Entity extends Serializable {
AUDIT("au", 65534);
- // Short name can be used to identify the entity type in the logs, peristent storage, etc.
+ // Short name can be used to identify the entity type in the logs, persistent storage, etc.
private final String shortName;
private final int index;
diff --git a/core/src/main/java/com/datastrato/graviton/EntityStore.java b/core/src/main/java/com/datastrato/graviton/EntityStore.java
index 7b8a99151d..71c44a72d3 100644
--- a/core/src/main/java/com/datastrato/graviton/EntityStore.java
+++ b/core/src/main/java/com/datastrato/graviton/EntityStore.java
@@ -106,7 +106,7 @@ public interface EntityStore extends Closeable {
* @return E the updated entity
* @throws IOException if the store operation fails
* @throws NoSuchEntityException if the entity does not exist
- * @throws AlreadyExistsException if the updated entity already exitsed.
+ * @throws AlreadyExistsException if the updated entity already existed.
*/
<E extends Entity & HasIdentifier> E update(
NameIdentifier ident, Class<E> type, EntityType entityType, Function<E, E> updater)
@@ -143,7 +143,7 @@ public interface EntityStore extends Closeable {
*
* @param ident the name identifier of the entity
* @param entityType the type of the entity to be deleted
- * @param cascade support cacade detele or not
+ * @param cascade support cascade delete or not
* @return true if the entity exists and is deleted successfully, false otherwise
* @throws IOException if the delete operation fails
*/
diff --git a/core/src/main/java/com/datastrato/graviton/catalog/BaseCatalog.java b/core/src/main/java/com/datastrato/graviton/catalog/BaseCatalog.java
index 024972f1d6..a25a349052 100644
--- a/core/src/main/java/com/datastrato/graviton/catalog/BaseCatalog.java
+++ b/core/src/main/java/com/datastrato/graviton/catalog/BaseCatalog.java
@@ -9,6 +9,7 @@ import com.datastrato.graviton.Catalog;
import com.datastrato.graviton.CatalogProvider;
import com.datastrato.graviton.meta.CatalogEntity;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
import java.util.Map;
/**
@@ -32,6 +33,7 @@ public abstract class BaseCatalog<T extends BaseCatalog>
private volatile CatalogOperations ops;
+ private volatile Map<String, String> properties;
/**
* Creates a new instance of CatalogOperations.
*
@@ -45,6 +47,11 @@ public abstract class BaseCatalog<T extends BaseCatalog>
return ops().tablePropertiesMetadata();
}
+ @Override
+ public PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException {
+ return ops().catalogPropertiesMetadata();
+ }
+
/**
* Retrieves the CatalogOperations instance associated with this catalog. Lazily initializes the
* instance if not already created.
@@ -123,8 +130,19 @@ public abstract class BaseCatalog<T extends BaseCatalog>
@Override
public Map<String, String> properties() {
- Preconditions.checkArgument(entity != null, "entity is not set");
- return entity.getProperties();
+ if (properties == null) {
+ synchronized (this) {
+ if (properties == null) {
+ Preconditions.checkArgument(entity != null, "entity is not set");
+ properties = Maps.newHashMap(entity.getProperties());
+ properties
+ .entrySet()
+ .removeIf(
+ entry -> ops().catalogPropertiesMetadata().isHiddenProperty(entry.getKey()));
+ }
+ }
+ }
+ return properties;
}
@Override
diff --git a/core/src/main/java/com/datastrato/graviton/catalog/TablePropertiesMetadata.java b/core/src/main/java/com/datastrato/graviton/catalog/BasePropertiesMetadata.java
similarity index 60%
rename from core/src/main/java/com/datastrato/graviton/catalog/TablePropertiesMetadata.java
rename to core/src/main/java/com/datastrato/graviton/catalog/BasePropertiesMetadata.java
index a86af23f59..ea1a854a61 100644
--- a/core/src/main/java/com/datastrato/graviton/catalog/TablePropertiesMetadata.java
+++ b/core/src/main/java/com/datastrato/graviton/catalog/BasePropertiesMetadata.java
@@ -13,22 +13,22 @@ import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;
-public abstract class TablePropertiesMetadata implements PropertiesMetadata {
+public abstract class BasePropertiesMetadata implements PropertiesMetadata {
- private static final Map<String, PropertyEntry<?>> BASIC_TABLE_PROPERTY_ENTRIES;
+ private static final Map<String, PropertyEntry<?>> BASIC_PROPERTY_ENTRIES;
- private Map<String, PropertyEntry<?>> propertyEntries;
+ private volatile Map<String, PropertyEntry<?>> propertyEntries;
static {
- List<PropertyEntry<?>> basicTablePropertyEntries =
+ // basicPropertyEntries is shared by all entities
+ List<PropertyEntry<?>> basicPropertyEntries =
ImmutableList.of(
PropertyEntry.stringReservedPropertyEntry(
ID_KEY,
"To differentiate the entities created directly by the underlying sources",
true));
- BASIC_TABLE_PROPERTY_ENTRIES =
- Maps.uniqueIndex(basicTablePropertyEntries, PropertyEntry::getName);
+ BASIC_PROPERTY_ENTRIES = Maps.uniqueIndex(basicPropertyEntries, PropertyEntry::getName);
}
@Override
@@ -37,14 +37,13 @@ public abstract class TablePropertiesMetadata implements PropertiesMetadata {
synchronized (this) {
if (propertyEntries == null) {
ImmutableMap.Builder<String, PropertyEntry<?>> builder = ImmutableMap.builder();
- Map<String, PropertyEntry<?>> catalogTableProperty = tablePropertyEntries();
- builder.putAll(catalogTableProperty);
+ Map<String, PropertyEntry<?>> properties = specificPropertyEntries();
+ builder.putAll(properties);
- BASIC_TABLE_PROPERTY_ENTRIES.forEach(
+ BASIC_PROPERTY_ENTRIES.forEach(
(name, entry) -> {
Preconditions.checkArgument(
- !catalogTableProperty.containsKey(name),
- "Property metadata already exists: " + name);
+ !properties.containsKey(name), "Property metadata already exists: " + name);
builder.put(name, entry);
});
@@ -55,5 +54,5 @@ public abstract class TablePropertiesMetadata implements PropertiesMetadata {
return propertyEntries;
}
- protected abstract Map<String, PropertyEntry<?>> tablePropertyEntries();
+ protected abstract Map<String, PropertyEntry<?>> specificPropertyEntries();
}
diff --git a/core/src/main/java/com/datastrato/graviton/catalog/CatalogManager.java b/core/src/main/java/com/datastrato/graviton/catalog/CatalogManager.java
index 672798bed2..d414c8c732 100644
--- a/core/src/main/java/com/datastrato/graviton/catalog/CatalogManager.java
+++ b/core/src/main/java/com/datastrato/graviton/catalog/CatalogManager.java
@@ -6,6 +6,8 @@ package com.datastrato.graviton.catalog;
import com.datastrato.graviton.Catalog;
import com.datastrato.graviton.CatalogChange;
+import com.datastrato.graviton.CatalogChange.RemoveProperty;
+import com.datastrato.graviton.CatalogChange.SetProperty;
import com.datastrato.graviton.CatalogProvider;
import com.datastrato.graviton.Config;
import com.datastrato.graviton.Configs;
@@ -40,6 +42,7 @@ import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.time.Instant;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -49,6 +52,7 @@ import java.util.ServiceLoader;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
+import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -210,7 +214,8 @@ public class CatalogManager implements SupportsCatalogs, Closeable {
*/
@Override
public Catalog loadCatalog(NameIdentifier ident) throws NoSuchCatalogException {
- return loadCatalogAndWrap(ident).catalog;
+ CatalogWrapper wrapper = loadCatalogInternal(ident);
+ return wrapper.catalog;
}
/**
@@ -266,18 +271,44 @@ public class CatalogManager implements SupportsCatalogs, Closeable {
store.put(e, false /* overwrite */);
return e;
});
- return catalogCache.get(ident, id -> createCatalogWrapper(entity)).catalog;
-
- } catch (EntityAlreadyExistsException ee) {
- LOG.warn("Catalog {} already exists", ident, ee);
+ CatalogWrapper wrapper = catalogCache.get(ident, id -> createCatalogWrapper(entity));
+ wrapper.doWithPropertiesMeta(
+ f -> {
+ f.catalogPropertiesMetadata().validatePropertyForCreate(properties);
+ return null;
+ });
+ return wrapper.catalog;
+ } catch (EntityAlreadyExistsException e1) {
+ LOG.warn("Catalog {} already exists", ident, e1);
throw new CatalogAlreadyExistsException("Catalog " + ident + " already exists");
-
- } catch (IOException ioe) {
- LOG.error("Failed to create catalog {}", ident, ioe);
- throw new RuntimeException(ioe);
+ } catch (IllegalArgumentException | NoSuchMetalakeException e2) {
+ throw e2;
+ } catch (Exception e3) {
+ LOG.error("Failed to create catalog {}", ident, e3);
+ throw new RuntimeException(e3);
}
}
+ private Pair<Map<String, String>, Map<String, String>> getCatalogAlterProperty(
+ CatalogChange... catalogChanges) {
+ Map<String, String> upserts = Maps.newHashMap();
+ Map<String, String> deletes = Maps.newHashMap();
+
+ Arrays.stream(catalogChanges)
+ .forEach(
+ tableChange -> {
+ if (tableChange instanceof SetProperty) {
+ SetProperty setProperty = (SetProperty) tableChange;
+ upserts.put(setProperty.getProperty(), setProperty.getValue());
+ } else if (tableChange instanceof RemoveProperty) {
+ RemoveProperty removeProperty = (RemoveProperty) tableChange;
+ deletes.put(removeProperty.getProperty(), removeProperty.getProperty());
+ }
+ });
+
+ return Pair.of(upserts, deletes);
+ }
+
/**
* Alters an existing catalog with the specified changes.
*
@@ -292,8 +323,29 @@ public class CatalogManager implements SupportsCatalogs, Closeable {
throws NoSuchCatalogException, IllegalArgumentException {
// There could be a race issue that someone is using the catalog from cache while we are
// updating it.
- catalogCache.invalidate(ident);
+
+ CatalogWrapper catalogWrapper = loadCatalogAndWrap(ident);
+ if (catalogWrapper == null) {
+ throw new NoSuchCatalogException("Catalog " + ident + " does not exist");
+ }
+ try {
+ catalogWrapper.doWithPropertiesMeta(
+ f -> {
+ Pair<Map<String, String>, Map<String, String>> alterProperty =
+ getCatalogAlterProperty(changes);
+ f.catalogPropertiesMetadata()
+ .validatePropertyForAlter(alterProperty.getLeft(), alterProperty.getRight());
+ return null;
+ });
+ } catch (IllegalArgumentException e1) {
+ throw e1;
+ } catch (Exception e) {
+ LOG.error("Failed to alter catalog {}", ident, e);
+ throw new RuntimeException(e);
+ }
+
+ catalogCache.invalidate(ident);
try {
CatalogEntity updatedCatalog =
store.update(
@@ -434,7 +486,24 @@ public class CatalogManager implements SupportsCatalogs, Closeable {
// Initialize the catalog
catalog = catalog.withCatalogEntity(entity).withCatalogConf(mergedConf);
- return new CatalogWrapper(catalog, classLoader);
+ CatalogWrapper wrapper = new CatalogWrapper(catalog, classLoader);
+
+ // Call wrapper.catalog.properties() to make BaseCatalog#properties in IsolatedClassLoader
+ // not null. Why we do this? Because wrapper.catalog.properties() need to be called in the
+ // IsolatedClassLoader, it needs to load the specific catalog class such as HiveCatalog or so.
+ // For simply, We will preload the value of properties and thus AppClassLoader can get the
+ // value of properties.
+ try {
+ wrapper.doWithPropertiesMeta(
+ f -> {
+ wrapper.catalog.properties();
+ return null;
+ });
+ } catch (Exception e) {
+ LOG.error("Failed to load catalog '{}' properties", entity.name(), e);
+ throw new RuntimeException(e);
+ }
+ return wrapper;
}
static Map<String, String> mergeConf(Map<String, String> properties, Map<String, String> conf) {
diff --git a/core/src/main/java/com/datastrato/graviton/catalog/CatalogOperationDispatcher.java b/core/src/main/java/com/datastrato/graviton/catalog/CatalogOperationDispatcher.java
index ec21cb7c5a..dcd80d790f 100644
--- a/core/src/main/java/com/datastrato/graviton/catalog/CatalogOperationDispatcher.java
+++ b/core/src/main/java/com/datastrato/graviton/catalog/CatalogOperationDispatcher.java
@@ -34,11 +34,13 @@ import com.datastrato.graviton.rel.SupportsSchemas;
import com.datastrato.graviton.rel.Table;
import com.datastrato.graviton.rel.TableCatalog;
import com.datastrato.graviton.rel.TableChange;
+import com.datastrato.graviton.rel.TableChange.RemoveProperty;
+import com.datastrato.graviton.rel.TableChange.SetProperty;
import com.datastrato.graviton.rel.transforms.Transform;
import com.datastrato.graviton.storage.IdGenerator;
import com.datastrato.graviton.utils.ThrowableFunction;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
@@ -46,6 +48,7 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -348,7 +351,7 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemas
c ->
c.doWithPropertiesMeta(
p -> {
- validateCreateTableProperties(p.tablePropertiesMetadata(), properties);
+ p.tablePropertiesMetadata().validatePropertyForCreate(properties);
return null;
}),
IllegalArgumentException.class);
@@ -402,37 +405,6 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemas
getHiddenPropertyNames(getCatalogIdentifier(ident), table.properties()));
}
- private void validateCreateTableProperties(
- PropertiesMetadata tablePropertiesMetadata, Map<String, String> properties) {
- if (properties == null) {
- return;
- }
-
- List<String> reservedProperties =
- properties.keySet().stream()
- .filter(tablePropertiesMetadata::isReservedProperty)
- .collect(Collectors.toList());
- Preconditions.checkArgument(
- reservedProperties.isEmpty(),
- "Properties are reserved and cannot be set: %s",
- reservedProperties);
-
- List<String> absentProperties =
- tablePropertiesMetadata.propertyEntries().keySet().stream()
- .filter(tablePropertiesMetadata::isRequiredProperty)
- .filter(k -> !properties.containsKey(k))
- .collect(Collectors.toList());
- Preconditions.checkArgument(
- absentProperties.isEmpty(),
- "Properties are required and must be set: %s",
- absentProperties);
-
- // use decode function to validate the property values
- properties.keySet().stream()
- .filter(tablePropertiesMetadata::containsProperty)
- .forEach(k -> tablePropertiesMetadata.propertyEntries().get(k).decode(properties.get(k)));
- }
-
/**
* Alters an existing table.
*
@@ -502,34 +474,36 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemas
getHiddenPropertyNames(getCatalogIdentifier(ident), alteredTable.properties()));
}
+ private Pair<Map<String, String>, Map<String, String>> getTableAlterProperty(
+ TableChange... tableChanges) {
+ Map<String, String> upserts = Maps.newHashMap();
+ Map<String, String> deletes = Maps.newHashMap();
+
+ Arrays.stream(tableChanges)
+ .forEach(
+ tableChange -> {
+ if (tableChange instanceof SetProperty) {
+ SetProperty setProperty = (SetProperty) tableChange;
+ upserts.put(setProperty.getProperty(), setProperty.getValue());
+ } else if (tableChange instanceof RemoveProperty) {
+ RemoveProperty removeProperty = (RemoveProperty) tableChange;
+ deletes.put(removeProperty.getProperty(), removeProperty.getProperty());
+ }
+ });
+
+ return Pair.of(upserts, deletes);
+ }
+
private void validateAlterTableProperties(NameIdentifier ident, TableChange... changes) {
doWithCatalog(
getCatalogIdentifier(ident),
c ->
c.doWithPropertiesMeta(
p -> {
- PropertiesMetadata tablePropertiesMetadata = p.tablePropertiesMetadata();
- for (TableChange change : changes) {
- if (change instanceof TableChange.SetProperty) {
- String propertyName = ((TableChange.SetProperty) change).getProperty();
- if (tablePropertiesMetadata.isReservedProperty(propertyName)
- || tablePropertiesMetadata.isImmutableProperty(propertyName)) {
- throw new IllegalArgumentException(
- String.format(
- "Property %s is reserved or immutable and cannot be set",
- propertyName));
- }
- }
-
- if (change instanceof TableChange.RemoveProperty) {
- String propertyName = ((TableChange.RemoveProperty) change).getProperty();
- if (tablePropertiesMetadata.isReservedProperty(propertyName)
- || tablePropertiesMetadata.isImmutableProperty(propertyName)) {
- throw new IllegalArgumentException(
- String.format("Property %s cannot be removed by user", propertyName));
- }
- }
- }
+ Pair<Map<String, String>, Map<String, String>> alterProperty =
+ getTableAlterProperty(changes);
+ p.tablePropertiesMetadata()
+ .validatePropertyForAlter(alterProperty.getLeft(), alterProperty.getRight());
return null;
}),
IllegalArgumentException.class);
diff --git a/core/src/main/java/com/datastrato/graviton/catalog/HasPropertyMetadata.java b/core/src/main/java/com/datastrato/graviton/catalog/HasPropertyMetadata.java
index ce9dbd41fd..ec691f400e 100644
--- a/core/src/main/java/com/datastrato/graviton/catalog/HasPropertyMetadata.java
+++ b/core/src/main/java/com/datastrato/graviton/catalog/HasPropertyMetadata.java
@@ -4,7 +4,22 @@
*/
package com.datastrato.graviton.catalog;
-/** This interface represents entities that have properties metadata. */
+/** This interface represents entities that have property metadata. */
public interface HasPropertyMetadata {
+
+ /**
+ * Returns the table property metadata.
+ *
+ * @return The table property metadata.
+ * @throws UnsupportedOperationException if the entity does not support table properties.
+ */
PropertiesMetadata tablePropertiesMetadata() throws UnsupportedOperationException;
+
+ /**
+ * Returns the catalog property metadata.
+ *
+ * @return The catalog property metadata.
+ * @throws UnsupportedOperationException if the entity does not support catalog properties.
+ */
+ PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException;
}
diff --git a/core/src/main/java/com/datastrato/graviton/catalog/PropertiesMetadata.java b/core/src/main/java/com/datastrato/graviton/catalog/PropertiesMetadata.java
index e8ccfdddba..be9ae9261d 100644
--- a/core/src/main/java/com/datastrato/graviton/catalog/PropertiesMetadata.java
+++ b/core/src/main/java/com/datastrato/graviton/catalog/PropertiesMetadata.java
@@ -4,7 +4,12 @@
*/
package com.datastrato.graviton.catalog;
+import com.google.common.base.Preconditions;
+import java.util.List;
import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+import java.util.stream.Collectors;
/** The PropertiesMetadata class is responsible for managing property metadata. */
public interface PropertiesMetadata {
@@ -33,4 +38,72 @@ public interface PropertiesMetadata {
default boolean containsProperty(String propertyName) {
return propertyEntries().containsKey(propertyName);
}
+
+ static <T> void checkValueFormat(String key, String value, Function<String, T> decoder) {
+ try {
+ decoder.apply(value);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(
+ String.format("Invalid value: '%s' for property: '%s'", value, key), e);
+ }
+ }
+
+ default void validatePropertyForAlter(Map<String, String> upserts, Map<String, String> deletes) {
+ for (Map.Entry<String, String> entry : upserts.entrySet()) {
+ PropertyEntry<?> propertyEntry = propertyEntries().get(entry.getKey());
+ if (Objects.nonNull(propertyEntry)) {
+ Preconditions.checkArgument(
+ !propertyEntry.isImmutable() && !propertyEntry.isReserved(),
+ "Property " + propertyEntry.getName() + " is immutable or reserved, cannot be set");
+ checkValueFormat(entry.getKey(), entry.getValue(), propertyEntry::decode);
+ }
+ }
+
+ for (Map.Entry<String, String> entry : deletes.entrySet()) {
+ PropertyEntry<?> propertyEntry = propertyEntries().get(entry.getKey());
+ if (Objects.nonNull(propertyEntry)) {
+ Preconditions.checkArgument(
+ !propertyEntry.isImmutable() && !propertyEntry.isReserved(),
+ "Property " + propertyEntry.getName() + " is immutable or reserved, cannot be deleted");
+ }
+ }
+ }
+
+ default void validatePropertyForCreate(Map<String, String> properties)
+ throws IllegalArgumentException {
+ if (properties == null) {
+ return;
+ }
+
+ List<String> reservedProperties =
+ properties.keySet().stream().filter(this::isReservedProperty).collect(Collectors.toList());
+ Preconditions.checkArgument(
+ reservedProperties.isEmpty(),
+ "Properties are reserved and cannot be set: %s",
+ reservedProperties);
+
+ List<String> absentProperties =
+ propertyEntries().keySet().stream()
+ .filter(this::isRequiredProperty)
+ .filter(k -> !properties.containsKey(k))
+ .collect(Collectors.toList());
+ Preconditions.checkArgument(
+ absentProperties.isEmpty(),
+ "Properties are required and must be set: %s",
+ absentProperties);
+
+ // use decode function to validate the property values
+ for (Map.Entry<String, String> entry : properties.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue();
+ if (containsProperty(key)) {
+ try {
+ propertyEntries().get(key).decode(value);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(
+ String.format("Invalid value: '%s' for property: '%s'", value, key));
+ }
+ }
+ }
+ }
}
diff --git a/core/src/main/java/com/datastrato/graviton/storage/kv/KvEntityStore.java b/core/src/main/java/com/datastrato/graviton/storage/kv/KvEntityStore.java
index 18fddaadda..63925171c6 100644
--- a/core/src/main/java/com/datastrato/graviton/storage/kv/KvEntityStore.java
+++ b/core/src/main/java/com/datastrato/graviton/storage/kv/KvEntityStore.java
@@ -254,28 +254,28 @@ public class KvEntityStore implements EntityStore {
*/
private List<byte[]> getSubEntitiesPrefix(NameIdentifier ident, EntityType type)
throws IOException {
- List<byte[]> prefixs = Lists.newArrayList();
+ List<byte[]> prefixes = Lists.newArrayList();
byte[] encode = entityKeyEncoder.encode(ident, type, true);
switch (type) {
case METALAKE:
- prefixs.add(replacePrefixTypeInfo(encode, CATALOG.getShortName()));
- prefixs.add(replacePrefixTypeInfo(encode, SCHEMA.getShortName()));
- prefixs.add(replacePrefixTypeInfo(encode, TABLE.getShortName()));
+ prefixes.add(replacePrefixTypeInfo(encode, CATALOG.getShortName()));
+ prefixes.add(replacePrefixTypeInfo(encode, SCHEMA.getShortName()));
+ prefixes.add(replacePrefixTypeInfo(encode, TABLE.getShortName()));
break;
case CATALOG:
- prefixs.add(replacePrefixTypeInfo(encode, SCHEMA.getShortName()));
- prefixs.add(replacePrefixTypeInfo(encode, TABLE.getShortName()));
+ prefixes.add(replacePrefixTypeInfo(encode, SCHEMA.getShortName()));
+ prefixes.add(replacePrefixTypeInfo(encode, TABLE.getShortName()));
break;
case SCHEMA:
- prefixs.add(replacePrefixTypeInfo(encode, TABLE.getShortName()));
+ prefixes.add(replacePrefixTypeInfo(encode, TABLE.getShortName()));
break;
case TABLE:
break;
default:
LOG.warn("Currently unknown type: {}, please check it", type);
}
- Collections.reverse(prefixs);
- return prefixs;
+ Collections.reverse(prefixes);
+ return prefixes;
}
private byte[] replacePrefixTypeInfo(byte[] encode, String subTypePrefix) {
diff --git a/core/src/test/java/com/datastrato/graviton/TestTablePropertiesMetadata.java b/core/src/test/java/com/datastrato/graviton/TestBasePropertiesMetadata.java
similarity index 71%
rename from core/src/test/java/com/datastrato/graviton/TestTablePropertiesMetadata.java
rename to core/src/test/java/com/datastrato/graviton/TestBasePropertiesMetadata.java
index 4be0f42f1a..6f2236f291 100644
--- a/core/src/test/java/com/datastrato/graviton/TestTablePropertiesMetadata.java
+++ b/core/src/test/java/com/datastrato/graviton/TestBasePropertiesMetadata.java
@@ -4,14 +4,14 @@
*/
package com.datastrato.graviton;
+import com.datastrato.graviton.catalog.BasePropertiesMetadata;
import com.datastrato.graviton.catalog.PropertyEntry;
-import com.datastrato.graviton.catalog.TablePropertiesMetadata;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;
-public class TestTablePropertiesMetadata extends TablePropertiesMetadata {
+public class TestBasePropertiesMetadata extends BasePropertiesMetadata {
public static final String COMMENT_KEY = "comment";
@@ -19,7 +19,7 @@ public class TestTablePropertiesMetadata extends TablePropertiesMetadata {
public static final String TEST_IMMUTABLE_KEY = "immutableKey";
- private static final Map<String, PropertyEntry<?>> TEST_TABLE_PROPERTY;
+ private static final Map<String, PropertyEntry<?>> TEST_BASE_PROPERTY;
static {
List<PropertyEntry<?>> tablePropertyMetadata =
@@ -30,11 +30,11 @@ public class TestTablePropertiesMetadata extends TablePropertiesMetadata {
PropertyEntry.stringImmutablePropertyEntry(
TEST_IMMUTABLE_KEY, "test immutable property", false, null, false, false));
- TEST_TABLE_PROPERTY = Maps.uniqueIndex(tablePropertyMetadata, PropertyEntry::getName);
+ TEST_BASE_PROPERTY = Maps.uniqueIndex(tablePropertyMetadata, PropertyEntry::getName);
}
@Override
- protected Map<String, PropertyEntry<?>> tablePropertyEntries() {
- return TEST_TABLE_PROPERTY;
+ protected Map<String, PropertyEntry<?>> specificPropertyEntries() {
+ return TEST_BASE_PROPERTY;
}
}
diff --git a/core/src/test/java/com/datastrato/graviton/TestCatalog.java b/core/src/test/java/com/datastrato/graviton/TestCatalog.java
index d84172d04b..f25ee6c606 100644
--- a/core/src/test/java/com/datastrato/graviton/TestCatalog.java
+++ b/core/src/test/java/com/datastrato/graviton/TestCatalog.java
@@ -20,7 +20,7 @@ public class TestCatalog extends BaseCatalog<TestCatalog> {
@Override
protected CatalogOperations newOps(Map<String, String> config) {
- return new TestCatalogOperations();
+ return new TestCatalogOperations(config);
}
@Override
diff --git a/core/src/test/java/com/datastrato/graviton/TestCatalogOperations.java b/core/src/test/java/com/datastrato/graviton/TestCatalogOperations.java
index 674b508efc..a04fa59efa 100644
--- a/core/src/test/java/com/datastrato/graviton/TestCatalogOperations.java
+++ b/core/src/test/java/com/datastrato/graviton/TestCatalogOperations.java
@@ -4,9 +4,10 @@
*/
package com.datastrato.graviton;
+import com.datastrato.graviton.catalog.BasePropertiesMetadata;
import com.datastrato.graviton.catalog.CatalogOperations;
import com.datastrato.graviton.catalog.PropertiesMetadata;
-import com.datastrato.graviton.catalog.TablePropertiesMetadata;
+import com.datastrato.graviton.catalog.PropertyEntry;
import com.datastrato.graviton.exceptions.NoSuchCatalogException;
import com.datastrato.graviton.exceptions.NoSuchSchemaException;
import com.datastrato.graviton.exceptions.NoSuchTableException;
@@ -24,6 +25,7 @@ import com.datastrato.graviton.rel.Table;
import com.datastrato.graviton.rel.TableCatalog;
import com.datastrato.graviton.rel.TableChange;
import com.datastrato.graviton.rel.transforms.Transform;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.io.IOException;
import java.time.Instant;
@@ -36,12 +38,14 @@ public class TestCatalogOperations implements CatalogOperations, TableCatalog, S
private final Map<NameIdentifier, TestSchema> schemas;
- private final TablePropertiesMetadata tablePropertiesMetadata;
+ private final BasePropertiesMetadata tablePropertiesMetadata;
+ private Map<String, String> config;
- public TestCatalogOperations() {
+ public TestCatalogOperations(Map<String, String> config) {
tables = Maps.newHashMap();
schemas = Maps.newHashMap();
- tablePropertiesMetadata = new TestTablePropertiesMetadata();
+ tablePropertiesMetadata = new TestBasePropertiesMetadata();
+ this.config = config;
}
@Override
@@ -263,7 +267,7 @@ public class TestCatalogOperations implements CatalogOperations, TableCatalog, S
if (cascade) {
tables.keySet().stream()
.filter(table -> table.namespace().toString().equals(ident.toString()))
- .forEach(table -> tables.remove(table));
+ .forEach(tables::remove);
}
return true;
@@ -273,4 +277,52 @@ public class TestCatalogOperations implements CatalogOperations, TableCatalog, S
public PropertiesMetadata tablePropertiesMetadata() throws UnsupportedOperationException {
return tablePropertiesMetadata;
}
+
+ @Override
+ public PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException {
+ if (config.containsKey("mock")) {
+ return new BasePropertiesMetadata() {
+ @Override
+ protected Map<String, PropertyEntry<?>> specificPropertyEntries() {
+ return ImmutableMap.<String, PropertyEntry<?>>builder()
+ .put(
+ "key1",
+ PropertyEntry.stringPropertyEntry(
+ "key1", "value1", true, true, null, false, false))
+ .put(
+ "key2",
+ PropertyEntry.stringPropertyEntry(
+ "key2", "value2", true, false, null, false, false))
+ .put(
+ "key3",
+ new PropertyEntry.Builder<Integer>()
+ .withDecoder(Integer::parseInt)
+ .withEncoder(Object::toString)
+ .withDefaultValue(1)
+ .withDescription("key3")
+ .withHidden(false)
+ .withReserved(false)
+ .withImmutable(true)
+ .withJavaType(Integer.class)
+ .withRequired(false)
+ .withName("key3")
+ .build())
+ .put(
+ "key4",
+ PropertyEntry.stringPropertyEntry(
+ "key4", "value4", false, false, "value4", false, false))
+ .put(
+ "reserved_key",
+ PropertyEntry.stringPropertyEntry(
+ "reserved_key", "reserved_key", false, true, "reserved_value", false, true))
+ .put(
+ "hidden_key",
+ PropertyEntry.stringPropertyEntry(
+ "hidden_key", "hidden_key", false, false, "hidden_value", true, false))
+ .build();
+ }
+ };
+ }
+ return Maps::newHashMap;
+ }
}
diff --git a/core/src/test/java/com/datastrato/graviton/TestEntityStore.java b/core/src/test/java/com/datastrato/graviton/TestEntityStore.java
index 867b1346ed..d364932acf 100644
--- a/core/src/test/java/com/datastrato/graviton/TestEntityStore.java
+++ b/core/src/test/java/com/datastrato/graviton/TestEntityStore.java
@@ -40,6 +40,10 @@ public class TestEntityStore {
this.lock = new ReentrantLock();
}
+ public void clear() {
+ entityMap.clear();
+ }
+
@Override
public void initialize(Config config) throws RuntimeException {}
diff --git a/core/src/test/java/com/datastrato/graviton/catalog/TestCatalogManager.java b/core/src/test/java/com/datastrato/graviton/catalog/TestCatalogManager.java
index 46b3e23756..470b1b2bd9 100644
--- a/core/src/test/java/com/datastrato/graviton/catalog/TestCatalogManager.java
+++ b/core/src/test/java/com/datastrato/graviton/catalog/TestCatalogManager.java
@@ -4,6 +4,8 @@
*/
package com.datastrato.graviton.catalog;
+import static com.datastrato.graviton.StringIdentifier.ID_KEY;
+
import com.datastrato.graviton.Catalog;
import com.datastrato.graviton.CatalogChange;
import com.datastrato.graviton.Config;
@@ -12,6 +14,7 @@ import com.datastrato.graviton.EntityStore;
import com.datastrato.graviton.NameIdentifier;
import com.datastrato.graviton.StringIdentifier;
import com.datastrato.graviton.TestEntityStore;
+import com.datastrato.graviton.TestEntityStore.InMemoryEntityStore;
import com.datastrato.graviton.exceptions.CatalogAlreadyExistsException;
import com.datastrato.graviton.exceptions.NoSuchCatalogException;
import com.datastrato.graviton.exceptions.NoSuchMetalakeException;
@@ -26,10 +29,17 @@ import java.time.Instant;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.mockito.Mockito;
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TestCatalogManager {
private static CatalogManager catalogManager;
@@ -42,6 +52,15 @@ public class TestCatalogManager {
private static String provider = "test";
+ private static BaseMetalake metalakeEntity =
+ new BaseMetalake.Builder()
+ .withId(1L)
+ .withName(metalake)
+ .withAuditInfo(
+ new AuditInfo.Builder().withCreator("test").withCreateTime(Instant.now()).build())
+ .withVersion(SchemaVersion.V_0_1)
+ .build();
+
@BeforeAll
public static void setUp() throws IOException {
config = new Config(false) {};
@@ -51,17 +70,17 @@ public class TestCatalogManager {
entityStore.initialize(config);
entityStore.setSerDe(null);
- BaseMetalake metalakeEntity =
- new BaseMetalake.Builder()
- .withId(1L)
- .withName(metalake)
- .withAuditInfo(
- new AuditInfo.Builder().withCreator("test").withCreateTime(Instant.now()).build())
- .withVersion(SchemaVersion.V_0_1)
- .build();
entityStore.put(metalakeEntity, true);
catalogManager = new CatalogManager(config, entityStore, new RandomIdGenerator());
+ catalogManager = Mockito.spy(catalogManager);
+ }
+
+ @BeforeEach
+ @AfterEach
+ void reset() throws IOException {
+ ((InMemoryEntityStore) entityStore).clear();
+ entityStore.put(metalakeEntity, true);
}
@AfterAll
@@ -77,6 +96,154 @@ public class TestCatalogManager {
}
}
+ @Test
+ @Order(1)
+ void testLoadTable() throws IOException {
+ NameIdentifier ident = NameIdentifier.of("metalake", "test444");
+ // key1 is required;
+ Map<String, String> props1 =
+ ImmutableMap.<String, String>builder()
+ .put("key2", "value2")
+ .put("key1", "value1")
+ .put("hidden_key", "hidden_value")
+ .put("mock", "mock")
+ .build();
+ Assertions.assertDoesNotThrow(
+ () ->
+ catalogManager.createCatalog(
+ ident, Catalog.Type.RELATIONAL, provider, "comment", props1));
+
+ Map<String, String> properties = catalogManager.loadCatalog(ident).properties();
+ Assertions.assertTrue(properties.containsKey("key2"));
+ Assertions.assertTrue(properties.containsKey("key1"));
+ Assertions.assertFalse(properties.containsKey("hidden_key"));
+ Assertions.assertFalse(properties.containsKey(ID_KEY));
+ reset();
+ }
+
+ @Test
+ @Order(2)
+ void testPropertyValidationInAlter() throws IOException {
+ // key1 is required and immutable and do not have default value, is not hidden and not reserved
+ // key2 is required and mutable and do not have default value, is not hidden and not reserved
+ // key3 is optional and immutable and have default value, is not hidden and not reserved
+ // key4 is optional and mutable and have default value, is not hidden and not reserved
+ // reserved_key is optional and immutable and have default value, is not hidden and reserved
+ // hidden_key is optional and mutable and have default value, is hidden and not reserved
+
+ NameIdentifier ident = NameIdentifier.of("metalake", "test111");
+ // key1 is required;
+ Map<String, String> props1 =
+ ImmutableMap.<String, String>builder()
+ .put("key2", "value2")
+ .put("key1", "value1")
+ .put("mock", "mock")
+ .build();
+ Assertions.assertDoesNotThrow(
+ () ->
+ catalogManager.createCatalog(
+ ident, Catalog.Type.RELATIONAL, provider, "comment", props1));
+
+ NameIdentifier ident2 = NameIdentifier.of("metalake", "test222");
+ // key1 is required;
+ Map<String, String> props2 =
+ ImmutableMap.<String, String>builder()
+ .put("key2", "value2")
+ .put("key1", "value1")
+ .put("key3", "3")
+ .put("key4", "value4")
+ .put("mock", "mock")
+ .build();
+ Assertions.assertDoesNotThrow(
+ () ->
+ catalogManager.createCatalog(
+ ident2, Catalog.Type.RELATIONAL, provider, "comment", props2));
+
+ Exception e1 =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> catalogManager.alterCatalog(ident, CatalogChange.setProperty("key1", "value1")));
+ Assertions.assertTrue(e1.getMessage().contains("Property key1 is immutable"));
+
+ Exception e2 =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> catalogManager.alterCatalog(ident2, CatalogChange.setProperty("key3", "value2")));
+ Assertions.assertTrue(e2.getMessage().contains("Property key3 is immutable"));
+
+ Assertions.assertDoesNotThrow(
+ () -> catalogManager.alterCatalog(ident2, CatalogChange.setProperty("key4", "value4")));
+ Assertions.assertDoesNotThrow(
+ () -> catalogManager.alterCatalog(ident2, CatalogChange.setProperty("key2", "value2")));
+
+ Exception e3 =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ catalogManager.alterCatalog(
+ ident2,
+ CatalogChange.setProperty("key4", "value4"),
+ CatalogChange.removeProperty("key1")));
+ Assertions.assertTrue(e3.getMessage().contains("Property key1 is immutable"));
+ reset();
+ }
+
+ @Test
+ @Order(3)
+ void testPropertyValidationInCreate() throws IOException {
+ // key1 is required and immutable and do not have default value, is not hidden and not reserved
+ // key2 is required and mutable and do not have default value, is not hidden and not reserved
+ // key3 is optional and immutable and have default value, is not hidden and not reserved
+ // key4 is optional and mutable and have default value, is not hidden and not reserved
+ // reserved_key is optional and immutable and have default value, is not hidden and reserved
+ // hidden_key is optional and mutable and have default value, is hidden and not reserved
+ NameIdentifier ident = NameIdentifier.of("metalake", "test111111");
+
+ // key1 is required;
+ Map<String, String> props1 =
+ ImmutableMap.<String, String>builder().put("key2", "value2").put("mock", "mock").build();
+ IllegalArgumentException e1 =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ catalogManager.createCatalog(
+ ident, Catalog.Type.RELATIONAL, provider, "comment", props1));
+ Assertions.assertTrue(
+ e1.getMessage().contains("Properties are required and must be set: [key1]"));
+ // BUG here, in memory does not support rollback
+ reset();
+
+ // key2 is required;
+ Map<String, String> props2 =
+ ImmutableMap.<String, String>builder().put("key1", "value1").put("mock", "mock").build();
+ e1 =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ catalogManager.createCatalog(
+ ident, Catalog.Type.RELATIONAL, provider, "comment", props2));
+ Assertions.assertTrue(
+ e1.getMessage().contains("Properties are required and must be set: [key2]"));
+ reset();
+
+ // key3 is optional, but we assign a wrong value format
+ Map<String, String> props3 =
+ ImmutableMap.<String, String>builder()
+ .put("key1", "value1")
+ .put("key2", "value2")
+ .put("key3", "a12a1a")
+ .put("mock", "mock")
+ .build();
+ e1 =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ catalogManager.createCatalog(
+ ident, Catalog.Type.RELATIONAL, provider, "comment", props3));
+ Assertions.assertTrue(e1.getMessage().contains("Invalid value: 'a12a1a' for property: 'key3'"));
+ reset();
+ }
+
@Test
public void testCreateCatalog() {
NameIdentifier ident = NameIdentifier.of("metalake", "test1");
@@ -232,8 +399,8 @@ public class TestCatalogManager {
Assertions.assertEquals(v, testProps.get(k));
});
- Assertions.assertTrue(testProps.containsKey(StringIdentifier.ID_KEY));
- StringIdentifier StringId = StringIdentifier.fromString(testProps.get(StringIdentifier.ID_KEY));
- Assertions.assertEquals(StringId.toString(), testProps.get(StringIdentifier.ID_KEY));
+ Assertions.assertTrue(testProps.containsKey(ID_KEY));
+ StringIdentifier StringId = StringIdentifier.fromString(testProps.get(ID_KEY));
+ Assertions.assertEquals(StringId.toString(), testProps.get(ID_KEY));
}
}
diff --git a/core/src/test/java/com/datastrato/graviton/catalog/TestCatalogOperationDispatcher.java b/core/src/test/java/com/datastrato/graviton/catalog/TestCatalogOperationDispatcher.java
index e281631acd..0d1fa07d9a 100644
--- a/core/src/test/java/com/datastrato/graviton/catalog/TestCatalogOperationDispatcher.java
+++ b/core/src/test/java/com/datastrato/graviton/catalog/TestCatalogOperationDispatcher.java
@@ -7,7 +7,7 @@ package com.datastrato.graviton.catalog;
import static com.datastrato.graviton.Entity.EntityType.SCHEMA;
import static com.datastrato.graviton.Entity.EntityType.TABLE;
import static com.datastrato.graviton.StringIdentifier.ID_KEY;
-import static com.datastrato.graviton.TestTablePropertiesMetadata.COMMENT_KEY;
+import static com.datastrato.graviton.TestBasePropertiesMetadata.COMMENT_KEY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
@@ -451,7 +451,7 @@ public class TestCatalogOperationDispatcher {
IllegalArgumentException.class,
() -> dispatcher.alterTable(tableIdent, illegalChange1));
Assertions.assertEquals(
- "Property comment is reserved or immutable and cannot be set", exception.getMessage());
+ "Property comment is immutable or reserved, cannot be set", exception.getMessage());
TableChange[] changes =
new TableChange[] {TableChange.setProperty("k3", "v3"), TableChange.removeProperty("k1")};
diff --git a/server/src/test/java/com/datastrato/graviton/server/web/rest/TestCatalog.java b/server/src/test/java/com/datastrato/graviton/server/web/rest/TestCatalog.java
index 4381270a50..b6825f6725 100644
--- a/server/src/test/java/com/datastrato/graviton/server/web/rest/TestCatalog.java
+++ b/server/src/test/java/com/datastrato/graviton/server/web/rest/TestCatalog.java
@@ -7,6 +7,7 @@ package com.datastrato.graviton.server.web.rest;
import com.datastrato.graviton.catalog.BaseCatalog;
import com.datastrato.graviton.catalog.CatalogOperations;
import com.datastrato.graviton.catalog.PropertiesMetadata;
+import com.google.common.collect.Maps;
import java.io.IOException;
import java.util.Map;
@@ -29,6 +30,10 @@ public class TestCatalog extends BaseCatalog<TestCatalog> {
@Override
public void close() throws IOException {}
+
+ public PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException {
+ return Maps::newHashMap;
+ }
};
}
}