World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#176] update English and JavaDocs in core module (#210)
Justin Mclean522f5b59d145
diff --git a/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.javaindex abfa1a76e0..101fbe5eb2 100644--- a/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java+++ b/catalog-hive/src/main/java/com/datastrato/graviton/catalog/hive/HiveCatalogOperations.java@@ -542,7 +542,7 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemas/*** Not supported in this implementation. Throws UnsupportedOperationException.*- * @param ident The identifier of the table to alter.+ * @param tableIdent The identifier of the table to alter.* @param changes The changes to apply to the table.* @return This method always throws UnsupportedOperationException.* @throws NoSuchTableException This exception will not be thrown in this method.@@ -781,7 +781,7 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemas/*** Checks if the given namespace is a valid namespace for the Hive schema.*- * @param namespace The namespace to validate.+ * @param tableIdent The namespace to validate.* @return true if the namespace is valid; otherwise, false.*/private boolean dropHiveTable(NameIdentifier tableIdent, boolean deleteData, boolean ifPurge) {diff --git a/core/src/main/java/com/datastrato/graviton/Config.java b/core/src/main/java/com/datastrato/graviton/Config.javaindex 72a3872d11..4889c29633 100644--- a/core/src/main/java/com/datastrato/graviton/Config.java+++ b/core/src/main/java/com/datastrato/graviton/Config.java@@ -21,6 +21,7 @@ import java.util.concurrent.ConcurrentMap;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+/** The Config class is responsible for managing configuration settings. */public abstract class Config {private static final Logger LOG = LoggerFactory.getLogger(Config.class);@@ -29,6 +30,11 @@ public abstract class Config {private final ConcurrentMap<String, String> configMap;+ /**+ * Constructs a Config instance.+ *+ * @param loadDefaults Set to true if default configurations should be loaded.+ */public Config(boolean loadDefaults) {configMap = new ConcurrentHashMap<>();if (loadDefaults) {@@ -36,10 +42,18 @@ public abstract class Config {}}+ /** Constructs a Config instance and loads default configurations. */public Config() {this(true);}+ /**+ * Loads configurations from a properties file.+ *+ * @param name The name of the properties file.+ * @return The Config instance.+ * @throws Exception If there's an issue loading the properties.+ */public Config loadFromFile(String name) throws Exception {String confDir =Optional.ofNullable(System.getenv("GRAVITON_CONF_DIR"))@@ -64,6 +78,14 @@ public abstract class Config {return this;}+ /**+ * Gets the value of a configuration entry.+ *+ * @param entry The configuration entry to retrieve.+ * @param <T> The type of the configuration value.+ * @return The value of the configuration entry.+ * @throws NoSuchElementException If the configuration entry is not found.+ */public <T> T get(ConfigEntry<T> entry) throws NoSuchElementException {if (entry.isDeprecated()) {LOG.warn("Config {} is deprecated.", entry.getKey());@@ -75,14 +97,36 @@ public abstract class Config {return entry.readFrom(configMap);}+ /**+ * Retrieves the raw string value associated with the specified configuration key.+ *+ * @param key The configuration key for which the raw string value is requested.+ * @return The raw string value associated with the given configuration key, or null if the key is+ * not found.+ */public String getRawString(String key) {return configMap.get(key);}+ /**+ * Retrieves the raw string value associated with the specified configuration key, providing a+ * default value if the key is not found.+ *+ * @param key The configuration key for which the raw string value is requested.+ * @param defaultValue The default value to be returned if the key is not found.+ * @return The raw string value associated with the given configuration key, or the provided+ * default value if the key is not found.+ */public String getRawString(String key, String defaultValue) {return configMap.getOrDefault(key, defaultValue);}+ /**+ * Retrieves a map containing configuration entries that have keys with the specified prefix.+ *+ * @param prefix The prefix that configuration keys should start with.+ * @return An unmodifiable map containing configuration entries with keys matching the prefix.+ */public Map<String, String> getConfigsWithPrefix(String prefix) {Map<String, String> configs = Maps.newHashMap();configMap.forEach(@@ -96,6 +140,13 @@ public abstract class Config {return Collections.unmodifiableMap(configs);}+ /**+ * Sets the value of a configuration entry.+ *+ * @param entry The configuration entry for which the value needs to be set.+ * @param value The new value to be assigned to the configuration entry.+ * @param <T> The type of the configuration value.+ */public <T> void set(ConfigEntry<T> entry, T value) {if (entry.isDeprecated()) {LOG.warn("Config {} is deprecated.", entry.getKey());@@ -111,6 +162,11 @@ public abstract class Config {entry.writeTo(configMap, value);}+ /**+ * Loads configurations from a map.+ *+ * @param map The map containing configuration key-value pairs.+ */private void loadFromMap(Map<String, String> map) {map.forEach((k, v) -> {@@ -122,11 +178,23 @@ public abstract class Config {});}+ /**+ * Loads configurations from properties.+ *+ * @param properties The properties object containing configuration key-value pairs.+ */@VisibleForTestingvoid loadFromProperties(Properties properties) {loadFromMap(Maps.fromProperties(properties));}+ /**+ * Loads properties from a file.+ *+ * @param file The properties file to load from.+ * @return The loaded properties.+ * @throws IOException If there's an issue loading the properties.+ */@VisibleForTestingProperties loadPropertiesFromFile(File file) throws IOException {Properties properties = new Properties();diff --git a/core/src/main/java/com/datastrato/graviton/Configs.java b/core/src/main/java/com/datastrato/graviton/Configs.javaindex 4bdf178a90..f1582418b9 100644--- a/core/src/main/java/com/datastrato/graviton/Configs.java+++ b/core/src/main/java/com/datastrato/graviton/Configs.java@@ -40,7 +40,7 @@ public interface Configs {ConfigEntry<String> ENTITY_SERDE =new ConfigBuilder("graviton.entity.serde")- .doc("The entity serde to use")+ .doc("The entity SerDe to use").version("0.1.0").stringConf().createWithDefault("proto");diff --git a/core/src/main/java/com/datastrato/graviton/Entity.java b/core/src/main/java/com/datastrato/graviton/Entity.javaindex 3ed005ff20..b44baf81fa 100644--- a/core/src/main/java/com/datastrato/graviton/Entity.java+++ b/core/src/main/java/com/datastrato/graviton/Entity.java@@ -10,7 +10,10 @@ import lombok.AllArgsConstructor;import lombok.Getter;import lombok.ToString;+/** This interface defines an entity within the Graviton framework. */public interface Entity extends Serializable {++ /** Enumeration defining the types of entities in the Graviton framework. */@Getterenum EntityType {METALAKE("ml", 0),@@ -31,34 +34,46 @@ public interface Entity extends Serializable {}}+ /** Class representing an identifier for an entity. */@Getter@AllArgsConstructor@ToString- class EntityIdentifer {+ class EntityIdentifier {private NameIdentifier nameIdentifier;private EntityType entityType;- public static EntityIdentifer of(NameIdentifier name, EntityType entityType) {- return new EntityIdentifer(name, entityType);+ /**+ * Create an instance of EntityIdentifier.+ *+ * @param name The name identifier of the entity.+ * @param entityType The type of the entity.+ * @return The created EntityIdentifier instance.+ */+ public static EntityIdentifier of(NameIdentifier name, EntityType entityType) {+ return new EntityIdentifier(name, entityType);}}/**- * Validates the entity if the field arguments are valid.+ * Validates the entity by ensuring the validity of its field arguments.*- * @throws IllegalArgumentException throws IllegalArgumentException if the validation is failed.+ * @throws IllegalArgumentException If the validation fails.*/default void validate() throws IllegalArgumentException {fields().forEach(Field::validate);}/**- * Returns the schema of the entity with values.+ * Retrieves the fields and their associated values of the entity.*- * @return Map of Field to Object to represent the schema of the entity with values.+ * @return A map of Field to Object representing the entity's schema with values.*/Map<Field, Object> fields();- /** Return type of the entity, plase see {@link EntityType} to see all types */+ /**+ * Retrieves the type of the entity.+ *+ * @return The type of the entity as defined by {@link EntityType}.+ */EntityType type();}diff --git a/core/src/main/java/com/datastrato/graviton/EntityAlreadyExistsException.java b/core/src/main/java/com/datastrato/graviton/EntityAlreadyExistsException.javaindex e2a84fde81..21fa114655 100644--- a/core/src/main/java/com/datastrato/graviton/EntityAlreadyExistsException.java+++ b/core/src/main/java/com/datastrato/graviton/EntityAlreadyExistsException.java@@ -4,11 +4,27 @@*/package com.datastrato.graviton;+/**+ * Exception class indicating that an entity already exists. This exception is thrown when an+ * attempt is made to create an entity that already exists within the Graviton framework.+ */public class EntityAlreadyExistsException extends RuntimeException {++ /**+ * Constructs an EntityAlreadyExistsException.+ *+ * @param message The detail message explaining the exception.+ */public EntityAlreadyExistsException(String message) {super(message);}+ /**+ * Constructs an EntityAlreadyExistsException.+ *+ * @param message The detail message explaining the exception.+ * @param cause The cause of the exception.+ */public EntityAlreadyExistsException(String message, Throwable cause) {super(message, cause);}diff --git a/core/src/main/java/com/datastrato/graviton/EntitySerDeFactory.java b/core/src/main/java/com/datastrato/graviton/EntitySerDeFactory.javaindex f0560c03b8..decdea4b63 100644--- a/core/src/main/java/com/datastrato/graviton/EntitySerDeFactory.java+++ b/core/src/main/java/com/datastrato/graviton/EntitySerDeFactory.java@@ -10,6 +10,11 @@ import java.util.Map;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+/**+ * This class is responsible for creating instances of EntitySerDe implementations. EntitySerDe+ * (Entity Serialization/Deserialization) implementations are used to serialize and deserialize+ * entities within the Graviton framework.+ */public class EntitySerDeFactory {private static final Logger LOG = LoggerFactory.getLogger(EntitySerDe.class);@@ -21,11 +26,24 @@ public class EntitySerDeFactory {private EntitySerDeFactory() {}+ /**+ * Creates an instance of EntitySerDe.+ *+ * @param config The configuration object containing settings for EntitySerDe.+ * @return An instance of EntitySerDe.+ */public static EntitySerDe createEntitySerDe(Config config) {String name = config.get(Configs.ENTITY_SERDE);return createEntitySerDe(name);}+ /**+ * Creates an instance of EntitySerDe.+ *+ * @param name The short name identifying the EntitySerDe implementation.+ * @return An instance of EntitySerDe.+ * @throws RuntimeException If the EntitySerDe creation fails.+ */public static EntitySerDe createEntitySerDe(String name) {String className = ENTITY_SERDES.getOrDefault(name, name);diff --git a/core/src/main/java/com/datastrato/graviton/EntityStoreFactory.java b/core/src/main/java/com/datastrato/graviton/EntityStoreFactory.javaindex 5d9fd57f06..92ab5b3e80 100644--- a/core/src/main/java/com/datastrato/graviton/EntityStoreFactory.java+++ b/core/src/main/java/com/datastrato/graviton/EntityStoreFactory.java@@ -9,6 +9,10 @@ import com.google.common.collect.ImmutableMap;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+/**+ * This class is responsible for creating instances of EntityStore implementations. EntityStore+ * implementations are used to store and manage entities within the Graviton framework.+ */public class EntityStoreFactory {private static final Logger LOG = LoggerFactory.getLogger(EntityStoreFactory.class);@@ -18,8 +22,15 @@ public class EntityStoreFactory {public static final ImmutableMap<String, String> ENTITY_STORES =ImmutableMap.of("kv", KvEntityStore.class.getCanonicalName());+ // Private constructor to prevent instantiation of this factory class.private EntityStoreFactory() {}+ /**+ * Creates an instance of EntityStore based on the configuration settings.+ *+ * @param config The configuration object containing settings for EntityStore.+ * @return An instance of EntityStore.+ */public static EntityStore createEntityStore(Config config) {String name = config.get(Configs.ENTITY_STORE);String className = ENTITY_STORES.getOrDefault(name, name);diff --git a/core/src/main/java/com/datastrato/graviton/Field.java b/core/src/main/java/com/datastrato/graviton/Field.javaindex 25274c30fa..b7dcf55ca1 100644--- a/core/src/main/java/com/datastrato/graviton/Field.java+++ b/core/src/main/java/com/datastrato/graviton/Field.java@@ -6,22 +6,28 @@ package com.datastrato.graviton;import lombok.EqualsAndHashCode;+/** This class represents a field in the Graviton framework. */@EqualsAndHashCodepublic class Field {- // The name of the field+private String fieldName;- // The type class of the fieldprivate Class<?> typeClass;- // The detailed description of the fieldprivate String description;- // Whether this field is optional or requiredprivate boolean optional;private Field() {}+ /**+ * Creates a required field instance.+ *+ * @param fieldName The name of the field.+ * @param typeClass The type class of the field.+ * @param description The description of the field.+ * @return A required Field instance.+ */public static Field required(String fieldName, Class<?> typeClass, String description) {return new Builder(false).withName(fieldName)@@ -30,6 +36,14 @@ public class Field {.build();}+ /**+ * Creates an optional field instance.+ *+ * @param fieldName The name of the field.+ * @param typeClass The type class of the field.+ * @param description The description of the field.+ * @return An optional Field instance.+ */public static Field optional(String fieldName, Class<?> typeClass, String description) {return new Builder(true).withName(fieldName)@@ -38,14 +52,35 @@ public class Field {.build();}+ /**+ * Creates a required field instance.+ *+ * @param fieldName The name of the field.+ * @param typeClass The type class of the field.+ * @return A required Field instance.+ */public static Field required(String fieldName, Class<?> typeClass) {return new Builder(false).withName(fieldName).withTypeClass(typeClass).build();}+ /**+ * Creates an optional field instance.+ *+ * @param fieldName The name of the field.+ * @param typeClass The type class of the field.+ * @return An optional Field instance.+ */public static Field optional(String fieldName, Class<?> typeClass) {return new Builder(true).withName(fieldName).withTypeClass(typeClass).build();}+ /**+ * Validates a field value according to the field's requirements.+ *+ * @param fieldValue The value to be validated.+ * @param <T> The type of the field value.+ * @throws IllegalArgumentException If the field value is invalid.+ */public <T> void validate(T fieldValue) {if (fieldValue == null && !optional) {throw new IllegalArgumentException("Field " + fieldName + " is required");@@ -57,29 +92,59 @@ public class Field {}}+ /** Builder class for creating Field instances. */public static class Builder {private final Field field;+ /**+ * Constructs a Field Builder with the specified optionality.+ *+ * @param isOptional Set to true for an optional field, false for a required field.+ */public Builder(boolean isOptional) {field = new Field();field.optional = isOptional;}+ /**+ * Sets the name of the field.+ *+ * @param name The name of the field.+ * @return The Builder instance.+ */public Builder withName(String name) {field.fieldName = name;return this;}+ /**+ * Sets the type class of the field.+ *+ * @param typeClass The type class of the field.+ * @return The Builder instance.+ */public Builder withTypeClass(Class<?> typeClass) {field.typeClass = typeClass;return this;}+ /**+ * Sets the description of the field.+ *+ * @param description The description of the field.+ * @return The Builder instance.+ */public Builder withDescription(String description) {field.description = description;return this;}+ /**+ * Builds and returns the configured Field instance.+ *+ * @return The created Field instance.+ * @throws IllegalArgumentException If the field attributes are not properly set.+ */public Field build() {if (field.fieldName == null) {throw new IllegalArgumentException("Field name is required");diff --git a/core/src/main/java/com/datastrato/graviton/GravitonEnv.java b/core/src/main/java/com/datastrato/graviton/GravitonEnv.javaindex ca9a4b595e..0daca2aa94 100644--- a/core/src/main/java/com/datastrato/graviton/GravitonEnv.java+++ b/core/src/main/java/com/datastrato/graviton/GravitonEnv.java@@ -10,6 +10,9 @@ import com.datastrato.graviton.meta.MetalakeManager;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+/*+ * This class manages the Graviton environment.+ */public class GravitonEnv {private static final Logger LOG = LoggerFactory.getLogger(GravitonEnv.class);@@ -32,10 +35,20 @@ public class GravitonEnv {private static final GravitonEnv INSTANCE = new GravitonEnv();}+ /**+ * Get the singleton instance of the GravitonEnv.+ *+ * @return The singleton instance of the GravitonEnv.+ */public static GravitonEnv getInstance() {return InstanceHolder.INSTANCE;}+ /**+ * Initialize the Graviton environment.+ *+ * @param config The configuration object to initialize the environment.+ */public void initialize(Config config) {LOG.info("Initializing Graviton Environment...");@@ -59,30 +72,61 @@ public class GravitonEnv {LOG.info("Graviton Environment is initialized.");}+ /**+ * Get the configuration object associated with the Graviton environment.+ *+ * @return The configuration object.+ */public Config config() {return config;}+ /**+ * Get the EntitySerDe associated with the Graviton environment.+ *+ * @return The EntitySerDe instance.+ */public EntitySerDe entitySerDe() {return entitySerDe;}+ /**+ * Get the EntityStore associated with the Graviton environment.+ *+ * @return The EntityStore instance.+ */public EntityStore entityStore() {return entityStore;}+ /**+ * Get the CatalogManager associated with the Graviton environment.+ *+ * @return The CatalogManager instance.+ */public CatalogManager catalogManager() {return catalogManager;}+ /**+ * Get the CatalogOperationDispatcher associated with the Graviton environment.+ *+ * @return The CatalogOperationDispatcher instance.+ */public CatalogOperationDispatcher catalogOperationDispatcher() {return catalogOperationDispatcher;}+ /**+ * Get the MetalakeManager associated with the Graviton environment.+ *+ * @return The MetalakeManager instance.+ */public MetalakeManager metalakesManager() {return metalakeManager;}+ /** Shutdown the Graviton environment. */public void shutdown() {LOG.info("Shutting down Graviton Environment...");diff --git a/core/src/main/java/com/datastrato/graviton/HasIdentifier.java b/core/src/main/java/com/datastrato/graviton/HasIdentifier.javaindex d6ccfb5a1b..62ad5f7c7c 100644--- a/core/src/main/java/com/datastrato/graviton/HasIdentifier.java+++ b/core/src/main/java/com/datastrato/graviton/HasIdentifier.java@@ -4,20 +4,38 @@*/package com.datastrato.graviton;+/** This interface represents entities that have identifiers. */public interface HasIdentifier {- /** Return the name of the entity. */+ /**+ * Get the name of the entity.+ *+ * @return The name of the entity.+ */String name();- /** Returns the namespace of the entity. */+ /**+ * Get the namespace of the entity.+ *+ * @return The namespace of the entity.+ */default Namespace namespace() {return Namespace.empty();}- /** Returns the name identifier of the entity. */+ /**+ * Get the name identifier of the entity.+ *+ * @return The name identifier of the entity.+ */default NameIdentifier nameIdentifier() {return NameIdentifier.of(namespace(), name());}+ /**+ * Returns a binary compact unique identifier of the entity.+ *+ * @return The binary compact unique identifier of the entity.+ */// TODO. Returns a binary compact unique identifier of the entity. @Jerry}diff --git a/core/src/main/java/com/datastrato/graviton/NoSuchEntityException.java b/core/src/main/java/com/datastrato/graviton/NoSuchEntityException.javaindex db675cc0ef..f10d7833d7 100644--- a/core/src/main/java/com/datastrato/graviton/NoSuchEntityException.java+++ b/core/src/main/java/com/datastrato/graviton/NoSuchEntityException.java@@ -4,12 +4,24 @@*/package com.datastrato.graviton;+/** This exception is thrown when an entity is not found. */public class NoSuchEntityException extends RuntimeException {+ /**+ * Constructs a new NoSuchEntityException.+ *+ * @param message The detail message.+ */public NoSuchEntityException(String message) {super(message);}+ /**+ * Constructs a new NoSuchEntityException.+ *+ * @param message The detail message.+ * @param cause The cause of the exception.+ */public NoSuchEntityException(String message, Throwable cause) {super(message, cause);}diff --git a/core/src/main/java/com/datastrato/graviton/catalog/BaseCatalog.java b/core/src/main/java/com/datastrato/graviton/catalog/BaseCatalog.javaindex d1814bb7ac..6b37cf0968 100644--- a/core/src/main/java/com/datastrato/graviton/catalog/BaseCatalog.java+++ b/core/src/main/java/com/datastrato/graviton/catalog/BaseCatalog.java@@ -20,6 +20,8 @@ import java.util.Map;** <p>For example, a hive catalog has a {@link CatalogEntity} metadata and a {@link* CatalogOperations} which manipulates Hive DBs and tables.+ *+ * @param <T> The type of the concrete subclass of BaseCatalog.*/public abstract class BaseCatalog<T extends BaseCatalog> implements Catalog, CatalogProvider {@@ -29,8 +31,21 @@ public abstract class BaseCatalog<T extends BaseCatalog> implements Catalog, Catprivate volatile CatalogOperations ops;+ /**+ * Creates a new instance of CatalogOperations.+ *+ * @param config The configuration parameters for creating CatalogOperations.+ * @return A new instance of CatalogOperations.+ */protected abstract CatalogOperations newOps(Map<String, String> config);+ /**+ * Retrieves the CatalogOperations instance associated with this catalog. Lazily initializes the+ * instance if not already created.+ *+ * @return The CatalogOperations instance.+ * @throws IllegalArgumentException If the entity or configuration is not set.+ */public CatalogOperations ops() {if (ops == null) {synchronized (this) {@@ -45,16 +60,33 @@ public abstract class BaseCatalog<T extends BaseCatalog> implements Catalog, Catreturn ops;}+ /**+ * Sets the CatalogEntity for this catalog.+ *+ * @param entity The CatalogEntity representing the metadata of the catalog.+ * @return The instance of the concrete subclass of BaseCatalog.+ */public T withCatalogEntity(CatalogEntity entity) {this.entity = entity;return (T) this;}+ /**+ * Sets the configuration for this catalog.+ *+ * @param conf The configuration parameters as a map.+ * @return The instance of the concrete subclass of BaseCatalog.+ */public T withCatalogConf(Map<String, String> conf) {this.conf = conf;return (T) this;}+ /**+ * Retrieves the CatalogEntity associated with this catalog.+ *+ * @return The CatalogEntity instance.+ */public CatalogEntity entity() {return entity;}diff --git a/core/src/main/java/com/datastrato/graviton/catalog/CatalogManager.java b/core/src/main/java/com/datastrato/graviton/catalog/CatalogManager.javaindex 5b062480ef..910afc85d1 100644--- a/core/src/main/java/com/datastrato/graviton/catalog/CatalogManager.java+++ b/core/src/main/java/com/datastrato/graviton/catalog/CatalogManager.java@@ -55,10 +55,12 @@ import java.util.stream.Collectors;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+/** Manages the catalog instances and operations. */public class CatalogManager implements SupportsCatalogs, Closeable {private static final Logger LOG = LoggerFactory.getLogger(CatalogManager.class);+ /** Wrapper class for a catalog instance and its class loader. */public static class CatalogWrapper {private BaseCatalog catalog;private IsolatedClassLoader classLoader;@@ -116,6 +118,12 @@ public class CatalogManager implements SupportsCatalogs, Closeable {private final EntityStore store;+ /**+ * Constructs a CatalogManager instance.+ *+ * @param config The configuration for the manager.+ * @param store The entity store to use.+ */public CatalogManager(Config config, EntityStore store) {this.config = config;this.store = store;@@ -140,11 +148,22 @@ public class CatalogManager implements SupportsCatalogs, Closeable {.build();}+ /**+ * Closes the CatalogManager and releases any resources associated with it. This method+ * invalidates all cached catalog instances and clears the cache.+ */@Overridepublic void close() {catalogCache.invalidateAll();}+ /**+ * Lists the catalogs within the specified namespace.+ *+ * @param namespace The namespace for which to list catalogs.+ * @return An array of NameIdentifier objects representing the catalogs.+ * @throws NoSuchMetalakeException If the specified metalake does not exist.+ */@Overridepublic NameIdentifier[] listCatalogs(Namespace namespace) throws NoSuchMetalakeException {NameIdentifier metalakeIdent = NameIdentifier.of(namespace.levels());@@ -172,11 +191,29 @@ public class CatalogManager implements SupportsCatalogs, Closeable {}}+ /**+ * Loads the catalog with the specified identifier.+ *+ * @param ident The identifier of the catalog to load.+ * @return The loaded catalog.+ * @throws NoSuchCatalogException If the specified catalog does not exist.+ */@Overridepublic Catalog loadCatalog(NameIdentifier ident) throws NoSuchCatalogException {return loadCatalogAndWrap(ident).catalog;}+ /**+ * Creates a new catalog with the provided details.+ *+ * @param ident The identifier of the new catalog.+ * @param type The type of the new catalog.+ * @param comment The comment for the new catalog.+ * @param properties The properties of the new catalog.+ * @return The created catalog.+ * @throws NoSuchMetalakeException If the specified metalake does not exist.+ * @throws CatalogAlreadyExistsException If a catalog with the same identifier already exists.+ */@Overridepublic Catalog createCatalog(NameIdentifier ident, Catalog.Type type, String comment, Map<String, String> properties)@@ -224,6 +261,15 @@ public class CatalogManager implements SupportsCatalogs, Closeable {}}+ /**+ * Alters an existing catalog with the specified changes.+ *+ * @param ident The identifier of the catalog to alter.+ * @param changes The changes to apply to the catalog.+ * @return The altered catalog.+ * @throws NoSuchCatalogException If the specified catalog does not exist.+ * @throws IllegalArgumentException If an unsupported catalog change is provided.+ */@Overridepublic Catalog alterCatalog(NameIdentifier ident, CatalogChange... changes)throws NoSuchCatalogException, IllegalArgumentException {@@ -283,6 +329,12 @@ public class CatalogManager implements SupportsCatalogs, Closeable {}}+ /**+ * Drops (deletes) the catalog with the specified identifier.+ *+ * @param ident The identifier of the catalog to drop.+ * @return {@code true} if the catalog was successfully dropped, {@code false} otherwise.+ */@Overridepublic boolean dropCatalog(NameIdentifier ident) {// There could be a race issue that someone is using the catalog while we are dropping it.@@ -296,6 +348,14 @@ public class CatalogManager implements SupportsCatalogs, Closeable {}}+ /**+ * Loads the catalog with the specified identifier, wraps it in a CatalogWrapper, and caches the+ * wrapper for reuse.+ *+ * @param ident The identifier of the catalog to load.+ * @return The wrapped CatalogWrapper containing the loaded catalog.+ * @throws NoSuchCatalogException If the specified catalog does not exist.+ */public CatalogWrapper loadCatalogAndWrap(NameIdentifier ident) throws NoSuchCatalogException {return catalogCache.get(ident, this::loadCatalogInternal);}diff --git a/core/src/main/java/com/datastrato/graviton/catalog/CatalogOperationDispatcher.java b/core/src/main/java/com/datastrato/graviton/catalog/CatalogOperationDispatcher.javaindex eac6820921..30a488ec06 100644--- a/core/src/main/java/com/datastrato/graviton/catalog/CatalogOperationDispatcher.java+++ b/core/src/main/java/com/datastrato/graviton/catalog/CatalogOperationDispatcher.java@@ -30,10 +30,23 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasprivate final CatalogManager catalogManager;+ /**+ * Creates a new CatalogOperationDispatcher instance.+ *+ * @param catalogManager The CatalogManager instance to be used for catalog operations.+ */public CatalogOperationDispatcher(CatalogManager catalogManager) {this.catalogManager = catalogManager;}+ /**+ * Lists the schemas within the specified namespace.+ *+ * @param namespace The namespace in which to list schemas.+ * @return An array of NameIdentifier objects representing the schemas within the specified+ * namespace.+ * @throws NoSuchCatalogException If the catalog namespace does not exist.+ */@Overridepublic NameIdentifier[] listSchemas(Namespace namespace) throws NoSuchCatalogException {NameIdentifier catalogIdent = NameIdentifier.of(namespace.levels());@@ -44,6 +57,17 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasNoSuchCatalogException.class);}+ /**+ * Creates a new schema.+ *+ * @param ident The identifier for the schema to be created.+ * @param comment The comment for the new schema.+ * @param metadata Additional metadata for the new schema.+ * @return The created Schema object.+ * @throws NoSuchCatalogException If the catalog corresponding to the provided identifier does not+ * exist.+ * @throws SchemaAlreadyExistsException If a schema with the same identifier already exists.+ */@Overridepublic Schema createSchema(NameIdentifier ident, String comment, Map<String, String> metadata)throws NoSuchCatalogException, SchemaAlreadyExistsException {@@ -56,6 +80,13 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasSchemaAlreadyExistsException.class);}+ /**+ * Loads and retrieves a schema.+ *+ * @param ident The identifier of the schema to be loaded.+ * @return The loaded Schema object.+ * @throws NoSuchSchemaException If the schema does not exist.+ */@Overridepublic Schema loadSchema(NameIdentifier ident) throws NoSuchSchemaException {NameIdentifier catalogIdent = NameIdentifier.of(ident.namespace().levels());@@ -66,6 +97,15 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasNoSuchSchemaException.class);}+ /**+ * Alters the schema by applying the provided schema changes.+ *+ * @param ident The identifier of the schema to be altered.+ * @param changes The array of SchemaChange objects representing the alterations to apply.+ * @return The altered Schema object.+ * @throws NoSuchSchemaException If the schema corresponding to the provided identifier does not+ * exist.+ */@Overridepublic Schema alterSchema(NameIdentifier ident, SchemaChange... changes)throws NoSuchSchemaException {@@ -77,6 +117,14 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasNoSuchSchemaException.class);}+ /**+ * Drops a schema.+ *+ * @param ident The identifier of the schema to be dropped.+ * @param cascade If true, drops all tables within the schema as well.+ * @return True if the schema was successfully dropped, false otherwise.+ * @throws NonEmptySchemaException If the schema contains tables and cascade is set to false.+ */@Overridepublic boolean dropSchema(NameIdentifier ident, boolean cascade) throws NonEmptySchemaException {NameIdentifier catalogIdent = NameIdentifier.of(ident.namespace().levels());@@ -87,6 +135,14 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasNonEmptySchemaException.class);}+ /**+ * Lists the tables within a schema.+ *+ * @param namespace The namespace of the schema containing the tables.+ * @return An array of {@link NameIdentifier} objects representing the identifiers of the tables+ * in the schema.+ * @throws NoSuchSchemaException If the specified schema does not exist.+ */@Overridepublic NameIdentifier[] listTables(Namespace namespace) throws NoSuchSchemaException {NameIdentifier catalogIdent = NameIdentifier.of(namespace.levels());@@ -97,6 +153,13 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasNoSuchSchemaException.class);}+ /**+ * Loads a table.+ *+ * @param ident The identifier of the table to load.+ * @return The loaded {@link Table} object representing the requested table.+ * @throws NoSuchTableException If the specified table does not exist.+ */@Overridepublic Table loadTable(NameIdentifier ident) throws NoSuchTableException {NameIdentifier catalogIdent = NameIdentifier.of(ident.namespace().levels());@@ -105,6 +168,17 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemascatalogIdent, c -> c.doWithTableOps(t -> t.loadTable(ident)), NoSuchTableException.class);}+ /**+ * Creates a new table in a schema.+ *+ * @param ident The identifier of the table to create.+ * @param columns An array of {@link Column} objects representing the columns of the table.+ * @param comment A description or comment associated with the table.+ * @param properties Additional properties to set for the table.+ * @return The newly created {@link Table} object.+ * @throws NoSuchSchemaException If the schema in which to create the table does not exist.+ * @throws TableAlreadyExistsException If a table with the same name already exists in the schema.+ */@Overridepublic Table createTable(NameIdentifier ident, Column[] columns, String comment, Map<String, String> properties)@@ -118,6 +192,16 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasTableAlreadyExistsException.class);}+ /**+ * Alters an existing table.+ *+ * @param ident The identifier of the table to alter.+ * @param changes An array of {@link TableChange} objects representing the changes to apply to the+ * table.+ * @return The altered {@link Table} object after applying the changes.+ * @throws NoSuchTableException If the table to alter does not exist.+ * @throws IllegalArgumentException If an unsupported or invalid change is specified.+ */@Overridepublic Table alterTable(NameIdentifier ident, TableChange... changes)throws NoSuchTableException, IllegalArgumentException {@@ -130,6 +214,14 @@ public class CatalogOperationDispatcher implements TableCatalog, SupportsSchemasIllegalArgumentException.class);}+ /**+ * Drops a table from the catalog.+ *+ * @param ident The identifier of the table to drop.+ * @return {@code true} if the table was successfully dropped, {@code false} if the table does not+ * exist.+ * @throws NoSuchTableException If the table to drop does not exist.+ */@Overridepublic boolean dropTable(NameIdentifier ident) {NameIdentifier catalogIdent = NameIdentifier.of(ident.namespace().levels());diff --git a/core/src/main/java/com/datastrato/graviton/config/ConfigBuilder.java b/core/src/main/java/com/datastrato/graviton/config/ConfigBuilder.javaindex 370614cbd3..0479cfdb36 100644--- a/core/src/main/java/com/datastrato/graviton/config/ConfigBuilder.java+++ b/core/src/main/java/com/datastrato/graviton/config/ConfigBuilder.java@@ -23,6 +23,11 @@ public class ConfigBuilder {private boolean isDeprecated;+ /**+ * Constructs a ConfigBuilder with the given key.+ *+ * @param key The key for the configuration.+ */public ConfigBuilder(String key) {this.key = key;@@ -33,31 +38,64 @@ public class ConfigBuilder {this.isDeprecated = false;}+ /**+ * Sets the alternatives for the configuration.+ *+ * @param alternatives The list of alternative keys.+ * @return The current ConfigBuilder instance.+ */public ConfigBuilder alternatives(List<String> alternatives) {this.alternatives = alternatives;return this;}+ /**+ * Sets the documentation for the configuration.+ *+ * @param doc The documentation string.+ * @return The current ConfigBuilder instance.+ */public ConfigBuilder doc(String doc) {this.doc = doc;return this;}+ /**+ * Sets the version for the configuration.+ *+ * @param version The version string.+ * @return The current ConfigBuilder instance.+ */public ConfigBuilder version(String version) {this.version = version;return this;}+ /**+ * Marks the configuration entry as internal (non-public).+ *+ * @return The current ConfigBuilder instance.+ */public ConfigBuilder internal() {this.isPublic = false;return this;}+ /**+ * Marks the configuration entry as deprecated.+ *+ * @return The current ConfigBuilder instance.+ */public ConfigBuilder deprecated() {this.isDeprecated = true;return this;}+ /**+ * Creates a configuration entry for String data type.+ *+ * @return The created ConfigEntry instance for String data type.+ */public ConfigEntry<String> stringConf() {ConfigEntry<String> conf =new ConfigEntry<>(key, version, doc, alternatives, isPublic, isDeprecated);@@ -67,6 +105,11 @@ public class ConfigBuilder {return conf;}+ /**+ * Creates a configuration entry for Integer data type.+ *+ * @return The created ConfigEntry instance for Integer data type.+ */public ConfigEntry<Integer> intConf() {ConfigEntry<Integer> conf =new ConfigEntry<>(key, version, doc, alternatives, isPublic, isDeprecated);@@ -87,6 +130,11 @@ public class ConfigBuilder {return conf;}+ /**+ * Creates a configuration entry for Long data type.+ *+ * @return The created ConfigEntry instance for Long data type.+ */public ConfigEntry<Long> longConf() {ConfigEntry<Long> conf =new ConfigEntry<>(key, version, doc, alternatives, isPublic, isDeprecated);@@ -107,6 +155,11 @@ public class ConfigBuilder {return conf;}+ /**+ * Creates a configuration entry for Boolean data type.+ *+ * @return The created ConfigEntry instance for Boolean data type.+ */public ConfigEntry<Boolean> booleanConf() {ConfigEntry<Boolean> conf =new ConfigEntry<>(key, version, doc, alternatives, isPublic, isDeprecated);diff --git a/core/src/main/java/com/datastrato/graviton/config/ConfigEntry.java b/core/src/main/java/com/datastrato/graviton/config/ConfigEntry.javaindex 81d687cfcb..25475c808c 100644--- a/core/src/main/java/com/datastrato/graviton/config/ConfigEntry.java+++ b/core/src/main/java/com/datastrato/graviton/config/ConfigEntry.java@@ -13,6 +13,7 @@ import lombok.Getter;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+/** Defines configuration properties. */public class ConfigEntry<T> {private static final Logger LOG = LoggerFactory.getLogger(ConfigEntry.class);@@ -37,6 +38,16 @@ public class ConfigEntry<T> {private boolean isOptional;+ /**+ * Creates a new ConfigEntry instance.+ *+ * @param key The key of the configuration.+ * @param version The version of the configuration.+ * @param doc The documentation of the configuration.+ * @param alternatives Alternative keys for the configuration.+ * @param isPublic Whether the configuration is public.+ * @param isDeprecated Whether the configuration is deprecated.+ */ConfigEntry(String key,String version,@@ -53,22 +64,49 @@ public class ConfigEntry<T> {this.isOptional = false;}+ /**+ * Sets a custom value converter function for this configuration.+ *+ * @param valueConverter The function that converts a configuration value string to the desired+ * type.+ */void setValueConverter(Function<String, T> valueConverter) {this.valueConverter = valueConverter;}+ /**+ * Sets a custom string converter function for this configuration.+ *+ * @param stringConverter The function that converts a configuration value to its string+ * representation.+ */void setStringConverter(Function<T, String> stringConverter) {this.stringConverter = stringConverter;}+ /**+ * Sets the default value for this configuration.+ *+ * @param t The default value to be used when no value is provided.+ */void setDefaultValue(T t) {this.defaultValue = t;}+ /**+ * Marks this configuration as optional. An optional entry can be absent in the configuration+ * properties without raising an exception.+ */void setOptional() {this.isOptional = true;}+ /**+ * Creates a new ConfigEntry instance based on this configuration entry with a default value.+ *+ * @param t The default value to be used when no value is provided.+ * @return A new ConfigEntry instance with the specified default value.+ */public ConfigEntry<T> createWithDefault(T t) {ConfigEntry<T> conf =new ConfigEntry<>(key, version, doc, alternatives, isPublic, isDeprecated);@@ -79,17 +117,30 @@ public class ConfigEntry<T> {return conf;}+ /**+ * Creates a new ConfigEntry instance based on this configuration entry with optional value+ * handling.+ *+ * @return A new ConfigEntry instance that works with optional values.+ */public ConfigEntry<Optional<T>> createWithOptional() {ConfigEntry<Optional<T>> conf =new ConfigEntry<>(key, version, doc, alternatives, isPublic, isDeprecated);conf.setValueConverter(s -> Optional.ofNullable(valueConverter.apply(s)));- // null value should not be possible unless the user explicitly sets it+ // Unless explicitly set by the user, null values are not expected to occur.conf.setStringConverter(t -> t.map(stringConverter).orElse(null));conf.setOptional();return conf;}+ /**+ * Reads the configuration value.+ *+ * @param properties The map containing the configuration properties.+ * @return The value of the configuration entry.+ * @throws NoSuchElementException If the configuration value is not found.+ */public T readFrom(Map<String, String> properties) throws NoSuchElementException {String value = properties.get(key);if (value == null) {@@ -112,10 +163,16 @@ public class ConfigEntry<T> {return valueConverter.apply(value);}+ /**+ * Writes the provided value to the specified properties map.+ *+ * @param properties The map to write the configuration property to.+ * @param value The value of the configuration entry.+ */public void writeTo(Map<String, String> properties, T value) {String stringValue = stringConverter.apply(value);if (stringValue == null) {- // We don't want user to set a null value to config, so this basically will not happen;+ // To ensure that a null value is not set in the configurationLOG.warn("Config {} value to set is null, ignore setting to Config.", stringValue);return;}diff --git a/core/src/main/java/com/datastrato/graviton/meta/AuditInfo.java b/core/src/main/java/com/datastrato/graviton/meta/AuditInfo.javaindex 9c5937de36..69c8267060 100644--- a/core/src/main/java/com/datastrato/graviton/meta/AuditInfo.java+++ b/core/src/main/java/com/datastrato/graviton/meta/AuditInfo.java@@ -2,6 +2,7 @@* Copyright 2023 Datastrato.* This software is licensed under the Apache License version 2.*/+package com.datastrato.graviton.meta;import com.datastrato.graviton.Audit;@@ -16,19 +17,21 @@ import javax.annotation.Nullable;import lombok.EqualsAndHashCode;import lombok.ToString;+/** Audit information associated with an entity. */@EqualsAndHashCode@ToStringpublic final class AuditInfo implements Audit, Entity {+public static final Field CREATOR =- Field.required("creator", String.class, "The name of user who creates the entity");+ Field.required("creator", String.class, "The name of the user who created the entity");public static final Field CREATE_TIME =- Field.required("create_time", Instant.class, "The time when the entity is created");+ Field.required("create_time", Instant.class, "The time when the entity was created");public static final Field LAST_MODIFIER =Field.optional(- "last_modifier", String.class, "The name of user who last modifies the entity");+ "last_modifier", String.class, "The name of the user who last modified the entity");public static final Field LAST_MODIFIED_TIME =Field.optional(- "last_modified_time", Instant.class, "The time when the entity is last modified");+ "last_modified_time", Instant.class, "The time when the entity was last modified");private String creator;@@ -40,6 +43,11 @@ public final class AuditInfo implements Audit, Entity {private AuditInfo() {}+ /**+ * Validates the audit information.+ *+ * @throws IllegalArgumentException If the validation fails.+ */@Overridepublic void validate() throws IllegalArgumentException {CREATOR.validate(creator);@@ -48,9 +56,14 @@ public final class AuditInfo implements Audit, Entity {Preconditions.checkArgument(lastModifier == null && lastModifiedTime == null|| lastModifier != null && lastModifiedTime != null,- "last_modifier and last_modified_time must be both set or both not set");+ "last_modifier and last_modified_time must be both set or both left unset");}+ /**+ * Retrieves a map of fields.+ *+ * @return An unmodifiable map containing the entity's fields and values.+ */@Overridepublic Map<Field, Object> fields() {Map<Field, Object> fields = new HashMap<>();@@ -62,58 +75,114 @@ public final class AuditInfo implements Audit, Entity {return Collections.unmodifiableMap(fields);}+ /**+ * Retrieves the creator's name.+ *+ * @return The name of the creator.+ */@Overridepublic String creator() {return creator;}+ /**+ * Retrieves the creation time.+ *+ * @return the creation time as an {@link Instant}.+ */@Overridepublic Instant createTime() {return createTime;}+ /**+ * Retrieves the last modifier's name.+ *+ * @return the name of the last modifier, or null if not set.+ */@Overridepublic String lastModifier() {return lastModifier;}+ /**+ * Retrieves the last modified time.+ *+ * @return the last modified time as an {@link Instant}, or null if not set.+ */@Overridepublic Instant lastModifiedTime() {return lastModifiedTime;}+ /**+ * Retrieves the type of the entity.+ *+ * @return the {@link EntityType#AUDIT} value.+ */@Overridepublic EntityType type() {return EntityType.AUDIT;}+ /** Builder class for creating instances of {@link AuditInfo}. */public static class Builder {private AuditInfo auditInfo;+ /** Constructs a new {@link Builder}. */public Builder() {this.auditInfo = new AuditInfo();}+ /**+ * Sets the creator's name.+ *+ * @param creator the name of the creator.+ * @return the builder instance.+ */public Builder withCreator(String creator) {this.auditInfo.creator = creator;return this;}+ /**+ * Sets the creation time.+ *+ * @param createTime the creation time as an {@link Instant}.+ * @return the builder instance.+ */public Builder withCreateTime(Instant createTime) {this.auditInfo.createTime = createTime;return this;}+ /**+ * Sets the modifier's name.+ *+ * @param lastModifier the name of the modifier.+ * @return the builder instance.+ */public Builder withLastModifier(String lastModifier) {this.auditInfo.lastModifier = lastModifier;return this;}+ /**+ * Sets the last modified time.+ *+ * @param lastModifiedTime the last modified time as an {@link Instant}.+ * @return the builder instance.+ */public Builder withLastModifiedTime(Instant lastModifiedTime) {this.auditInfo.lastModifiedTime = lastModifiedTime;return this;}+ /**+ * Builds the {@link AuditInfo} instance after validation.+ *+ * @return the constructed and validated {@link AuditInfo} instance.+ */public AuditInfo build() {auditInfo.validate();return auditInfo;diff --git a/core/src/main/java/com/datastrato/graviton/meta/BaseMetalake.java b/core/src/main/java/com/datastrato/graviton/meta/BaseMetalake.javaindex 5fd13b3c87..014e44031d 100644--- a/core/src/main/java/com/datastrato/graviton/meta/BaseMetalake.java+++ b/core/src/main/java/com/datastrato/graviton/meta/BaseMetalake.java@@ -18,21 +18,24 @@ import lombok.EqualsAndHashCode;import lombok.Getter;import lombok.ToString;+/** Base implementation of a Metalake entity. */@EqualsAndHashCode@ToStringpublic class BaseMetalake implements Metalake, Entity, Auditable, HasIdentifier {public static final Field ID =- Field.required("id", Long.class, "The unique identifier of the metalake");- public static final Field NAME = Field.required("name", String.class, "The name of the metalake");+ Field.required("id", Long.class, "The metalake's unique identifier");+ public static final Field NAME = Field.required("name", String.class, "The metalake's name");public static final Field COMMENT =- Field.optional("comment", String.class, "The comment of the metalake");+ Field.optional("comment", String.class, "The metalake's comment or description");public static final Field PROPERTIES =- Field.optional("properties", Map.class, "The properties of the metalake");+ Field.optional("properties", Map.class, "The properties associated with the metalake");public static final Field AUDIT_INFO =- Field.required("audit_info", AuditInfo.class, "The audit info of the metalake");+ Field.required("audit_info", AuditInfo.class, "The audit details of the metalake");++ /** The required field for the schema version of the metalake. */public static final Field SCHEMA_VERSION =- Field.required("version", SchemaVersion.class, "The schema version of the metalake");+ Field.required("version", SchemaVersion.class, "The version of the schema for the metalake");@Getter private Long id;@@ -48,6 +51,11 @@ public class BaseMetalake implements Metalake, Entity, Auditable, HasIdentifierprivate BaseMetalake() {}+ /**+ * A map of fields and their corresponding values.+ *+ * @return An unmodifiable map containing the entity's fields and values.+ */@Overridepublic Map<Field, Object> fields() {Map<Field, Object> fields = new HashMap<>();@@ -61,68 +69,136 @@ public class BaseMetalake implements Metalake, Entity, Auditable, HasIdentifierreturn Collections.unmodifiableMap(fields);}+ /**+ * The audit information of the metalake.+ *+ * @return The audit information as an {@link Audit} instance.+ */@Overridepublic Audit auditInfo() {return auditInfo;}+ /**+ * The name of the metalake.+ *+ * @return The name of the metalake.+ */@Overridepublic String name() {return name;}+ /**+ * The comment of the metalake.+ *+ * @return The comment of the metalake, or null if not set.+ */@Overridepublic String comment() {return comment;}+ /**+ * Retrieves the type of the entity.+ *+ * @return the {@link EntityType#METALAKE} value.+ */@Overridepublic EntityType type() {return EntityType.METALAKE;}+ /**+ * Retrieves the properties of the metalake.+ *+ * @return the properties as a map of key-value pairs.+ */@Overridepublic Map<String, String> properties() {return properties;}+ /** Builder class for creating instances of {@link BaseMetalake}. */public static class Builder {private final BaseMetalake metalake;+ /** Constructs a new {@link Builder}. */public Builder() {metalake = new BaseMetalake();}+ /**+ * Sets the unique identifier of the metalake.+ *+ * @param id the unique identifier of the metalake.+ * @return the builder instance.+ */public Builder withId(Long id) {metalake.id = id;return this;}+ /**+ * Sets the name of the metalake.+ *+ * @param name the name of the metalake.+ * @return the builder instance.+ */public Builder withName(String name) {metalake.name = name;return this;}+ /**+ * Sets the comment of the metalake.+ *+ * @param comment the comment of the metalake.+ * @return the builder instance.+ */public Builder withComment(String comment) {metalake.comment = comment;return this;}+ /**+ * Sets the properties of the metalake.+ *+ * @param properties the properties as a map of key-value pairs.+ * @return the builder instance.+ */public Builder withProperties(Map<String, String> properties) {metalake.properties = properties;return this;}+ /**+ * Sets the audit information of the metalake.+ *+ * @param auditInfo the audit information as an {@link AuditInfo} instance.+ * @return the builder instance.+ */public Builder withAuditInfo(AuditInfo auditInfo) {metalake.auditInfo = auditInfo;return this;}+ /**+ * Sets the schema version of the metalake.+ *+ * @param version the schema version as a {@link SchemaVersion} instance.+ * @return the builder instance.+ */public Builder withVersion(SchemaVersion version) {metalake.version = version;return this;}+ /**+ * Builds the {@link BaseMetalake} instance after validation.+ *+ * @return the constructed and validated {@link BaseMetalake} instance.+ */public BaseMetalake build() {metalake.validate();return metalake;diff --git a/core/src/main/java/com/datastrato/graviton/meta/CatalogEntity.java b/core/src/main/java/com/datastrato/graviton/meta/CatalogEntity.javaindex e54d209d62..fd5ffc5e77 100644--- a/core/src/main/java/com/datastrato/graviton/meta/CatalogEntity.java+++ b/core/src/main/java/com/datastrato/graviton/meta/CatalogEntity.java@@ -19,22 +19,23 @@ import javax.annotation.Nullable;import lombok.Getter;import lombok.ToString;+/** An entity within a catalog. */@ToStringpublic class CatalogEntity implements Entity, Auditable, HasIdentifier {public static final Field ID =- Field.required("id", Long.class, "The unique identifier of the catalog");+ Field.required("id", Long.class, "The catalog's unique identifier");public static final Field METALAKE_ID =- Field.required("metalake_id", Long.class, "The unique identifier of the metalake");- public static final Field NAME = Field.required("name", String.class, "The name of the catalog");+ Field.required("metalake_id", Long.class, "The associated metalake's unique identifier");+ public static final Field NAME = Field.required("name", String.class, "The catalog's name");public static final Field TYPE =Field.required("type", Catalog.Type.class, "The type of the catalog");public static final Field COMMENT =- Field.optional("comment", String.class, "The comment of the catalog");+ Field.optional("comment", String.class, "The comment or description of the catalog");public static final Field PROPERTIES =- Field.optional("properties", Map.class, "The properties of the catalog");+ Field.optional("properties", Map.class, "The properties associated with the catalog");public static final Field AUDIT_INFO =- Field.required("audit_info", AuditInfo.class, "The audit info of the catalog");+ Field.required("audit_info", AuditInfo.class, "The audit details of the catalog");@Getter private Long id;@@ -52,6 +53,11 @@ public class CatalogEntity implements Entity, Auditable, HasIdentifier {private Namespace namespace;+ /**+ * A map of fields and their corresponding values.+ *+ * @return An unmodifiable map containing the entity's fields and values.+ */@Overridepublic Map<Field, Object> fields() {Map<Field, Object> fields = new HashMap<>();@@ -66,81 +72,162 @@ public class CatalogEntity implements Entity, Auditable, HasIdentifier {return Collections.unmodifiableMap(fields);}+ /**+ * The audit information of the catalog.+ *+ * @return the audit information as an {@link Audit} instance.+ */@Overridepublic Audit auditInfo() {return auditInfo;}+ /**+ * The name of the catalog entity.+ *+ * @return The name of the catalog entity.+ */@Overridepublic String name() {return name;}+ /**+ * The namespace of the catalog entity.+ *+ * @return The namespace as a {@link Namespace} instance.+ */@Overridepublic Namespace namespace() {return namespace;}+ /**+ * The type of the entity.+ *+ * @return The {@link EntityType#CATALOG} value.+ */@Overridepublic EntityType type() {return EntityType.CATALOG;}+ /** Builder class for creating instances of {@link CatalogEntity}. */public static class Builder {private final CatalogEntity catalog;+ /** Constructs a new {@link Builder}. */public Builder() {catalog = new CatalogEntity();}+ /**+ * Sets the unique identifier of the catalog.+ *+ * @param id the unique identifier of the catalog.+ * @return the builder instance.+ */public Builder withId(Long id) {catalog.id = id;return this;}+ /**+ * Sets the unique identifier of the associated metalake.+ *+ * @param metalakeId the unique identifier of the metalake.+ * @return the builder instance.+ */public Builder withMetalakeId(Long metalakeId) {catalog.metalakeId = metalakeId;return this;}+ /**+ * Sets the name of the catalog.+ *+ * @param name the name of the catalog.+ * @return the builder instance.+ */public Builder withName(String name) {catalog.name = name;return this;}+ /**+ * Sets the namespace of the catalog.+ *+ * @param namespace the namespace as a {@link Namespace} instance.+ * @return the builder instance.+ */public Builder withNamespace(Namespace namespace) {catalog.namespace = namespace;return this;}+ /**+ * Sets the type of the catalog.+ *+ * @param type the type of the catalog.+ * @return the builder instance.+ */public Builder withType(Catalog.Type type) {catalog.type = type;return this;}+ /**+ * Sets the comment or description of the catalog.+ *+ * @param comment the comment of the catalog.+ * @return the builder instance.+ */public Builder withComment(String comment) {catalog.comment = comment;return this;}+ /**+ * Sets the properties of the catalog.+ *+ * @param properties the properties as a map of key-value pairs.+ * @return the builder instance.+ */public Builder withProperties(Map<String, String> properties) {catalog.properties = properties;return this;}+ /**+ * Sets the audit information of the catalog.+ *+ * @param auditInfo the audit information as an {@link AuditInfo} instance.+ * @return the builder instance.+ */public Builder withAuditInfo(AuditInfo auditInfo) {catalog.auditInfo = auditInfo;return this;}+ /**+ * Builds the {@link CatalogEntity} instance after validation.+ *+ * @return the constructed and validated {@link CatalogEntity} instance.+ */public CatalogEntity build() {catalog.validate();return catalog;}}- /** Attention, this method ignores the namespace field in the comparison */+ /**+ * Compares this object to the specified object for equality. Note: This method ignores comparing+ * the namespace field.+ *+ * @param o the object to compare to.+ * @return {@code true} if the objects are equal, {@code false} otherwise.+ */@Overridepublic boolean equals(Object o) {if (this == o) {@@ -159,6 +246,11 @@ public class CatalogEntity implements Entity, Auditable, HasIdentifier {&& Objects.equal(auditInfo, that.auditInfo);}+ /**+ * Generates a hash code value for this object based on its attributes.+ *+ * @return the hash code value for this object.+ */@Overridepublic int hashCode() {return Objects.hashCode(id, metalakeId, name, type, comment, properties, auditInfo);diff --git a/core/src/main/java/com/datastrato/graviton/meta/MetalakeManager.java b/core/src/main/java/com/datastrato/graviton/meta/MetalakeManager.javaindex a61d5b86ae..59c464303e 100644--- a/core/src/main/java/com/datastrato/graviton/meta/MetalakeManager.java+++ b/core/src/main/java/com/datastrato/graviton/meta/MetalakeManager.java@@ -21,16 +21,28 @@ import java.util.Map;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+/** Manages Metalakes within the Graviton system. */public class MetalakeManager implements SupportsMetalakes {private static final Logger LOG = LoggerFactory.getLogger(MetalakeManager.class);private final EntityStore store;+ /**+ * Constructs a MetalakeManager instance.+ *+ * @param store The EntityStore to use for managing Metalakes.+ */public MetalakeManager(EntityStore store) {this.store = store;}+ /**+ * Lists all available Metalakes.+ *+ * @return An array of Metalake instances representing the available Metalakes.+ * @throws RuntimeException If listing Metalakes encounters storage issues.+ */@Overridepublic BaseMetalake[] listMetalakes() {try {@@ -38,11 +50,19 @@ public class MetalakeManager implements SupportsMetalakes {.list(Namespace.empty(), BaseMetalake.class, EntityType.METALAKE).toArray(new BaseMetalake[0]);} catch (IOException ioe) {- LOG.error("Failed to list metalakes due to storage issues", ioe);+ LOG.error("Listing Metalakes failed due to storage issues.", ioe);throw new RuntimeException(ioe);}}+ /**+ * Loads a Metalake.+ *+ * @param ident The identifier of the Metalake to load.+ * @return The loaded Metalake instance.+ * @throws NoSuchMetalakeException If the Metalake with the given identifier does not exist.+ * @throws RuntimeException If loading the Metalake encounters storage issues.+ */@Overridepublic BaseMetalake loadMetalake(NameIdentifier ident) throws NoSuchMetalakeException {try {@@ -51,25 +71,35 @@ public class MetalakeManager implements SupportsMetalakes {LOG.warn("Metalake {} does not exist", ident, e);throw new NoSuchMetalakeException("Metalake " + ident + " does not exist");} catch (IOException ioe) {- LOG.error("Failed to load metalake {} due to storage issues", ident, ioe);+ LOG.error("Loading Metalake {} failed due to storage issues", ident, ioe);throw new RuntimeException(ioe);}}+ /**+ * Creates a new Metalake.+ *+ * @param ident The identifier of the new Metalake.+ * @param comment A comment or description for the Metalake.+ * @param properties Additional properties for the Metalake.+ * @return The created Metalake instance.+ * @throws MetalakeAlreadyExistsException If a Metalake with the same identifier already exists.+ * @throws RuntimeException If creating the Metalake encounters storage issues.+ */@Overridepublic BaseMetalake createMetalake(NameIdentifier ident, String comment, Map<String, String> properties)throws MetalakeAlreadyExistsException {BaseMetalake metalake =new BaseMetalake.Builder()- .withId(1L /* TODO. use ID generator */)+ .withId(1L /* TODO: Use ID generator */).withName(ident.name()).withComment(comment).withProperties(properties).withVersion(SchemaVersion.V_0_1).withAuditInfo(new AuditInfo.Builder()- .withCreator("graviton") /*TODO. we should real user later on*/+ .withCreator("graviton") /*TODO: Use real user later on. */.withCreateTime(Instant.now()).build()).build();@@ -81,11 +111,21 @@ public class MetalakeManager implements SupportsMetalakes {LOG.warn("Metalake {} already exists", ident, e);throw new MetalakeAlreadyExistsException("Metalake " + ident + " already exists");} catch (IOException ioe) {- LOG.error("Failed to create metalake {} due to storage issues", ident, ioe);+ LOG.error("Loading Metalake {} failed due to storage issues", ident, ioe);throw new RuntimeException(ioe);}}+ /**+ * Alters a Metalake by applying specified changes.+ *+ * @param ident The identifier of the Metalake to be altered.+ * @param changes The array of MetalakeChange objects representing the changes to apply.+ * @return The altered Metalake instance after applying the changes.+ * @throws NoSuchMetalakeException If the Metalake with the given identifier does not exist.+ * @throws IllegalArgumentException If the provided changes are invalid.+ * @throws RuntimeException If altering the Metalake encounters storage issues.+ */@Overridepublic BaseMetalake alterMetalake(NameIdentifier ident, MetalakeChange... changes)throws NoSuchMetalakeException, IllegalArgumentException {@@ -108,7 +148,7 @@ public class MetalakeManager implements SupportsMetalakes {.withCreator(metalake.auditInfo().creator()).withCreateTime(metalake.auditInfo().createTime()).withLastModifier(- metalake.auditInfo().creator()) /*TODO. we should real user later on*/+ metalake.auditInfo().creator()) /*TODO: Use real user later on. */.withLastModifiedTime(Instant.now()).build();builder.withAuditInfo(newInfo);@@ -127,25 +167,41 @@ public class MetalakeManager implements SupportsMetalakes {throw new NoSuchMetalakeException("Metalake " + ident + " does not exist");} catch (IllegalArgumentException iae) {- LOG.warn("Failed to alter metalake {} due to invalid changes", ident, iae);+ LOG.warn("Altering Metalake {} failed due to invalid changes", ident, iae);throw iae;} catch (IOException ioe) {- LOG.error("Failed to alter metalake {} due to storage issues", ident, ioe);+ LOG.error("Loading Metalake {} failed due to storage issues", ident, ioe);throw new RuntimeException(ioe);}}+ /**+ * Deletes a Metalake.+ *+ * @param ident The identifier of the Metalake to be deleted.+ * @return `true` if the Metalake was successfully deleted, `false` otherwise.+ * @throws RuntimeException If deleting the Metalake encounters storage issues.+ */@Overridepublic boolean dropMetalake(NameIdentifier ident) {try {return store.delete(ident, EntityType.METALAKE);} catch (IOException ioe) {- LOG.error("Failed to delete metalake {} due to storage issues", ident, ioe);+ LOG.error("Deletinf metalake {} failed due to storage issues", ident, ioe);throw new RuntimeException(ioe);}}+ /**+ * Updates an entity with the provided changes.+ *+ * @param builder The builder for the entity.+ * @param newProps The new properties to apply.+ * @param changes The changes to apply.+ * @return The updated entity builder.+ * @throws IllegalArgumentException If an unknown MetalakeChange is encountered.+ */private BaseMetalake.Builder updateEntity(BaseMetalake.Builder builder, Map<String, String> newProps, MetalakeChange... changes) {for (MetalakeChange change : changes) {@@ -167,7 +223,7 @@ public class MetalakeManager implements SupportsMetalakes {newProps.remove(removeProperty.getProperty());} else {- throw new IllegalArgumentException("Unknown metalake change: " + change);+ throw new IllegalArgumentException("Unknown metalake change type: " + change);}}diff --git a/core/src/main/java/com/datastrato/graviton/meta/SchemaVersion.java b/core/src/main/java/com/datastrato/graviton/meta/SchemaVersion.javaindex 09346c278f..5be5b7dc8a 100644--- a/core/src/main/java/com/datastrato/graviton/meta/SchemaVersion.java+++ b/core/src/main/java/com/datastrato/graviton/meta/SchemaVersion.java@@ -4,6 +4,7 @@*/package com.datastrato.graviton.meta;+/** The major and minor versions of a schema. */public enum SchemaVersion {V_0_1(0, 1);@@ -11,6 +12,43 @@ public enum SchemaVersion {public final int minorVersion;+ /**+ * Constructs a SchemaVersion enum value with the provided version numbers.+ *+ * @param majorVersion The major version number.+ * @param minorVersion The minor version number.+ */+ SchemaVersion(int majorVersion, int minorVersion) {+ this.majorVersion = majorVersion;+ this.minorVersion = minorVersion;+ }++ /**+ * The major version number of the schema.+ *+ * @return The major version number.+ */+ public int getMajorVersion() {+ return majorVersion;+ }++ /**+ * The minor version number of the schema.+ *+ * @return The minor version number.+ */+ public int getMinorVersion() {+ return minorVersion;+ }++ /**+ * The SchemaVersion enum value corresponding to the provided major and minor version numbers.+ *+ * @param majorVersion The major version number.+ * @param minorVersion The minor version number.+ * @return The corresponding SchemaVersion enum value.+ * @throws IllegalArgumentException If no schema version is found.+ */public static SchemaVersion forValues(int majorVersion, int minorVersion) {for (SchemaVersion schemaVersion : SchemaVersion.values()) {if (schemaVersion.majorVersion == majorVersion@@ -24,17 +62,4 @@ public enum SchemaVersion {"No schema version found for major version %d and minor version %d",majorVersion, minorVersion));}-- SchemaVersion(int majorVersion, int minorVersion) {- this.majorVersion = majorVersion;- this.minorVersion = minorVersion;- }-- public int getMajorVersion() {- return majorVersion;- }-- public int getMinorVersion() {- return minorVersion;- }}diff --git a/core/src/main/java/com/datastrato/graviton/meta/rel/BaseColumn.java b/core/src/main/java/com/datastrato/graviton/meta/rel/BaseColumn.javaindex c566ab793f..c9d1c6a6aa 100644--- a/core/src/main/java/com/datastrato/graviton/meta/rel/BaseColumn.java+++ b/core/src/main/java/com/datastrato/graviton/meta/rel/BaseColumn.java@@ -2,6 +2,7 @@* Copyright 2023 Datastrato.* This software is licensed under the Apache License version 2.*/+package com.datastrato.graviton.meta.rel;import com.datastrato.graviton.Entity;@@ -14,13 +15,15 @@ import javax.annotation.Nullable;import lombok.EqualsAndHashCode;import lombok.ToString;+/** An abstract class representing a base column in a relational database. */@EqualsAndHashCode@ToStringpublic abstract class BaseColumn implements Column, Entity {- public static final Field NAME = Field.required("name", String.class, "The name of the column");+ public static final Field NAME = Field.required("name", String.class, "The column's name");public static final Field COMMENT =- Field.optional("comment", String.class, "The comment of the column");- public static final Field TYPE = Field.required("dataType", Type.class, "The type of the column");+ Field.optional("comment", String.class, "The comment or description for the column");+ public static final Field TYPE =+ Field.required("dataType", Type.class, "The data type of the column");protected String name;@@ -28,27 +31,52 @@ public abstract class BaseColumn implements Column, Entity {protected Type dataType;+ /**+ * Returns the name of the column.+ *+ * @return The name of the column.+ */@Overridepublic String name() {return name;}+ /**+ * Returns the data type of the column.+ *+ * @return The data type of the column.+ */@Overridepublic Type dataType() {return dataType;}+ /**+ * Returns the comment or description for the column.+ *+ * @return The comment or description for the column.+ */@Nullable@Overridepublic String comment() {return comment;}+ /**+ * Returns the type of the entity, which is {@link EntityType#COLUMN}.+ *+ * @return The type of the entity.+ */@Overridepublic EntityType type() {return EntityType.COLUMN;}+ /**+ * Returns a map of the fields and their corresponding values for this column.+ *+ * @return A map of the fields and values.+ */@Overridepublic Map<Field, Object> fields() {Map<Field, Object> fields = Maps.newHashMap();@@ -59,6 +87,12 @@ public abstract class BaseColumn implements Column, Entity {return fields;}+ /**+ * Builder interface for creating instances of {@link BaseColumn}.+ *+ * @param <SELF> The type of the builder.+ * @param <T> The type of the column being built.+ */interface Builder<SELF extends BaseColumn.Builder<SELF, T>, T extends BaseColumn> {SELF withName(String name);@@ -69,6 +103,12 @@ public abstract class BaseColumn implements Column, Entity {T build();}+ /**+ * An abstract class implementing the builder interface for {@link BaseColumn}.+ *+ * @param <SELF> The type of the builder.+ * @param <T> The type of the column being built.+ */public abstract static class BaseColumnBuilder<SELF extends BaseColumn.Builder<SELF, T>, T extends BaseColumn>implements BaseColumn.Builder<SELF, T> {@@ -76,24 +116,47 @@ public abstract class BaseColumn implements Column, Entity {protected String comment;protected Type dataType;+ /**+ * Sets the name of the column.+ *+ * @param name The name of the column.+ * @return The builder instance.+ */@Overridepublic SELF withName(String name) {this.name = name;return self();}+ /**+ * Sets the comment of the column.+ *+ * @param comment The comment or description for the column.+ * @return The builder instance.+ */@Overridepublic SELF withComment(String comment) {this.comment = comment;return self();}+ /**+ * Sets the data type of the column.+ *+ * @param dataType The data type of the column.+ * @return The builder instance.+ */@Overridepublic SELF withType(Type dataType) {this.dataType = dataType;return self();}+ /**+ * Builds the instance of the column with the provided attributes.+ *+ * @return The built column instance.+ */@Overridepublic T build() {T t = internalBuild();diff --git a/core/src/main/java/com/datastrato/graviton/meta/rel/BaseSchema.java b/core/src/main/java/com/datastrato/graviton/meta/rel/BaseSchema.javaindex 9fd9bb0529..64730614ae 100644--- a/core/src/main/java/com/datastrato/graviton/meta/rel/BaseSchema.java+++ b/core/src/main/java/com/datastrato/graviton/meta/rel/BaseSchema.java@@ -2,6 +2,7 @@* Copyright 2023 Datastrato.* This software is licensed under the Apache License version 2.*/+package com.datastrato.graviton.meta.rel;import com.datastrato.graviton.Entity;@@ -17,21 +18,21 @@ import javax.annotation.Nullable;import lombok.EqualsAndHashCode;import lombok.ToString;+/** An abstract class representing a base schema in a relational database. */@EqualsAndHashCode@ToStringpublic abstract class BaseSchema implements Schema, Entity, HasIdentifier {- public static final Field ID =- Field.required("id", Long.class, "The unique identifier of the schema");+ public static final Field ID = Field.required("id", Long.class, "The schema's unique identifier");public static final Field CATALOG_ID =- Field.required("catalog_id", Long.class, "The unique identifier of the catalog");- public static final Field NAME = Field.required("name", String.class, "The name of the schema");+ Field.required("catalog_id", Long.class, "The catalog's unique identifier");+ public static final Field NAME = Field.required("name", String.class, "The schema's name");public static final Field COMMENT =- Field.optional("comment", String.class, "The comment of the schema");+ Field.optional("comment", String.class, "The comment or description for the schema");public static final Field PROPERTIES =- Field.optional("properties", Map.class, "The properties of the schema");+ Field.optional("properties", Map.class, "The associated properties of the schema");public static final Field AUDIT_INFO =- Field.required("audit_info", AuditInfo.class, "The audit info of the schema");+ Field.required("audit_info", AuditInfo.class, "The audit details of the schema");protected Long id;@@ -47,6 +48,11 @@ public abstract class BaseSchema implements Schema, Entity, HasIdentifier {protected Namespace namespace;+ /**+ * Returns an unmodifiable map of the fields and their corresponding values for this schema.+ *+ * @return An unmodifiable map of the fields and values.+ */@Overridepublic Map<Field, Object> fields() {Map<Field, Object> fields = Maps.newHashMap();@@ -60,36 +66,72 @@ public abstract class BaseSchema implements Schema, Entity, HasIdentifier {return Collections.unmodifiableMap(fields);}+ /**+ * Returns the name of the schema.+ *+ * @return The name of the schema.+ */@Overridepublic String name() {return name;}+ /**+ * Returns the namespace of the schema.+ *+ * @return The namespace of the schema.+ */@Overridepublic Namespace namespace() {return namespace;}+ /**+ * Returns the comment or description for the schema.+ *+ * @return The comment or description for the schema.+ */@Overridepublic String comment() {return comment;}+ /**+ * Returns the associated properties of the schema.+ *+ * @return The associated properties of the schema.+ */@Overridepublic Map<String, String> properties() {return properties;}+ /**+ * Returns the audit details of the schema.+ *+ * @return The audit details of the schema.+ */@Overridepublic AuditInfo auditInfo() {return auditInfo;}+ /**+ * Returns the type of the entity, which is {@link EntityType#SCHEMA}.+ *+ * @return The type of the entity.+ */@Overridepublic EntityType type() {return EntityType.SCHEMA;}+ /**+ * Builder interface for creating instances of {@link BaseSchema}.+ *+ * @param <SELF> The type of the builder.+ * @param <T> The type of the schema being built.+ */interface Builder<SELF extends Builder<SELF, T>, T extends BaseSchema> {SELF withId(Long id);@@ -108,6 +150,12 @@ public abstract class BaseSchema implements Schema, Entity, HasIdentifier {T build();}+ /**+ * An abstract class implementing the builder interface for {@link BaseSchema}.+ *+ * @param <SELF> The type of the builder.+ * @param <T> The type of the schema being built.+ */public abstract static class BaseSchemaBuilder<SELF extends Builder<SELF, T>, T extends BaseSchema>implements Builder<SELF, T> {@@ -119,48 +167,95 @@ public abstract class BaseSchema implements Schema, Entity, HasIdentifier {protected Map<String, String> properties;protected AuditInfo auditInfo;+ /**+ * Sets the unique identifier of the schema.+ *+ * @param id The unique identifier of the schema.+ * @return The builder instance.+ */@Overridepublic SELF withId(Long id) {this.id = id;return self();}+ /**+ * Sets the unique identifier of the catalog.+ *+ * @param catalogId The unique identifier of the catalog.+ * @return The builder instance.+ */@Overridepublic SELF withCatalogId(Long catalogId) {this.catalogId = catalogId;return self();}+ /**+ * Sets the name of the schema.+ *+ * @param name The name of the schema.+ * @return The builder instance.+ */@Overridepublic SELF withName(String name) {this.name = name;return self();}+ /**+ * Sets the namespace of the schema.+ *+ * @param namespace The namespace of the schema.+ * @return The builder instance.+ */@Overridepublic SELF withNamespace(Namespace namespace) {this.namespace = namespace;return self();}+ /**+ * Sets the comment of the schema.+ *+ * @param comment The comment or description for the schema.+ * @return The builder instance.+ */@Overridepublic SELF withComment(String comment) {this.comment = comment;return self();}+ /**+ * Sets the associated properties of the schema.+ *+ * @param properties The associated properties of the schema.+ * @return The builder instance.+ */@Overridepublic SELF withProperties(Map<String, String> properties) {this.properties = properties;return self();}+ /**+ * Sets the audit details of the schema.+ *+ * @param auditInfo The audit details of the schema.+ * @return The builder instance.+ */@Overridepublic SELF withAuditInfo(AuditInfo auditInfo) {this.auditInfo = auditInfo;return self();}+ /**+ * Builds the instance of the schema with the provided attributes.+ *+ * @return The built schema instance.+ */@Overridepublic T build() {T t = internalBuild();diff --git a/core/src/main/java/com/datastrato/graviton/meta/rel/BaseTable.java b/core/src/main/java/com/datastrato/graviton/meta/rel/BaseTable.javaindex 729ee8fb2b..5619f48445 100644--- a/core/src/main/java/com/datastrato/graviton/meta/rel/BaseTable.java+++ b/core/src/main/java/com/datastrato/graviton/meta/rel/BaseTable.java@@ -2,6 +2,7 @@* Copyright 2023 Datastrato.* This software is licensed under the Apache License version 2.*/+package com.datastrato.graviton.meta.rel;import com.datastrato.graviton.Audit;@@ -18,23 +19,23 @@ import javax.annotation.Nullable;import lombok.EqualsAndHashCode;import lombok.ToString;+/** An abstract class representing a base table in a relational database. */@EqualsAndHashCode@ToStringpublic abstract class BaseTable implements Table, Entity, HasIdentifier {- public static final Field ID =- Field.required("id", Long.class, "The unique identifier of the table");+ public static final Field ID = Field.required("id", Long.class, "The table's unique identifier");public static final Field SCHEMA_ID =- Field.required("schema_id", Long.class, "The unique identifier of the schema");- public static final Field NAME = Field.required("name", String.class, "The name of the table");+ Field.required("schema_id", Long.class, "The schema's unique identifier");+ public static final Field NAME = Field.required("name", String.class, "The table's name");public static final Field COMMENT =- Field.optional("comment", String.class, "The comment of the table");+ Field.optional("comment", String.class, "The comment or description for the table");public static final Field PROPERTIES =- Field.optional("properties", Map.class, "The properties of the table");+ Field.optional("properties", Map.class, "The associated properties of the table");public static final Field AUDIT_INFO =- Field.required("audit_info", AuditInfo.class, "The audit info of the table");+ Field.required("audit_info", AuditInfo.class, "The audit details of the table");public static final Field COLUMNS =- Field.required("columns", Column[].class, "The columns of the table");+ Field.required("columns", Column[].class, "The columns that make up the table");protected Long id;@@ -52,6 +53,11 @@ public abstract class BaseTable implements Table, Entity, HasIdentifier {protected Namespace namespace;+ /**+ * Returns a map of the fields and their corresponding values for this table.+ *+ * @return A map of the fields and values.+ */@Overridepublic Map<Field, Object> fields() {Map<Field, Object> fields = Maps.newHashMap();@@ -66,42 +72,83 @@ public abstract class BaseTable implements Table, Entity, HasIdentifier {return fields;}+ /**+ * Returns the audit details of the table.+ *+ * @return The audit details of the table.+ */@Overridepublic Audit auditInfo() {return auditInfo;}+ /**+ * Returns the name of the table.+ *+ * @return The name of the table.+ */@Overridepublic String name() {return name;}+ /**+ * Returns an array of columns that make up the table.+ *+ * @return An array of columns.+ */@Overridepublic Column[] columns() {return columns;}+ /**+ * Returns the comment or description for the table.+ *+ * @return The comment or description for the table.+ */@Nullable@Overridepublic String comment() {return comment;}+ /**+ * Returns the associated properties of the table.+ *+ * @return The associated properties of the table.+ */@Overridepublic Map<String, String> properties() {return properties;}+ /**+ * Returns the namespace of the table.+ *+ * @return The namespace of the table.+ */@Overridepublic Namespace namespace() {return namespace;}+ /**+ * Returns the type of the entity, which is {@link EntityType#TABLE}.+ *+ * @return The type of the entity.+ */@Overridepublic EntityType type() {return EntityType.TABLE;}+ /**+ * Builder interface for creating instances of {@link BaseTable}.+ *+ * @param <SELF> The type of the builder.+ * @param <T> The type of the table being built.+ */interface Builder<SELF extends Builder<SELF, T>, T extends BaseTable> {SELF withId(Long id);@@ -122,6 +169,12 @@ public abstract class BaseTable implements Table, Entity, HasIdentifier {T build();}+ /**+ * An abstract class implementing the builder interface for {@link BaseTable}.+ *+ * @param <SELF> The type of the builder.+ * @param <T> The type of the table being built.+ */public abstract static class BaseTableBuilder<SELF extends Builder<SELF, T>, T extends BaseTable>implements Builder<SELF, T> {protected Long id;@@ -133,54 +186,107 @@ public abstract class BaseTable implements Table, Entity, HasIdentifier {protected AuditInfo auditInfo;protected Column[] columns;+ /**+ * Sets the unique identifier of the table.+ *+ * @param id The unique identifier of the table.+ * @return The builder instance.+ */@Overridepublic SELF withId(Long id) {this.id = id;return self();}+ /**+ * Sets the unique identifier of the schema.+ *+ * @param schemaId The unique identifier of the schema.+ * @return The builder instance.+ */@Overridepublic SELF withSchemaId(Long schemaId) {this.schemaId = schemaId;return self();}+ /**+ * Sets the namespace of the table.+ *+ * @param namespace The namespace of the table.+ * @return The builder instance.+ */@Overridepublic SELF withNameSpace(Namespace namespace) {this.namespace = namespace;return self();}+ /**+ * Sets the name of the table.+ *+ * @param name The name of the table.+ * @return The builder instance.+ */@Overridepublic SELF withName(String name) {this.name = name;return self();}+ /**+ * Sets the comment of the table.+ *+ * @param comment The comment or description for the table.+ * @return The builder instance.+ */@Overridepublic SELF withComment(String comment) {this.comment = comment;return self();}+ /**+ * Sets the columns that make up the table.+ *+ * @param columns The columns that make up the table.+ * @return The builder instance.+ */@Overridepublic SELF withColumns(Column[] columns) {this.columns = columns;return self();}+ /**+ * Sets the associated properties of the table.+ *+ * @param properties The associated properties of the table.+ * @return The builder instance.+ */@Overridepublic SELF withProperties(Map<String, String> properties) {this.properties = properties;return self();}+ /**+ * Sets the audit details of the table.+ *+ * @param auditInfo The audit details of the table.+ * @return The builder instance.+ */@Overridepublic SELF withAuditInfo(AuditInfo auditInfo) {this.auditInfo = auditInfo;return self();}+ /**+ * Builds the instance of the table with the provided attributes.+ *+ * @return The built table instance.+ */@Overridepublic T build() {T t = internalBuild();diff --git a/core/src/main/java/com/datastrato/graviton/proto/AuditInfoSerDe.java b/core/src/main/java/com/datastrato/graviton/proto/AuditInfoSerDe.javaindex 2d581cbb29..2dd2584369 100644--- a/core/src/main/java/com/datastrato/graviton/proto/AuditInfoSerDe.java+++ b/core/src/main/java/com/datastrato/graviton/proto/AuditInfoSerDe.java@@ -2,9 +2,19 @@* Copyright 2023 Datastrato.* This software is licensed under the Apache License version 2.*/+package com.datastrato.graviton.proto;+/** A class for serializing and deserializing AuditInfo objects. */class AuditInfoSerDe implements ProtoSerDe<com.datastrato.graviton.meta.AuditInfo, AuditInfo> {++ /**+ * Serializes an {@link com.datastrato.graviton.meta.AuditInfo} object to a {@link AuditInfo}+ * object.+ *+ * @param auditInfo The AuditInfo object to be serialized.+ * @return The serialized AuditInfo object.+ */@Overridepublic AuditInfo serialize(com.datastrato.graviton.meta.AuditInfo auditInfo) {AuditInfo.Builder builder =@@ -21,6 +31,13 @@ class AuditInfoSerDe implements ProtoSerDe<com.datastrato.graviton.meta.AuditInfreturn builder.build();}+ /**+ * Deserializes a {@link AuditInfo} object to an {@link com.datastrato.graviton.meta.AuditInfo}+ * object.+ *+ * @param p The serialized AuditInfo object.+ * @return The deserialized AuditInfo object.+ */@Overridepublic com.datastrato.graviton.meta.AuditInfo deserialize(AuditInfo p) {com.datastrato.graviton.meta.AuditInfo.Builder builder =diff --git a/core/src/main/java/com/datastrato/graviton/proto/BaseMetalakeSerDe.java b/core/src/main/java/com/datastrato/graviton/proto/BaseMetalakeSerDe.javaindex d77525d875..46a66a9a41 100644--- a/core/src/main/java/com/datastrato/graviton/proto/BaseMetalakeSerDe.java+++ b/core/src/main/java/com/datastrato/graviton/proto/BaseMetalakeSerDe.java@@ -2,11 +2,21 @@* Copyright 2023 Datastrato.* This software is licensed under the Apache License version 2.*/+package com.datastrato.graviton.proto;import com.datastrato.graviton.meta.AuditInfo;+/** A class for serializing and deserializing BaseMetalake objects. */class BaseMetalakeSerDe implements ProtoSerDe<com.datastrato.graviton.meta.BaseMetalake, Metalake> {++ /**+ * Serializes a {@link com.datastrato.graviton.meta.BaseMetalake} object to a {@link Metalake}+ * object.+ *+ * @param baseMetalake The BaseMetalake object to be serialized.+ * @return The serialized Metalake object.+ */@Overridepublic Metalake serialize(com.datastrato.graviton.meta.BaseMetalake baseMetalake) {Metalake.Builder builder =@@ -33,6 +43,13 @@ class BaseMetalakeSerDe implements ProtoSerDe<com.datastrato.graviton.meta.BaseMreturn builder.build();}+ /**+ * Deserializes a {@link Metalake} object to a {@link com.datastrato.graviton.meta.BaseMetalake}+ * object.+ *+ * @param p The serialized Metalake object.+ * @return The deserialized BaseMetalake object.+ */@Overridepublic com.datastrato.graviton.meta.BaseMetalake deserialize(Metalake p) {com.datastrato.graviton.meta.BaseMetalake.Builder builder =diff --git a/core/src/main/java/com/datastrato/graviton/proto/CatalogEntitySerDe.java b/core/src/main/java/com/datastrato/graviton/proto/CatalogEntitySerDe.javaindex ace0443bc4..2bd7b77653 100644--- a/core/src/main/java/com/datastrato/graviton/proto/CatalogEntitySerDe.java+++ b/core/src/main/java/com/datastrato/graviton/proto/CatalogEntitySerDe.java@@ -2,12 +2,21 @@* Copyright 2023 Datastrato.* This software is licensed under the Apache License version 2.*/+package com.datastrato.graviton.proto;import com.datastrato.graviton.meta.AuditInfo;import com.datastrato.graviton.meta.CatalogEntity;+/** A class for serializing and deserializing CatalogEntity objects using Protocol Buffers. */public class CatalogEntitySerDe implements ProtoSerDe<CatalogEntity, Catalog> {++ /**+ * Serializes a {@link CatalogEntity} object to a {@link Catalog} object.+ *+ * @param catalogEntity The CatalogEntity object to be serialized.+ * @return The serialized Catalog object.+ */@Overridepublic Catalog serialize(CatalogEntity catalogEntity) {Catalog.Builder builder =@@ -29,10 +38,16 @@ public class CatalogEntitySerDe implements ProtoSerDe<CatalogEntity, Catalog> {com.datastrato.graviton.proto.Catalog.Type.valueOf(catalogEntity.getType().name());builder.setType(type);- // Attention we have ignored namespace field here+ // Note we have ignored the namespace field herereturn builder.build();}+ /**+ * Deserializes a {@link Catalog} object to a {@link CatalogEntity} object.+ *+ * @param p The serialized Catalog object.+ * @return The deserialized CatalogEntity object.+ */@Overridepublic CatalogEntity deserialize(Catalog p) {CatalogEntity.Builder builder = new CatalogEntity.Builder();diff --git a/core/src/main/java/com/datastrato/graviton/proto/ProtoSerDe.java b/core/src/main/java/com/datastrato/graviton/proto/ProtoSerDe.javaindex 75550ff737..9e225f1924 100644--- a/core/src/main/java/com/datastrato/graviton/proto/ProtoSerDe.java+++ b/core/src/main/java/com/datastrato/graviton/proto/ProtoSerDe.java@@ -6,9 +6,27 @@ package com.datastrato.graviton.proto;import com.google.protobuf.Message;+/**+ * This interface defines the contract for a Protocol Buffer Serializer and Deserializer (SerDe).+ *+ * @param <T> The entity type to be serialized and deserialized.+ * @param <M> The Protocol Buffer message type representing the entity.+ */public interface ProtoSerDe<T, M extends Message> {+ /**+ * Serializes the provided entity into its corresponding Protocol Buffer message representation.+ *+ * @param t The entity to be serialized.+ * @return The Protocol Buffer message representing the serialized entity.+ */M serialize(T t);+ /**+ * Deserializes the provided Protocol Buffer message into its corresponding entity representation.+ *+ * @param p The Protocol Buffer message to be deserialized.+ * @return The entity representing the deserialized Protocol Buffer message.+ */T deserialize(M p);}diff --git a/core/src/main/java/com/datastrato/graviton/proto/ProtoSerDeException.java b/core/src/main/java/com/datastrato/graviton/proto/ProtoSerDeException.javaindex bf93bbd647..39ee611571 100644--- a/core/src/main/java/com/datastrato/graviton/proto/ProtoSerDeException.java+++ b/core/src/main/java/com/datastrato/graviton/proto/ProtoSerDeException.java@@ -4,12 +4,26 @@*/package com.datastrato.graviton.proto;+/**+ * Custom exception class for Protocol Buffer Serializer and Deserializer (SerDe) related errors.+ */public class ProtoSerDeException extends RuntimeException {+ /**+ * Constructs a new ProtoSerDeException.+ *+ * @param message The error message.+ */public ProtoSerDeException(String message) {super(message);}+ /**+ * Constructs a new ProtoSerDeException.+ *+ * @param message The error message.+ * @param cause The underlying cause of the exception.+ */public ProtoSerDeException(String message, Throwable cause) {super(message, cause);}diff --git a/core/src/main/java/com/datastrato/graviton/proto/ProtoUtils.java b/core/src/main/java/com/datastrato/graviton/proto/ProtoUtils.javaindex 2ab6213c24..682358b5c9 100644--- a/core/src/main/java/com/datastrato/graviton/proto/ProtoUtils.java+++ b/core/src/main/java/com/datastrato/graviton/proto/ProtoUtils.java@@ -7,10 +7,17 @@ package com.datastrato.graviton.proto;import com.google.protobuf.Timestamp;import java.time.Instant;+/** Utility class for converting between Java Instant and Protocol Buffer Timestamp. */public class ProtoUtils {private ProtoUtils() {}+ /**+ * Converts a Java Instant object to a Protocol Buffer Timestamp object.+ *+ * @param instant The Java Instant to convert.+ * @return The corresponding Protocol Buffer Timestamp.+ */public static Timestamp fromInstant(Instant instant) {return Timestamp.newBuilder().setSeconds(instant.getEpochSecond())@@ -18,6 +25,12 @@ public class ProtoUtils {.build();}+ /**+ * Converts a Protocol Buffer Timestamp object to a Java Instant object.+ *+ * @param timestamp The Protocol Buffer Timestamp to convert.+ * @return The corresponding Java Instant.+ */public static Instant toInstant(Timestamp timestamp) {return Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos());}diff --git a/core/src/main/java/com/datastrato/graviton/storage/kv/CustomEntityKeyEncoder.java b/core/src/main/java/com/datastrato/graviton/storage/kv/CustomEntityKeyEncoder.javaindex a74abecb15..83ae8b30e1 100644--- a/core/src/main/java/com/datastrato/graviton/storage/kv/CustomEntityKeyEncoder.java+++ b/core/src/main/java/com/datastrato/graviton/storage/kv/CustomEntityKeyEncoder.java@@ -9,7 +9,7 @@ import static com.datastrato.graviton.Entity.EntityType.METALAKE;import static com.datastrato.graviton.Entity.EntityType.SCHEMA;import static com.datastrato.graviton.Entity.EntityType.TABLE;-import com.datastrato.graviton.Entity.EntityIdentifer;+import com.datastrato.graviton.Entity.EntityIdentifier;import com.datastrato.graviton.Entity.EntityType;import com.datastrato.graviton.NameIdentifier;import com.datastrato.graviton.NoSuchEntityException;@@ -144,7 +144,7 @@ public class CustomEntityKeyEncoder implements EntityKeyEncoder {* @param entityIdentifier the entity identifier to encode* @return the encoded key for key-value storage*/- private byte[] encodeEntity(EntityIdentifer entityIdentifier, boolean createIdIfNotExists)+ private byte[] encodeEntity(EntityIdentifier entityIdentifier, boolean createIdIfNotExists)throws IOException {EntityType entityType = entityIdentifier.getEntityType();String[] nameSpace = entityIdentifier.getNameIdentifier().namespace().levels();@@ -228,9 +228,15 @@ public class CustomEntityKeyEncoder implements EntityKeyEncoder {return maxByte == null ? 0 : ByteUtils.byteToLong(maxByte) + 1;}+ /**+ * Encodes a Namespace object into a byte array for use as a key in a key-value store.+ *+ * @param namespace The Namespace object to be encoded.+ * @return The byte array representing the encoded key.+ */@Override- public byte[] encode(EntityIdentifer entityIdentifer, boolean createIdIfNotExists)+ public byte[] encode(EntityIdentifier entityIdentifier, boolean createIdIfNotExists)throws IOException {- return encodeEntity(entityIdentifer, createIdIfNotExists);+ return encodeEntity(entityIdentifier, createIdIfNotExists);}}diff --git a/core/src/main/java/com/datastrato/graviton/storage/kv/EntityKeyEncoder.java b/core/src/main/java/com/datastrato/graviton/storage/kv/EntityKeyEncoder.javaindex 1945adfe19..bd083c280b 100644--- a/core/src/main/java/com/datastrato/graviton/storage/kv/EntityKeyEncoder.java+++ b/core/src/main/java/com/datastrato/graviton/storage/kv/EntityKeyEncoder.java@@ -5,7 +5,7 @@package com.datastrato.graviton.storage.kv;-import com.datastrato.graviton.Entity.EntityIdentifer;+import com.datastrato.graviton.Entity.EntityIdentifier;import java.io.IOException;/**@@ -13,14 +13,13 @@ import java.io.IOException;* entity in the backend.*/public interface EntityKeyEncoder {-/*** Construct the key for key-value store from the entity NameIdentifier and EntityType.*- * @param entityIdentifer entity identifier+ * @param entityIdentifier entity identifier* @param createIdIfNotExists create the id mapping for name if not exists* @return encoded key for key-value store* @throws IOException*/- byte[] encode(EntityIdentifer entityIdentifer, boolean createIdIfNotExists) throws IOException;+ byte[] encode(EntityIdentifier entityIdentifier, boolean createIdIfNotExists) throws IOException;}diff --git a/core/src/main/java/com/datastrato/graviton/storage/kv/KvBackend.java b/core/src/main/java/com/datastrato/graviton/storage/kv/KvBackend.javaindex 06efd01471..fc428877c6 100644--- a/core/src/main/java/com/datastrato/graviton/storage/kv/KvBackend.java+++ b/core/src/main/java/com/datastrato/graviton/storage/kv/KvBackend.java@@ -13,47 +13,66 @@ import java.io.IOException;import java.util.List;import org.apache.commons.lang3.tuple.Pair;+/** Interface defining the operations for a Key-Value (KV) Backend. */public interface KvBackend extends Closeable {/**- * Init KvBackend environment+ * Initializes the KV Backend environment with the provided configuration.*- * @param config configuration for the backend+ * @param config The configuration for the backend.+ * @throws IOException If an I/O exception occurs during initialization.*/void initialize(Config config) throws IOException;/**- * Store a key value pair ignoring any existing value if overwrite is true. Once the value is- * false, it will throw {@link EntityAlreadyExistsException} if the key already exists+ * Stores a key-value pair, possibly overwriting an existing value if specified.*- * @param key key of the pair- * @param value value of the pair- * @param overwrite if true, overwrite existing value+ * @param key The key of the pair.+ * @param value The value of the pair.+ * @param overwrite If true, overwrites the existing value.+ * @throws IOException If an I/O exception occurs during the operation.+ * @throws EntityAlreadyExistsException If the key already exists and overwrite is false.*/void put(byte[] key, byte[] value, boolean overwrite)throws IOException, EntityAlreadyExistsException;- /** Get a value pair for a key, Null if the key does not exist */+ /**+ * Retrieves the value associated with a given key.+ *+ * @param key The key to retrieve the value for.+ * @return The value associated with the key, or null if the key does not exist.+ * @throws IOException If an I/O exception occurs during retrieval.+ */byte[] get(byte[] key) throws IOException;- /** Delete key value pair */+ /**+ * Deletes the key-value pair associated with the given key.+ *+ * @param key The key to delete.+ * @return True if the key-value pair was successfully deleted, false if the key was not found.+ * @throws IOException If an I/O exception occurs during deletion.+ */default boolean delete(byte[] key) throws IOException {return false;}/**- * Scan the range represented by {@link KvRangeScan} and return the list of key value pairs+ * Scans the specified range using the provided KvRangeScan and returns a list of key-value pairs.*- * @param scanRange range to scan- * @return List of key value pairs- * @throws IOException if exectiopn occurs+ * @param scanRange The range to scan.+ * @return A list of key-value pairs within the specified range.+ * @throws IOException If an I/O exception occurs during scanning.*/List<Pair<byte[], byte[]>> scan(KvRangeScan scanRange) throws IOException;/**- * Do a transactional operation on the backend+ * Executes a transactional operation on the KV backend.*- * @param executable- * @throws IOException+ * @param executable The executable operation to perform transactionally.+ * @param <R> The type of the result.+ * @param <E> The type of exception that the executable may throw.+ * @return The result of the transactional operation.+ * @throws E If the executable throws an exception.+ * @throws IOException If an I/O exception occurs during the transaction.*/<R, E extends Exception> R executeInTransaction(Executable<R, E> executable)throws E, IOException;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.javaindex a2c509910d..53f4e48794 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@@ -9,7 +9,7 @@ import static com.datastrato.graviton.Configs.ENTITY_KV_STORE;import com.datastrato.graviton.Config;import com.datastrato.graviton.Entity;-import com.datastrato.graviton.Entity.EntityIdentifer;+import com.datastrato.graviton.Entity.EntityIdentifier;import com.datastrato.graviton.Entity.EntityType;import com.datastrato.graviton.EntityAlreadyExistsException;import com.datastrato.graviton.EntitySerDe;@@ -62,7 +62,7 @@ public class KvEntityStore implements EntityStore {Namespace namespace, Class<E> e, EntityType type) throws IOException {// Star means it's a wildcardNameIdentifier identifier = NameIdentifier.of(namespace, "*");- byte[] startKey = entityKeyEncoder.encode(EntityIdentifer.of(identifier, type), false);+ byte[] startKey = entityKeyEncoder.encode(EntityIdentifier.of(identifier, type), false);byte[] endKey = Bytes.increment(Bytes.wrap(startKey)).get();List<Pair<byte[], byte[]>> kvs =backend.scan(@@ -84,17 +84,18 @@ public class KvEntityStore implements EntityStore {@Overridepublic boolean exists(NameIdentifier ident, EntityType entityType) throws IOException {- return backend.get(entityKeyEncoder.encode(EntityIdentifer.of(ident, entityType), false))+ return backend.get(entityKeyEncoder.encode(EntityIdentifier.of(ident, entityType), false))!= null;}@Overridepublic <E extends Entity & HasIdentifier> void put(E e, boolean overwritten)throws IOException, EntityAlreadyExistsException {+ // Simple implementation, just use the entity's identifier as the keyexecuteInTransaction(() -> {byte[] key =- entityKeyEncoder.encode(EntityIdentifer.of(e.nameIdentifier(), e.type()), true);+ entityKeyEncoder.encode(EntityIdentifier.of(e.nameIdentifier(), e.type()), true);byte[] value = serDe.serialize(e);backend.put(key, value, overwritten);return null;@@ -107,7 +108,7 @@ public class KvEntityStore implements EntityStore {throws IOException, NoSuchEntityException {return executeInTransaction(() -> {- byte[] key = entityKeyEncoder.encode(EntityIdentifer.of(ident, entityType), false);+ byte[] key = entityKeyEncoder.encode(EntityIdentifier.of(ident, entityType), false);byte[] value = backend.get(key);if (value == null) {throw new NoSuchEntityException(ident.toString());@@ -128,7 +129,7 @@ public class KvEntityStore implements EntityStore {public <E extends Entity & HasIdentifier> E get(NameIdentifier ident, EntityType entityType, Class<E> e)throws NoSuchEntityException, IOException {- byte[] key = entityKeyEncoder.encode(EntityIdentifer.of(ident, entityType), false);+ byte[] key = entityKeyEncoder.encode(EntityIdentifier.of(ident, entityType), false);// refer type from key;byte[] value = backend.get(key);if (value == null) {@@ -139,7 +140,7 @@ public class KvEntityStore implements EntityStore {@Overridepublic boolean delete(NameIdentifier ident, EntityType entityType) throws IOException {- return backend.delete(entityKeyEncoder.encode(EntityIdentifer.of(ident, entityType), false));+ return backend.delete(entityKeyEncoder.encode(EntityIdentifier.of(ident, entityType), false));}@Overridediff --git a/core/src/main/java/com/datastrato/graviton/storage/kv/KvRangeScan.java b/core/src/main/java/com/datastrato/graviton/storage/kv/KvRangeScan.javaindex f87af11672..3637ff20e0 100644--- a/core/src/main/java/com/datastrato/graviton/storage/kv/KvRangeScan.java+++ b/core/src/main/java/com/datastrato/graviton/storage/kv/KvRangeScan.java@@ -8,6 +8,7 @@ package com.datastrato.graviton.storage.kv;import lombok.Builder;import lombok.Data;+/** Represents a range scan configuration for the key-value store. */@Builder@Datapublic class KvRangeScan {@@ -17,4 +18,23 @@ public class KvRangeScan {private boolean endInclusive;private int limit;++ /**+ * Constructs a KvRangeScan instance with the specified parameters.+ *+ * @param start The start key of the range.+ * @param end The end key of the range.+ * @param startInclusive True if the start key is inclusive, false otherwise.+ * @param endInclusive True if the end key is inclusive, false otherwise.+ * @param limit The maximum number of results to retrieve.+ */+ @Builder+ public KvRangeScan(+ byte[] start, byte[] end, boolean startInclusive, boolean endInclusive, int limit) {+ this.start = start;+ this.end = end;+ this.startInclusive = startInclusive;+ this.endInclusive = endInclusive;+ this.limit = limit;+ }}diff --git a/core/src/main/java/com/datastrato/graviton/util/ByteUtils.java b/core/src/main/java/com/datastrato/graviton/util/ByteUtils.javaindex e27c6e6bba..dafe49e366 100644--- a/core/src/main/java/com/datastrato/graviton/util/ByteUtils.java+++ b/core/src/main/java/com/datastrato/graviton/util/ByteUtils.java@@ -8,7 +8,15 @@ package com.datastrato.graviton.util;import java.nio.ByteBuffer;import java.nio.ByteOrder;+/** Utility class containing methods to convert between primitive types and byte arrays. */public class ByteUtils {++ /**+ * Converts an integer value to a byte array representation.+ *+ * @param v The integer value to convert.+ * @return A byte array representation of the integer value.+ */public static byte[] intToByte(int v) {ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);buffer.order(ByteOrder.BIG_ENDIAN);@@ -16,6 +24,12 @@ public class ByteUtils {return buffer.array();}+ /**+ * Converts a long value to a byte array representation.+ *+ * @param v The long value to convert.+ * @return A byte array representation of the long value.+ */public static byte[] longToByte(long v) {ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);buffer.order(ByteOrder.BIG_ENDIAN);@@ -23,6 +37,12 @@ public class ByteUtils {return buffer.array();}+ /**+ * Converts a byte array to an integer value.+ *+ * @param bytes The byte array to convert.+ * @return The integer value obtained from the byte array.+ */public static int byteToInt(byte[] bytes) {ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);buffer.order(ByteOrder.BIG_ENDIAN);@@ -31,6 +51,12 @@ public class ByteUtils {return buffer.getInt();}+ /**+ * Converts a byte array to a long value.+ *+ * @param bytes The byte array to convert.+ * @return The long value obtained from the byte array.+ */public static long byteToLong(byte[] bytes) {ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);buffer.order(ByteOrder.BIG_ENDIAN);diff --git a/core/src/main/java/com/datastrato/graviton/util/Bytes.java b/core/src/main/java/com/datastrato/graviton/util/Bytes.javaindex 913766429f..343027d4cc 100644--- a/core/src/main/java/com/datastrato/graviton/util/Bytes.java+++ b/core/src/main/java/com/datastrato/graviton/util/Bytes.java@@ -48,7 +48,12 @@ public class Bytes implements Comparable<byte[]> {return this.bytes;}- /** Concat byte arrays into one. */+ /**+ * Concatenates multiple byte arrays into a single byte array.+ *+ * @param values An array of byte arrays to be concatenated.+ * @return A new byte array containing the concatenated data.+ */public static byte[] concat(byte[]... values) {int totalLen = 0;for (byte[] b : values) {diff --git a/core/src/main/java/com/datastrato/graviton/util/IsolatedClassLoader.java b/core/src/main/java/com/datastrato/graviton/util/IsolatedClassLoader.javaindex faef5a0d71..ea81b99f9f 100644--- a/core/src/main/java/com/datastrato/graviton/util/IsolatedClassLoader.java+++ b/core/src/main/java/com/datastrato/graviton/util/IsolatedClassLoader.java@@ -17,6 +17,10 @@ import org.apache.commons.lang3.SystemUtils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;+/**+ * IsolatedClassLoader provides a mechanism for creating an isolated class loader that allows+ * controlled loading of classes from specified jars and shared classes from the base class loader.+ */public class IsolatedClassLoader implements Closeable {private static final Logger LOG = LoggerFactory.getLogger(IsolatedClassLoader.class);@@ -31,6 +35,14 @@ public class IsolatedClassLoader implements Closeable {private final ClassLoader baseClassLoader;+ /**+ * Constructs an IsolatedClassLoader with the provided parameters.+ *+ * @param execJars List of URLs representing the executable jars to load classes from.+ * @param sharedClasses List of fully qualified class names to be shared with the base class+ * loader.+ * @param barrierClasses List of fully qualified class names to be loaded in an isolated manner.+ */public IsolatedClassLoader(List<URL> execJars, List<String> sharedClasses, List<String> barrierClasses) {this.execJars = execJars;@@ -39,6 +51,14 @@ public class IsolatedClassLoader implements Closeable {this.baseClassLoader = Thread.currentThread().getContextClassLoader();}+ /**+ * Executes the provided function within the isolated class loading context.+ *+ * @param fn The function to be executed within the isolated class loading context.+ * @param <T> The return type of the function.+ * @return The result of the executed function.+ * @throws Exception if an error occurs during the execution.+ */public <T> T withClassLoader(ThrowableFunction<ClassLoader, T> fn) throws Exception {ClassLoader original = Thread.currentThread().getContextClassLoader();Thread.currentThread().setContextClassLoader(classLoader());@@ -49,6 +69,7 @@ public class IsolatedClassLoader implements Closeable {}}+ /** Closes the class loader. */@Overridepublic void close() {try {@@ -106,6 +127,12 @@ public class IsolatedClassLoader implements Closeable {return classLoader;}+ /**+ * Checks if a given class name belongs to a shared class.+ *+ * @param name The fully qualified class name.+ * @return true if the class is shared, false otherwise.+ */private boolean isSharedClass(String name) {return name.startsWith("org.slf4j")|| name.startsWith("org.apache.log4j")@@ -116,6 +143,12 @@ public class IsolatedClassLoader implements Closeable {|| sharedClasses.stream().anyMatch(name::startsWith);}+ /**+ * Checks if a given class name belongs to a barrier class.+ *+ * @param name The fully qualified class name.+ * @return true if the class is a barrier class, false otherwise.+ */private boolean isBarrierClass(String name) {// We need to add more later on when we have more catalog implementations.return name.startsWith(BaseSchema.class.getName())diff --git a/core/src/test/java/com/datastrato/graviton/meta/TestAuditInfo.java b/core/src/test/java/com/datastrato/graviton/meta/TestAuditInfo.javaindex 8e8df09062..12a2ada96e 100644--- a/core/src/test/java/com/datastrato/graviton/meta/TestAuditInfo.java+++ b/core/src/test/java/com/datastrato/graviton/meta/TestAuditInfo.java@@ -61,7 +61,7 @@ public class TestAuditInfo {.build();});Assertions.assertEquals(- "last_modifier and last_modified_time must be both set or both not set",+ "last_modifier and last_modified_time must be both set or both left unset",exception1.getMessage());}}diff --git a/core/src/test/java/com/datastrato/graviton/storage/kv/TestEntityKeyEncoding.java b/core/src/test/java/com/datastrato/graviton/storage/kv/TestEntityKeyEncoding.javaindex c501cc7fa2..0189241e61 100644--- a/core/src/test/java/com/datastrato/graviton/storage/kv/TestEntityKeyEncoding.java+++ b/core/src/test/java/com/datastrato/graviton/storage/kv/TestEntityKeyEncoding.java@@ -14,7 +14,7 @@ import static com.datastrato.graviton.storage.kv.CustomEntityKeyEncoder.WILD_CARimport com.datastrato.graviton.Config;import com.datastrato.graviton.Configs;-import com.datastrato.graviton.Entity.EntityIdentifer;+import com.datastrato.graviton.Entity.EntityIdentifier;import com.datastrato.graviton.Entity.EntityType;import com.datastrato.graviton.EntitySerDeFactory;import com.datastrato.graviton.EntityStore;@@ -112,7 +112,7 @@ public class TestEntityKeyEncoding {NameIdentifier mateLakeIdentifier1 = NameIdentifier.of(namespace, "metalake1");byte[] realKey =- mockEncoder.encode(EntityIdentifer.of(mateLakeIdentifier1, EntityType.METALAKE), true);+ mockEncoder.encode(EntityIdentifier.of(mateLakeIdentifier1, EntityType.METALAKE), true);byte[] expenctKey =Bytes.concat(EntityType.METALAKE.getShortName().getBytes(),@@ -133,7 +133,7 @@ public class TestEntityKeyEncoding {for (int i = 0; i < catalogIdentifiers.length; i++) {NameIdentifier identifier = catalogIdentifiers[i];- realKey = mockEncoder.encode(EntityIdentifer.of(identifier, EntityType.CATALOG), true);+ realKey = mockEncoder.encode(EntityIdentifier.of(identifier, EntityType.CATALOG), true);expenctKey =Bytes.concat(EntityType.CATALOG.getShortName().getBytes(),@@ -159,7 +159,7 @@ public class TestEntityKeyEncoding {for (int i = 0; i < schemaIdentifiers.length; i++) {NameIdentifier identifier = schemaIdentifiers[i];- realKey = mockEncoder.encode(EntityIdentifer.of(identifier, EntityType.SCHEMA), true);+ realKey = mockEncoder.encode(EntityIdentifier.of(identifier, EntityType.SCHEMA), true);expenctKey =Bytes.concat(EntityType.SCHEMA.getShortName().getBytes(),@@ -187,7 +187,7 @@ public class TestEntityKeyEncoding {for (int i = 0; i < tableIdentifiers.length; i++) {NameIdentifier identifier = tableIdentifiers[i];- realKey = mockEncoder.encode(EntityIdentifer.of(identifier, EntityType.TABLE), true);+ realKey = mockEncoder.encode(EntityIdentifier.of(identifier, EntityType.TABLE), true);expenctKey =Bytes.concat(EntityType.TABLE.getShortName().getBytes(),@@ -209,7 +209,7 @@ public class TestEntityKeyEncoding {UnsupportedOperationException.class,() -> {mockEncoder.encode(- EntityIdentifer.of(+ EntityIdentifier.of(NameIdentifier.of(Namespace.of("metalake1", "catalog2", "schema3", "table1"), "column1"),EntityType.COLUMN),@@ -230,7 +230,8 @@ public class TestEntityKeyEncoding {Assertions.assertThrows(IOException.class,() ->- mockEncoder.encode(EntityIdentifer.of(mateLakeIdentifier1, EntityType.METALAKE), true));+ mockEncoder.encode(+ EntityIdentifier.of(mateLakeIdentifier1, EntityType.METALAKE), true));}@Test@@ -259,7 +260,7 @@ public class TestEntityKeyEncoding {NameIdentifier metalakeIdentifier = NameIdentifier.of(namespace, WILD_CARD);byte[] realKey =- mockEncoder.encode(EntityIdentifer.of(metalakeIdentifier, EntityType.METALAKE), true);+ mockEncoder.encode(EntityIdentifier.of(metalakeIdentifier, EntityType.METALAKE), true);byte[] expenctKey =Bytes.concat(EntityType.METALAKE.getShortName().getBytes(), NAMESPACE_SEPARATOR);Assertions.assertArrayEquals(expenctKey, realKey);@@ -268,7 +269,7 @@ public class TestEntityKeyEncoding {// metalake1 --> 1000000LNamespace catalogNamespace = Namespace.of("metalake1");NameIdentifier catalogIdentifier = NameIdentifier.of(catalogNamespace, WILD_CARD);- realKey = mockEncoder.encode(EntityIdentifer.of(catalogIdentifier, EntityType.CATALOG), true);+ realKey = mockEncoder.encode(EntityIdentifier.of(catalogIdentifier, EntityType.CATALOG), true);expenctKey =Bytes.concat(EntityType.CATALOG.getShortName().getBytes(),@@ -283,7 +284,7 @@ public class TestEntityKeyEncoding {// catalog2 --> 0Namespace schemaNameSpace = Namespace.of("metalake1", "catalog2");NameIdentifier schemaIdentifier = NameIdentifier.of(schemaNameSpace, WILD_CARD);- realKey = mockEncoder.encode(EntityIdentifer.of(schemaIdentifier, EntityType.SCHEMA), true);+ realKey = mockEncoder.encode(EntityIdentifier.of(schemaIdentifier, EntityType.SCHEMA), true);expenctKey =Bytes.concat(EntityType.SCHEMA.getShortName().getBytes(),@@ -300,7 +301,7 @@ public class TestEntityKeyEncoding {// schema3 --> 1Namespace tableNameSpace = Namespace.of("metalake1", "catalog2", "schema3");NameIdentifier tableIdentifier = NameIdentifier.of(tableNameSpace, WILD_CARD);- realKey = mockEncoder.encode(EntityIdentifer.of(tableIdentifier, EntityType.TABLE), true);+ realKey = mockEncoder.encode(EntityIdentifier.of(tableIdentifier, EntityType.TABLE), true);expenctKey =Bytes.concat(EntityType.TABLE.getShortName().getBytes(),@@ -320,7 +321,7 @@ public class TestEntityKeyEncoding {UnsupportedOperationException.class,() -> {mockEncoder.encode(- EntityIdentifer.of(+ EntityIdentifier.of(NameIdentifier.of(Namespace.of("metalake1", "catalog2", "schema3", "table1"), WILD_CARD),EntityType.COLUMN),diff --git a/core/src/test/java/com/datastrato/graviton/util/TestBytes.java b/core/src/test/java/com/datastrato/graviton/util/TestBytes.javanew file mode 100644index 0000000000..dc1d4a33cd--- /dev/null+++ b/core/src/test/java/com/datastrato/graviton/util/TestBytes.java@@ -0,0 +1,115 @@+/*+ * Copyright 2023 Datastrato.+ * This software is licensed under the Apache License version 2.+ */++package com.datastrato.graviton.util;++import static org.junit.jupiter.api.Assertions.assertArrayEquals;+import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertTrue;++import org.junit.jupiter.api.Test;++public class TestBytes {++ @Test+ public void testWrapAndGet() {+ byte[] data = {0x01, 0x02, 0x03};+ Bytes bytes = Bytes.wrap(data);++ assertArrayEquals(data, bytes.get());+ }++ @Test+ public void testCompareTo() {+ byte[] data1 = {0x01, 0x02, 0x03};+ byte[] data2 = {0x01, 0x02, 0x03};+ byte[] data3 = {0x01, 0x02, 0x04};+ byte[] data4 = {0x01, 0x02};++ Bytes bytes1 = new Bytes(data1);+ Bytes bytes3 = new Bytes(data3);+ Bytes bytes4 = new Bytes(data4);++ assertEquals(0, bytes1.compareTo(data2));+ assertTrue(bytes1.compareTo(data3) < 0);+ assertTrue(bytes3.compareTo(data1) > 0);+ assertTrue(bytes1.compareTo(data2) == 0);++ // Test cases for different lengths+ assertTrue(bytes1.compareTo(data4) > 0);+ assertTrue(bytes4.compareTo(data1) < 0);+ }++ @Test+ public void testConcat() {+ byte[] first = {0x01, 0x02};+ byte[] second = {0x03, 0x04};+ byte[] expected = {0x01, 0x02, 0x03, 0x04};+ byte[] result = Bytes.concat(first, second);++ assertArrayEquals(expected, result);+ }++ @Test+ public void testHashCode() {+ byte[] data1 = {0x01, 0x02, 0x03};+ byte[] data2 = {0x01, 0x02, 0x03};+ Bytes bytes1 = new Bytes(data1);+ Bytes bytes2 = new Bytes(data2);++ assertEquals(bytes1.hashCode(), bytes2.hashCode());+ }++ @Test+ public void testEquals() {+ byte[] data1 = {0x01, 0x02, 0x03};+ byte[] data2 = {0x01, 0x02, 0x03};+ Bytes bytes1 = new Bytes(data1);+ Bytes bytes2 = new Bytes(data2);++ assertTrue(bytes1.equals(bytes2));+ }++ @Test+ public void testIncrement() {+ byte[] data = {0x01, 0x01};+ byte[] expected = {0x01, 0x02};+ Bytes bytes = Bytes.increment(new Bytes(data));++ assertArrayEquals(expected, bytes.get());+ }++ @Test+ public void testIncrementCarry() {+ byte[] data = {0x01, (byte) 0xFF};+ byte[] expected = {0x02, 0x00};+ Bytes bytes = Bytes.increment(new Bytes(data));++ assertArrayEquals(expected, bytes.get());+ }++ @Test+ public void testToString() {+ byte[] data = {0x01, 0x02, (byte) 0xAB};+ String expected = "\\x01\\x02\\xAB";+ Bytes bytes = new Bytes(data);+ String result = bytes.toString();++ assertEquals(expected, result);+ }++ @Test+ public void testLexicographicByteArrayComparator() {+ byte[] data1 = {0x01, 0x02, 0x03};+ byte[] data2 = {0x01, 0x02, 0x04};+ byte[] data3 = {0x01, 0x02, 0x03, 0x00};+ Bytes.ByteArrayComparator comparator = Bytes.BYTES_LEXICO_COMPARATOR;++ assertTrue(comparator.compare(data1, data2) < 0);+ assertTrue(comparator.compare(data2, data1) > 0);+ assertTrue(comparator.compare(data1, data1) == 0);+ assertTrue(comparator.compare(data1, data3) < 0);+ }+}