Skip to content

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

[#44] refactor: refactor the schema system and add catalog interfaces (#45)

Jerry Shao095c67e6b683
diff --git a/core/build.gradle.kts b/core/build.gradle.kts
index c07efb087e..5388fd3fbf 100644
--- a/core/build.gradle.kts
+++ b/core/build.gradle.kts
@@ -6,7 +6,7 @@ plugins {
}
dependencies {
- implementation(project(":schema"));
+ implementation(project(":meta"));
implementation(libs.protobuf.java.util) {
exclude("com.google.guava", "guava")
.because("Brings in Guava for Andriod, which we don't want (and breaks multimaps).")
diff --git a/core/src/main/java/com/datastrato/graviton/BaseTenantOperations.java b/core/src/main/java/com/datastrato/graviton/BaseTenantOperations.java
deleted file mode 100644
index 5cc2ad6143..0000000000
--- a/core/src/main/java/com/datastrato/graviton/BaseTenantOperations.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.datastrato.graviton;
-
-import com.datastrato.graviton.schema.Tenant;
-
-public class BaseTenantOperations implements EntityOperations<Tenant> {}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/Entity.java b/core/src/main/java/com/datastrato/graviton/Entity.java
similarity index 93%
rename from core/src/main/java/com/datastrato/graviton/schema/Entity.java
rename to core/src/main/java/com/datastrato/graviton/Entity.java
index 23c3bf5a67..2f0123f9c8 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/Entity.java
+++ b/core/src/main/java/com/datastrato/graviton/Entity.java
@@ -1,4 +1,4 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton;
import java.io.Serializable;
import java.util.Map;
diff --git a/core/src/main/java/com/datastrato/graviton/EntityAlreadyExistsException.java b/core/src/main/java/com/datastrato/graviton/EntityAlreadyExistsException.java
new file mode 100644
index 0000000000..f96bbaaad0
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/EntityAlreadyExistsException.java
@@ -0,0 +1,12 @@
+package com.datastrato.graviton;
+
+public class EntityAlreadyExistsException extends RuntimeException {
+
+ public EntityAlreadyExistsException(String message) {
+ super(message);
+ }
+
+ public EntityAlreadyExistsException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/EntityChange.java b/core/src/main/java/com/datastrato/graviton/EntityChange.java
new file mode 100644
index 0000000000..e26eb187d4
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/EntityChange.java
@@ -0,0 +1,7 @@
+package com.datastrato.graviton;
+
+/** Mark interface for entity changes, all the entity changes must inherit this interface. */
+public interface EntityChange {
+
+ // TODO. Update the audit info of the entity. @Jerry
+}
diff --git a/core/src/main/java/com/datastrato/graviton/EntityCreate.java b/core/src/main/java/com/datastrato/graviton/EntityCreate.java
new file mode 100644
index 0000000000..0e5e61f7a6
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/EntityCreate.java
@@ -0,0 +1,6 @@
+package com.datastrato.graviton;
+
+/** Mark interface for entity creation, all the entity creation must inherit this interface. */
+public interface EntityCreate {
+ // TODO. Update the audit info of the entity. @Jerry
+}
diff --git a/core/src/main/java/com/datastrato/graviton/EntityOperations.java b/core/src/main/java/com/datastrato/graviton/EntityOperations.java
index 125509499e..ba3e5fb3b0 100644
--- a/core/src/main/java/com/datastrato/graviton/EntityOperations.java
+++ b/core/src/main/java/com/datastrato/graviton/EntityOperations.java
@@ -1,45 +1,69 @@
package com.datastrato.graviton;
-import com.datastrato.graviton.schema.Entity;
-import com.datastrato.graviton.schema.HasIdentifier;
-import com.datastrato.graviton.schema.NameIdentifier;
+public interface EntityOperations<
+ E extends Entity & HasIdentifier, CREATE extends EntityCreate, CHANGE extends EntityChange> {
-public interface EntityOperations<T extends Entity & HasIdentifier> {
+ /**
+ * List the entities in the system.
+ *
+ * @return an array of entities
+ */
+ E[] listEntities();
/**
- * Creates the entity.
+ * Load an entity by {@link NameIdentifier} from the system.
*
- * @param t the entity to create.
+ * @param ident the identifier of the entity
+ * @return the entity
+ * @throws NoSuchEntityException if the entity does not exist
*/
- default void create(T t) {
- throw new UnsupportedOperationException("Not implemented yet");
- }
+ E loadEntity(NameIdentifier ident) throws NoSuchEntityException;
/**
- * Gets the entity by name identifier.
+ * Check if an entity exists using an {@link NameIdentifier} from the system.
*
- * @param nameIdentifier the name identifier of the entity.
- * @return the entity.
+ * @param ident the identifier of the entity
+ * @return true if the entity exists, false otherwise
*/
- default T get(NameIdentifier nameIdentifier) {
- throw new UnsupportedOperationException("Not implemented yet");
+ default boolean entityExists(NameIdentifier ident) {
+ try {
+ loadEntity(ident);
+ return true;
+ } catch (NoSuchEntityException e) {
+ return false;
+ }
}
/**
- * Updates the entity.
+ * Create an entity in the system.
*
- * @param t the entity to update.
+ * @param ident the identifier of the entity
+ * @param create the entity creation metadata
+ * @return the created entity metadata
+ * @throws EntityAlreadyExistsException if the entity already exists
*/
- default void update(T t) {
- throw new UnsupportedOperationException("Not implemented yet");
- }
+ E createEntity(NameIdentifier ident, CREATE create) throws EntityAlreadyExistsException;
/**
- * Deletes the entity by name identifier.
+ * Apply the {@link EntityChange} to alter an entity in the system.
+ *
+ * <p>Implementation may reject the change. If any change is rejected, no changes should be
+ * applied to the entity.
*
- * @param nameIdentifier the name identifier of the entity.
+ * @param ident the identifier of the entity
+ * @param change the entity change to apply to the entity
+ * @return the altered entity metadata
+ * @throws NoSuchEntityException if the entity does not exist
+ * @throws IllegalArgumentException if the change is rejected by the implementation
*/
- default void delete(NameIdentifier nameIdentifier) {
- throw new UnsupportedOperationException("Not implemented yet");
- }
+ E alterEntity(NameIdentifier ident, CHANGE change)
+ throws NoSuchEntityException, IllegalArgumentException;
+
+ /**
+ * Drop an entity from the system.
+ *
+ * @param ident the identifier of the entity
+ * @return true if the entity was dropped, false if the entity did not exist
+ */
+ boolean dropEntity(NameIdentifier ident);
}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/Field.java b/core/src/main/java/com/datastrato/graviton/Field.java
similarity index 98%
rename from core/src/main/java/com/datastrato/graviton/schema/Field.java
rename to core/src/main/java/com/datastrato/graviton/Field.java
index 963505cd05..567ff5ebc0 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/Field.java
+++ b/core/src/main/java/com/datastrato/graviton/Field.java
@@ -1,4 +1,4 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton;
import lombok.EqualsAndHashCode;
diff --git a/core/src/main/java/com/datastrato/graviton/schema/HasIdentifier.java b/core/src/main/java/com/datastrato/graviton/HasIdentifier.java
similarity index 92%
rename from core/src/main/java/com/datastrato/graviton/schema/HasIdentifier.java
rename to core/src/main/java/com/datastrato/graviton/HasIdentifier.java
index 4822ae5867..d804c1d1f4 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/HasIdentifier.java
+++ b/core/src/main/java/com/datastrato/graviton/HasIdentifier.java
@@ -1,4 +1,4 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton;
public interface HasIdentifier {
diff --git a/core/src/main/java/com/datastrato/graviton/schema/NameIdentifier.java b/core/src/main/java/com/datastrato/graviton/NameIdentifier.java
similarity index 98%
rename from core/src/main/java/com/datastrato/graviton/schema/NameIdentifier.java
rename to core/src/main/java/com/datastrato/graviton/NameIdentifier.java
index 6ea358adeb..ecbcd81670 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/NameIdentifier.java
+++ b/core/src/main/java/com/datastrato/graviton/NameIdentifier.java
@@ -1,4 +1,4 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
diff --git a/core/src/main/java/com/datastrato/graviton/schema/Namespace.java b/core/src/main/java/com/datastrato/graviton/Namespace.java
similarity index 97%
rename from core/src/main/java/com/datastrato/graviton/schema/Namespace.java
rename to core/src/main/java/com/datastrato/graviton/Namespace.java
index c1b496ee3e..28295c4154 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/Namespace.java
+++ b/core/src/main/java/com/datastrato/graviton/Namespace.java
@@ -1,4 +1,4 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
diff --git a/core/src/main/java/com/datastrato/graviton/NoSuchEntityException.java b/core/src/main/java/com/datastrato/graviton/NoSuchEntityException.java
new file mode 100644
index 0000000000..d28a3c3edc
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/NoSuchEntityException.java
@@ -0,0 +1,12 @@
+package com.datastrato.graviton;
+
+public class NoSuchEntityException extends RuntimeException {
+
+ public NoSuchEntityException(String message) {
+ super(message);
+ }
+
+ public NoSuchEntityException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/json/JsonUtils.java b/core/src/main/java/com/datastrato/graviton/json/JsonUtils.java
similarity index 97%
rename from core/src/main/java/com/datastrato/graviton/schema/json/JsonUtils.java
rename to core/src/main/java/com/datastrato/graviton/json/JsonUtils.java
index c8e8d78a4b..e41c17d229 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/json/JsonUtils.java
+++ b/core/src/main/java/com/datastrato/graviton/json/JsonUtils.java
@@ -1,4 +1,4 @@
-package com.datastrato.graviton.schema.json;
+package com.datastrato.graviton.json;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
diff --git a/core/src/main/java/com/datastrato/graviton/schema/AuditInfo.java b/core/src/main/java/com/datastrato/graviton/meta/AuditInfo.java
similarity index 70%
rename from core/src/main/java/com/datastrato/graviton/schema/AuditInfo.java
rename to core/src/main/java/com/datastrato/graviton/meta/AuditInfo.java
index 6e787eb037..d503da9425 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/AuditInfo.java
+++ b/core/src/main/java/com/datastrato/graviton/meta/AuditInfo.java
@@ -1,5 +1,7 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton.meta;
+import com.datastrato.graviton.Entity;
+import com.datastrato.graviton.Field;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import java.time.Instant;
@@ -9,6 +11,7 @@ import java.util.Map;
import javax.annotation.Nullable;
import lombok.EqualsAndHashCode;
import lombok.Getter;
+import lombok.Setter;
import lombok.ToString;
@Getter
@@ -25,12 +28,6 @@ public final class AuditInfo implements Entity {
public static final Field LAST_MODIFIED_TIME =
Field.optional(
"last_modified_time", Instant.class, "The time when the entity is last modified");
- public static final Field LAST_ACCESS_USER =
- Field.optional(
- "last_access_user", String.class, "The name of user who last accesses the entity");
- public static final Field LAST_ACCESS_TIME =
- Field.optional(
- "last_access_time", Instant.class, "The time when the entity is last accessed");
@JsonProperty("creator")
private String creator;
@@ -40,20 +37,14 @@ public final class AuditInfo implements Entity {
@Nullable
@JsonProperty("last_modifier")
+ @Setter
private String lastModifier;
@Nullable
@JsonProperty("last_modified_time")
+ @Setter
private Instant lastModifiedTime;
- @Nullable
- @JsonProperty("last_access_user")
- private String lastAccessUser;
-
- @Nullable
- @JsonProperty("last_access_time")
- private Instant lastAccessTime;
-
private AuditInfo() {}
@Override
@@ -65,11 +56,6 @@ public final class AuditInfo implements Entity {
lastModifier == null && lastModifiedTime == null
|| lastModifier != null && lastModifiedTime != null,
"last_modifier and last_modified_time must be both set or both not set");
-
- Preconditions.checkArgument(
- lastAccessUser == null && lastAccessTime == null
- || lastAccessUser != null && lastAccessTime != null,
- "last_access_user and last_access_time must be both set or both not set");
}
@Override
@@ -79,8 +65,6 @@ public final class AuditInfo implements Entity {
fields.put(CREATE_TIME, createTime);
fields.put(LAST_MODIFIER, lastModifier);
fields.put(LAST_MODIFIED_TIME, lastModifiedTime);
- fields.put(LAST_ACCESS_USER, lastAccessUser);
- fields.put(LAST_ACCESS_TIME, lastAccessTime);
return Collections.unmodifiableMap(fields);
}
@@ -112,16 +96,6 @@ public final class AuditInfo implements Entity {
return this;
}
- public Builder withLastAccessUser(String lastAccessUser) {
- this.auditInfo.lastAccessUser = lastAccessUser;
- return this;
- }
-
- public Builder withLastAccessTime(Instant lastAccessTime) {
- this.auditInfo.lastAccessTime = lastAccessTime;
- return this;
- }
-
public AuditInfo build() {
auditInfo.validate();
return auditInfo;
diff --git a/core/src/main/java/com/datastrato/graviton/schema/Auditable.java b/core/src/main/java/com/datastrato/graviton/meta/Auditable.java
similarity index 78%
rename from core/src/main/java/com/datastrato/graviton/schema/Auditable.java
rename to core/src/main/java/com/datastrato/graviton/meta/Auditable.java
index c8e6ecc9ed..76b06cbbe8 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/Auditable.java
+++ b/core/src/main/java/com/datastrato/graviton/meta/Auditable.java
@@ -1,4 +1,4 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton.meta;
public interface Auditable {
diff --git a/core/src/main/java/com/datastrato/graviton/meta/BaseCatalog.java b/core/src/main/java/com/datastrato/graviton/meta/BaseCatalog.java
new file mode 100644
index 0000000000..53800d63c2
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/BaseCatalog.java
@@ -0,0 +1,185 @@
+package com.datastrato.graviton.meta;
+
+import com.datastrato.graviton.*;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.io.Closeable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.ToString;
+
+/**
+ * This is the base class for a Catalog implementation, it defines the interface to initialize and
+ * uninitialize the catalog. This class inherits from Closeable, so that a determined close() method
+ * should be called to release any resources that the catalog holds.
+ */
+@Getter
+@EqualsAndHashCode
+@ToString
+public abstract class BaseCatalog implements Entity, Auditable, HasIdentifier, Closeable {
+
+ enum Type {
+ RELATIONAL, // Catalog Type for Relational Data Structure, like db.table, catalog.db.table.
+ FILE, // Catalog Type for File System (including HDFS, S3, etc.), like path/to/file
+ STREAM, // Catalog Type for Streaming Data, like kafka://topic
+ }
+
+ public static final Field ID =
+ Field.required("id", Long.class, "The unique identifier of the catalog");
+ public static final Field LAKEHOUSE_ID =
+ Field.required("lakehouse_id", Long.class, "The unique identifier of the lakehouse");
+ public static final Field NAME = Field.required("name", String.class, "The name of the catalog");
+ public static final Field TYPE = Field.required("type", Type.class, "The type of the catalog");
+ public static final Field COMMENT =
+ Field.optional("comment", String.class, "The comment of the catalog");
+ public static final Field PROPERTIES =
+ Field.optional("properties", Map.class, "The properties of the catalog");
+ public static final Field AUDIT_INFO =
+ Field.required("audit_info", AuditInfo.class, "The audit info of the catalog");
+
+ @JsonProperty("id")
+ protected Long id;
+
+ @JsonProperty("lakehouse_id")
+ protected Long lakehouseId;
+
+ @JsonProperty("name")
+ protected String name;
+
+ @JsonProperty("type")
+ protected Type type;
+
+ @Nullable
+ @JsonProperty("comment")
+ protected String comment;
+
+ @Nullable
+ @JsonProperty("properties")
+ protected Map<String, String> properties;
+
+ @JsonProperty("audit_info")
+ protected AuditInfo auditInfo;
+
+ /**
+ * Initialize the catalog with specified configuration. This method is called after Catalog object
+ * is created, but before any other method is called. The method is used to initialize the
+ * connection to the underlying metadata source. RuntimeException will be thrown if the
+ * initialization failed.
+ *
+ * @param config The configuration of this Catalog.
+ * @throws RuntimeException if the initialization failed.
+ */
+ public abstract void initialize(Config config) throws RuntimeException;
+
+ @Override
+ public Map<Field, Object> fields() {
+ Map<Field, Object> fields = new HashMap<>();
+ fields.put(ID, id);
+ fields.put(LAKEHOUSE_ID, lakehouseId);
+ fields.put(NAME, name);
+ fields.put(COMMENT, comment);
+ fields.put(TYPE, type);
+ fields.put(PROPERTIES, properties);
+ fields.put(AUDIT_INFO, auditInfo);
+
+ return Collections.unmodifiableMap(fields);
+ }
+
+ @Override
+ public AuditInfo auditInfo() {
+ return auditInfo;
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ interface Builder<SELF extends Builder<SELF, T>, T extends BaseCatalog> {
+ SELF withId(Long id);
+
+ SELF withLakehouseId(Long lakehouseId);
+
+ SELF withName(String name);
+
+ SELF withType(Type type);
+
+ SELF withComment(String comment);
+
+ SELF withProperties(Map<String, String> properties);
+
+ SELF withAuditInfo(AuditInfo auditInfo);
+
+ T build();
+ }
+
+ public abstract static class BaseCatalogBuilder<
+ SELF extends Builder<SELF, T>, T extends BaseCatalog>
+ implements Builder<SELF, T> {
+ protected Long id;
+ protected Long lakehouseId;
+ protected String name;
+ protected Type type;
+ protected String comment;
+ protected Map<String, String> properties;
+ protected AuditInfo auditInfo;
+
+ @Override
+ public SELF withId(Long id) {
+ this.id = id;
+ return self();
+ }
+
+ @Override
+ public SELF withLakehouseId(Long lakehouseId) {
+ this.lakehouseId = lakehouseId;
+ return self();
+ }
+
+ @Override
+ public SELF withName(String name) {
+ this.name = name;
+ return self();
+ }
+
+ @Override
+ public SELF withType(Type type) {
+ this.type = type;
+ return self();
+ }
+
+ @Override
+ public SELF withComment(String comment) {
+ this.comment = comment;
+ return self();
+ }
+
+ @Override
+ public SELF withProperties(Map<String, String> properties) {
+ this.properties = properties;
+ return self();
+ }
+
+ @Override
+ public SELF withAuditInfo(AuditInfo auditInfo) {
+ this.auditInfo = auditInfo;
+ return self();
+ }
+
+ @Override
+ public T build() {
+ T t = internalBuild();
+ t.validate();
+ return t;
+ }
+
+ private SELF self() {
+ return (SELF) this;
+ }
+
+ protected abstract T internalBuild();
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/BaseCatalogOperations.java b/core/src/main/java/com/datastrato/graviton/meta/BaseCatalogOperations.java
new file mode 100644
index 0000000000..6e7d08f444
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/BaseCatalogOperations.java
@@ -0,0 +1,30 @@
+package com.datastrato.graviton.meta;
+
+import com.datastrato.graviton.EntityOperations;
+import com.datastrato.graviton.NameIdentifier;
+import com.datastrato.graviton.NoSuchEntityException;
+
+public abstract class BaseCatalogOperations
+ implements EntityOperations<BaseCatalog, CatalogCreate, CatalogChange> {
+
+ @Override
+ public BaseCatalog[] listEntities() {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ @Override
+ public BaseCatalog loadEntity(NameIdentifier ident) throws NoSuchEntityException {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ @Override
+ public BaseCatalog alterEntity(NameIdentifier ident, CatalogChange change)
+ throws NoSuchEntityException, IllegalArgumentException {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ @Override
+ public boolean dropEntity(NameIdentifier ident) {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/BaseLakehouseOperations.java b/core/src/main/java/com/datastrato/graviton/meta/BaseLakehouseOperations.java
new file mode 100644
index 0000000000..4d2f87a4b2
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/BaseLakehouseOperations.java
@@ -0,0 +1,33 @@
+package com.datastrato.graviton.meta;
+
+import com.datastrato.graviton.*;
+
+public class BaseLakehouseOperations
+ implements EntityOperations<Lakehouse, LakehouseCreate, LakehouseChange> {
+ @Override
+ public Lakehouse[] listEntities() {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ @Override
+ public Lakehouse loadEntity(NameIdentifier ident) throws NoSuchEntityException {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ @Override
+ public Lakehouse createEntity(NameIdentifier ident, LakehouseCreate create)
+ throws EntityAlreadyExistsException {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ @Override
+ public Lakehouse alterEntity(NameIdentifier ident, LakehouseChange change)
+ throws NoSuchEntityException, IllegalArgumentException {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ @Override
+ public boolean dropEntity(NameIdentifier ident) {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/CatalogChange.java b/core/src/main/java/com/datastrato/graviton/meta/CatalogChange.java
new file mode 100644
index 0000000000..e62d178be8
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/CatalogChange.java
@@ -0,0 +1,63 @@
+package com.datastrato.graviton.meta;
+
+import com.datastrato.graviton.EntityChange;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+
+public interface CatalogChange extends EntityChange {
+
+ static CatalogChange rename(String newName) {
+ return new RenameCatalog(newName);
+ }
+
+ static CatalogChange updateComment(String newComment) {
+ return new UpdateCatalogComment(newComment);
+ }
+
+ static CatalogChange setProperty(String property, String value) {
+ return new SetProperty(property, value);
+ }
+
+ static CatalogChange removeProperty(String property) {
+ return new RemoveProperty(property);
+ }
+
+ @Getter
+ @EqualsAndHashCode
+ final class RenameCatalog implements CatalogChange {
+ private final String newName;
+
+ private RenameCatalog(String newName) {
+ this.newName = newName;
+ }
+ }
+
+ @Getter
+ @EqualsAndHashCode
+ final class UpdateCatalogComment implements CatalogChange {
+ private final String newComment;
+
+ private UpdateCatalogComment(String newComment) {
+ this.newComment = newComment;
+ }
+ }
+
+ @Getter
+ final class SetProperty implements CatalogChange {
+ private final String property;
+ private final String value;
+
+ private SetProperty(String property, String value) {
+ this.property = property;
+ this.value = value;
+ }
+ }
+
+ final class RemoveProperty implements CatalogChange {
+ private final String property;
+
+ private RemoveProperty(String property) {
+ this.property = property;
+ }
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/CatalogCreate.java b/core/src/main/java/com/datastrato/graviton/meta/CatalogCreate.java
new file mode 100644
index 0000000000..f154d9d360
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/CatalogCreate.java
@@ -0,0 +1,48 @@
+package com.datastrato.graviton.meta;
+
+import com.datastrato.graviton.EntityCreate;
+import java.util.Map;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+
+@Getter
+@EqualsAndHashCode
+public final class CatalogCreate implements EntityCreate {
+
+ private final String name;
+
+ private final String lakehouseName;
+
+ private final BaseCatalog.Type type;
+
+ private final String comment;
+
+ private final Map<String, String> properties;
+
+ private final String creator;
+
+ private CatalogCreate(
+ String name,
+ String lakehouseName,
+ BaseCatalog.Type type,
+ String comment,
+ Map<String, String> properties,
+ String creator) {
+ this.name = name;
+ this.lakehouseName = lakehouseName;
+ this.type = type;
+ this.comment = comment;
+ this.properties = properties;
+ this.creator = creator;
+ }
+
+ public static CatalogCreate create(
+ String name,
+ String lakehouseName,
+ BaseCatalog.Type type,
+ String comment,
+ Map<String, String> properties,
+ String creator) {
+ return new CatalogCreate(name, lakehouseName, type, comment, properties, creator);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/Lakehouse.java b/core/src/main/java/com/datastrato/graviton/meta/Lakehouse.java
similarity index 85%
rename from core/src/main/java/com/datastrato/graviton/schema/Lakehouse.java
rename to core/src/main/java/com/datastrato/graviton/meta/Lakehouse.java
index ab4d2a9ae9..1d176dc201 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/Lakehouse.java
+++ b/core/src/main/java/com/datastrato/graviton/meta/Lakehouse.java
@@ -1,5 +1,6 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton.meta;
+import com.datastrato.graviton.*;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Collections;
import java.util.HashMap;
@@ -24,6 +25,8 @@ public class Lakehouse implements Entity, Auditable, HasIdentifier {
Field.optional("properties", Map.class, "The properties of the lakehouse");
public static final Field AUDIT_INFO =
Field.required("audit_info", AuditInfo.class, "The audit info of the lakehouse");
+ public static final Field SCHEMA_VERSION =
+ Field.required("version", SchemaVersion.class, "The schema version of the lakehouse");
@JsonProperty("id")
private Long id;
@@ -42,6 +45,9 @@ public class Lakehouse implements Entity, Auditable, HasIdentifier {
@JsonProperty("audit_info")
private AuditInfo auditInfo;
+ @JsonProperty("version")
+ SchemaVersion version;
+
private Lakehouse() {}
@Override
@@ -52,6 +58,7 @@ public class Lakehouse implements Entity, Auditable, HasIdentifier {
fields.put(COMMENT, comment);
fields.put(PROPERTIES, properties);
fields.put(AUDIT_INFO, auditInfo);
+ fields.put(SCHEMA_VERSION, version);
return Collections.unmodifiableMap(fields);
}
@@ -98,6 +105,11 @@ public class Lakehouse implements Entity, Auditable, HasIdentifier {
return this;
}
+ public Builder withVersion(SchemaVersion version) {
+ lakehouse.version = version;
+ return this;
+ }
+
public Lakehouse build() {
lakehouse.validate();
return lakehouse;
diff --git a/core/src/main/java/com/datastrato/graviton/meta/LakehouseChange.java b/core/src/main/java/com/datastrato/graviton/meta/LakehouseChange.java
new file mode 100644
index 0000000000..9a2522e76b
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/LakehouseChange.java
@@ -0,0 +1,66 @@
+package com.datastrato.graviton.meta;
+
+import com.datastrato.graviton.EntityChange;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+
+public interface LakehouseChange extends EntityChange {
+
+ static LakehouseChange rename(String newName) {
+ return new RenameLakehouse(newName);
+ }
+
+ static LakehouseChange updateComment(String newComment) {
+ return new UpdateLakehouseComment(newComment);
+ }
+
+ static LakehouseChange setProperty(String property, String value) {
+ return new SetProperty(property, value);
+ }
+
+ static LakehouseChange removeProperty(String property) {
+ return new RemoveProperty(property);
+ }
+
+ @Getter
+ @EqualsAndHashCode
+ final class RenameLakehouse implements LakehouseChange {
+ private final String newName;
+
+ private RenameLakehouse(String newName) {
+ this.newName = newName;
+ }
+ }
+
+ @Getter
+ @EqualsAndHashCode
+ final class UpdateLakehouseComment implements LakehouseChange {
+ private final String newComment;
+
+ private UpdateLakehouseComment(String newComment) {
+ this.newComment = newComment;
+ }
+ }
+
+ @Getter
+ @EqualsAndHashCode
+ final class SetProperty implements LakehouseChange {
+ private final String property;
+ private final String value;
+
+ private SetProperty(String property, String value) {
+ this.property = property;
+ this.value = value;
+ }
+ }
+
+ @Getter
+ @EqualsAndHashCode
+ final class RemoveProperty implements LakehouseChange {
+ private final String property;
+
+ private RemoveProperty(String property) {
+ this.property = property;
+ }
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/LakehouseCreate.java b/core/src/main/java/com/datastrato/graviton/meta/LakehouseCreate.java
new file mode 100644
index 0000000000..77946f08a2
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/LakehouseCreate.java
@@ -0,0 +1,32 @@
+package com.datastrato.graviton.meta;
+
+import com.datastrato.graviton.EntityCreate;
+import java.util.Map;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+
+@Getter
+@EqualsAndHashCode
+public final class LakehouseCreate implements EntityCreate {
+
+ private final String name;
+
+ private final String comment;
+
+ private final Map<String, String> properties;
+
+ private final String creator;
+
+ private LakehouseCreate(
+ String name, String comment, Map<String, String> properties, String creator) {
+ this.name = name;
+ this.comment = comment;
+ this.properties = properties;
+ this.creator = creator;
+ }
+
+ public static LakehouseCreate create(
+ String name, String comment, Map<String, String> properties, String creator) {
+ return new LakehouseCreate(name, comment, properties, creator);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/SchemaVersion.java b/core/src/main/java/com/datastrato/graviton/meta/SchemaVersion.java
similarity index 96%
rename from core/src/main/java/com/datastrato/graviton/schema/SchemaVersion.java
rename to core/src/main/java/com/datastrato/graviton/meta/SchemaVersion.java
index 09546c37d7..3f3645e91f 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/SchemaVersion.java
+++ b/core/src/main/java/com/datastrato/graviton/meta/SchemaVersion.java
@@ -1,4 +1,4 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton.meta;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
diff --git a/core/src/main/java/com/datastrato/graviton/meta/catalog/NamespaceAlreadyExistsException.java b/core/src/main/java/com/datastrato/graviton/meta/catalog/NamespaceAlreadyExistsException.java
new file mode 100644
index 0000000000..1548e822eb
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/catalog/NamespaceAlreadyExistsException.java
@@ -0,0 +1,15 @@
+package com.datastrato.graviton.meta.catalog;
+
+import com.datastrato.graviton.EntityAlreadyExistsException;
+
+/** Exception thrown when a namespace already exists. */
+public class NamespaceAlreadyExistsException extends EntityAlreadyExistsException {
+
+ public NamespaceAlreadyExistsException(String message) {
+ super(message);
+ }
+
+ public NamespaceAlreadyExistsException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/catalog/NamespaceChange.java b/core/src/main/java/com/datastrato/graviton/meta/catalog/NamespaceChange.java
new file mode 100644
index 0000000000..071d49eb33
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/catalog/NamespaceChange.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Referred from Apache's connector/catalog implementation
+// sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/NamespaceChange.java
+
+package com.datastrato.graviton.meta.catalog;
+
+import com.datastrato.graviton.EntityChange;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+
+public interface NamespaceChange extends EntityChange {
+
+ /**
+ * NamespaceChange class to set the property and value for the namespace.
+ *
+ * @param property the property name to set
+ * @param value the property value to set
+ * @return the NamespaceChange object
+ */
+ static NamespaceChange setProperty(String property, String value) {
+ return new SetProperty(property, value);
+ }
+
+ /**
+ * NamespaceChange class to remove the property from the namespace.
+ *
+ * @param property the property name to remove
+ * @return the NamespaceChange object
+ */
+ static NamespaceChange removeProperty(String property) {
+ return new RemoveProperty(property);
+ }
+
+ @Getter
+ @EqualsAndHashCode
+ final class SetProperty implements NamespaceChange {
+ private final String property;
+ private final String value;
+
+ private SetProperty(String property, String value) {
+ this.property = property;
+ this.value = value;
+ }
+ }
+
+ @Getter
+ @EqualsAndHashCode
+ final class RemoveProperty implements NamespaceChange {
+ private final String property;
+
+ private RemoveProperty(String property) {
+ this.property = property;
+ }
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/catalog/NoSuchNamespaceException.java b/core/src/main/java/com/datastrato/graviton/meta/catalog/NoSuchNamespaceException.java
new file mode 100644
index 0000000000..aadc30b398
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/catalog/NoSuchNamespaceException.java
@@ -0,0 +1,15 @@
+package com.datastrato.graviton.meta.catalog;
+
+import com.datastrato.graviton.NoSuchEntityException;
+
+/** Exception thrown when a namespace with specified name is not existed. */
+public class NoSuchNamespaceException extends NoSuchEntityException {
+
+ public NoSuchNamespaceException(String message) {
+ super(message);
+ }
+
+ public NoSuchNamespaceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/catalog/NonEmptyNamespaceException.java b/core/src/main/java/com/datastrato/graviton/meta/catalog/NonEmptyNamespaceException.java
new file mode 100644
index 0000000000..cff7330cfc
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/catalog/NonEmptyNamespaceException.java
@@ -0,0 +1,13 @@
+package com.datastrato.graviton.meta.catalog;
+
+/** Exception thrown when a namespace is not empty. */
+public class NonEmptyNamespaceException extends RuntimeException {
+
+ public NonEmptyNamespaceException(String message) {
+ super(message);
+ }
+
+ public NonEmptyNamespaceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/catalog/SupportsNamespaces.java b/core/src/main/java/com/datastrato/graviton/meta/catalog/SupportsNamespaces.java
new file mode 100644
index 0000000000..82aacd45a5
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/catalog/SupportsNamespaces.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Referred from Apache's connector/catalog implementation
+// sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/SupportNamespaces.java
+
+package com.datastrato.graviton.meta.catalog;
+
+import com.datastrato.graviton.Namespace;
+import java.util.Map;
+
+/**
+ * The Catalog interface to support namespace operations. If the implemented catalog has namespace
+ * semantics, it should implement this interface.
+ */
+public interface SupportsNamespaces {
+
+ /**
+ * List top-level namespaces from the catalog.
+ *
+ * <p>If an entity such as a table, view exists, its parent namespaces must also exist and must be
+ * returned by this discovery method. For example, if table a.b.t exists, this method must return
+ * ["a"] in the result array.
+ *
+ * @return an array of namespace
+ * @throws NoSuchNamespaceException if there's no namespace in the catalog
+ */
+ Namespace[] listNamespaces() throws NoSuchNamespaceException;
+
+ /**
+ * List namespaces in a namespace.
+ *
+ * <p>If an entity such as a table, view exists, its parent namespaces must also exist and must be
+ * returned by this discovery method. For example, if table a.b.t exists, this method invoked as
+ * listNamespaces(a) must return [a.b] in the result array
+ *
+ * @param namespace the namespace to list
+ * @return an array of namespace
+ * @throws NoSuchNamespaceException if the namespace does not exist
+ */
+ Namespace[] listNamespaces(Namespace namespace) throws NoSuchNamespaceException;
+
+ /**
+ * Check if a namespace exists.
+ *
+ * <p>If an entity such as a table, view exists, its parent namespaces must also exist. For
+ * example, if table a.b.t exists, this method invoked as namespaceExists(a) must return true.
+ *
+ * @param namespace the namespace to check
+ * @return true if the namespace exists, false otherwise
+ */
+ boolean namespaceExists(Namespace namespace);
+
+ /**
+ * Create a namespace in the catalog.
+ *
+ * @param namespace the namespace to create
+ * @param metadata the metadata of the namespace
+ * @throws NamespaceAlreadyExistsException if the namespace already exists
+ */
+ void createNamespace(Namespace namespace, Map<String, String> metadata)
+ throws NamespaceAlreadyExistsException;
+
+ /**
+ * Apply the metadata change to a namespace in the catalog.
+ *
+ * @param namespace the namespace to alter
+ * @param change the metadata change to apply
+ * @throws NoSuchNamespaceException if the namespace does not exist
+ */
+ void alterNamespace(Namespace namespace, NamespaceChange change) throws NoSuchNamespaceException;
+
+ /**
+ * Drop a namespace from the catalog with cascade option, recursively dropping all objects within
+ * the namespace if cascade is tur.
+ *
+ * <p>If the catalog implementation does not support this operation, it may throw {@link
+ * UnsupportedOperationException}.
+ *
+ * @param namespace the namespace to drop
+ * @param cascade if true, recursively drop all objects within the namespace
+ * @return true if the namespace is dropped successfully, false otherwise
+ * @throws NonEmptyNamespaceException if the namespace is not empty and cascade is false
+ * @throws NoSuchNamespaceException if the namespace does not exist
+ */
+ boolean dropNamespace(Namespace namespace, boolean cascade)
+ throws NonEmptyNamespaceException, NoSuchNamespaceException;
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/catalog/TableCatalog.java b/core/src/main/java/com/datastrato/graviton/meta/catalog/TableCatalog.java
new file mode 100644
index 0000000000..0fb3218f6d
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/catalog/TableCatalog.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Referred from Apache's connector/catalog implementation
+// sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableCatalog.java
+
+package com.datastrato.graviton.meta.catalog;
+
+import com.datastrato.graviton.NameIdentifier;
+import com.datastrato.graviton.Namespace;
+import com.datastrato.graviton.meta.catalog.rel.*;
+import java.util.Map;
+
+/**
+ * The TableCatalog interface defines the public API for managing tables in a namespace. If the
+ * catalog implementation supports tables, it must implement this interface.
+ */
+public interface TableCatalog {
+
+ /**
+ * List the tables in a namespace from the catalog.
+ *
+ * @param namespace a namespace
+ * @return an array of table identifiers in the namespace
+ * @throws NoSuchNamespaceException if the namespace does not exist
+ */
+ NameIdentifier[] listTables(Namespace namespace) throws NoSuchNamespaceException;
+
+ /**
+ * Load table metadata by {@link NameIdentifier} from the catalog.
+ *
+ * @param ident a table identifier
+ * @return the table metadata
+ * @throws NoSuchTableException if the table does not exist
+ */
+ Table loadTable(NameIdentifier ident) throws NoSuchTableException;
+
+ /**
+ * Check if a table exists using an {@link NameIdentifier} from the catalog.
+ *
+ * @param ident a table identifier
+ * @return true if the table exists, false otherwise
+ */
+ default boolean tableExists(NameIdentifier ident) {
+ try {
+ return loadTable(ident) != null;
+ } catch (NoSuchTableException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Create a table in the catalog.
+ *
+ * @param ident a table identifier
+ * @param columns the columns of the new table
+ * @param comment the table comment
+ * @param properties the table properties
+ * @return the created table metadata
+ * @throws NoSuchNamespaceException if the namespace does not exist
+ * @throws TableAlreadyExistsException if the table already exists
+ */
+ Table createTable(
+ NameIdentifier ident, Column[] columns, String comment, Map<String, String> properties)
+ throws NoSuchNamespaceException, TableAlreadyExistsException;
+
+ /**
+ * Apply the {@link TableChange change} to a table in the catalog.
+ *
+ * <p>Implementations may reject the change. If any change is rejected, no changes should be
+ * applied to the table.
+ *
+ * @param ident a table identifier
+ * @param change a table change to apply to the table
+ * @return the updated table metadata
+ * @throws NoSuchTableException if the table does not exist
+ * @throws IllegalArgumentException if the change is rejected by the implementation
+ */
+ Table alterTable(NameIdentifier ident, TableChange change)
+ throws NoSuchTableException, IllegalArgumentException;
+
+ /**
+ * Drop a table from the catalog.
+ *
+ * @param ident a table identifier
+ * @return true if the table was dropped, false if the table did not exist
+ */
+ boolean dropTable(NameIdentifier ident);
+
+ /**
+ * Drop a table from the catalog and completely remove its data.
+ *
+ * <p>If the catalog supports to purge a table, this method should be overridden. The default
+ * implementation throws an {@link UnsupportedOperationException}.
+ *
+ * @param ident a table identifier
+ * @return true if the table was purged, false if the table did not exist
+ * @throws UnsupportedOperationException if the catalog does not support to purge a table
+ */
+ default boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("purgeTable not supported.");
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/Column.java b/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/Column.java
new file mode 100644
index 0000000000..2d570c2f5c
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/Column.java
@@ -0,0 +1,41 @@
+package com.datastrato.graviton.meta.catalog.rel;
+
+import com.datastrato.graviton.Entity;
+import com.datastrato.graviton.HasIdentifier;
+import com.datastrato.graviton.NameIdentifier;
+import com.datastrato.graviton.json.JsonUtils;
+import com.datastrato.graviton.meta.Auditable;
+import com.datastrato.graviton.meta.catalog.TableCatalog;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import io.substrait.type.Type;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * An interface representing a column of a {@link Table}. It defines basic properties of a column,
+ * such as name and data type.
+ *
+ * <p>Catalog implementation needs to implement it. They should consume it in APIs like {@link
+ * TableCatalog#createTable(NameIdentifier, Column[], String, Map)}, and report it in {@link
+ * Table#columns()} a default value and a generation expression.
+ */
+public interface Column extends Entity, Auditable, HasIdentifier {
+
+ /** Returns the name of this column. */
+ @JsonProperty("name")
+ String name();
+ /** Returns the data type of this column. */
+ @JsonProperty("type")
+ @JsonSerialize(using = JsonUtils.TypeSerializer.class)
+ @JsonDeserialize(using = JsonUtils.TypeDeserializer.class)
+ Type dataType();
+
+ /** Returns the comment of this column, null if not specified. */
+ @Nullable
+ @JsonProperty("comment")
+ String comment();
+
+ // TODO. Support column default value. @Jerry
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/NoSuchTableException.java b/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/NoSuchTableException.java
new file mode 100644
index 0000000000..3a04b469ea
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/NoSuchTableException.java
@@ -0,0 +1,15 @@
+package com.datastrato.graviton.meta.catalog.rel;
+
+import com.datastrato.graviton.NoSuchEntityException;
+
+/** Exception thrown when a table with specified name is not existed. */
+public class NoSuchTableException extends NoSuchEntityException {
+
+ public NoSuchTableException(String message) {
+ super(message);
+ }
+
+ public NoSuchTableException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/Table.java b/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/Table.java
new file mode 100644
index 0000000000..5d8b8be9b8
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/Table.java
@@ -0,0 +1,39 @@
+package com.datastrato.graviton.meta.catalog.rel;
+
+import com.datastrato.graviton.Entity;
+import com.datastrato.graviton.HasIdentifier;
+import com.datastrato.graviton.Namespace;
+import com.datastrato.graviton.meta.Auditable;
+import com.datastrato.graviton.meta.catalog.TableCatalog;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.Collections;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * An interface representing a table in a {@link Namespace}. It defines basic properties of a table.
+ * A catalog implementation with {@link TableCatalog} should implement it.
+ */
+public interface Table extends Entity, Auditable, HasIdentifier {
+
+ /** return the name of the table. */
+ @JsonProperty("name")
+ String name();
+
+ /** return the columns of the table. */
+ @JsonProperty("columns")
+ Column[] columns();
+
+ /** return the comment of the table. Null is returned if no comment is set. */
+ @Nullable
+ @JsonProperty("comment")
+ default String comment() {
+ return null;
+ }
+
+ /** return the properties of the table. Empty map is returned if no properties are set. */
+ @JsonProperty("properties")
+ default Map<String, String> properties() {
+ return Collections.emptyMap();
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/TableAlreadyExistsException.java b/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/TableAlreadyExistsException.java
new file mode 100644
index 0000000000..12c89f57c5
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/TableAlreadyExistsException.java
@@ -0,0 +1,15 @@
+package com.datastrato.graviton.meta.catalog.rel;
+
+import com.datastrato.graviton.EntityAlreadyExistsException;
+
+/** Exception thrown when a table with specified name already exists. */
+public class TableAlreadyExistsException extends EntityAlreadyExistsException {
+
+ public TableAlreadyExistsException(String message) {
+ super(message);
+ }
+
+ public TableAlreadyExistsException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/TableChange.java b/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/TableChange.java
new file mode 100644
index 0000000000..36ce226ccf
--- /dev/null
+++ b/core/src/main/java/com/datastrato/graviton/meta/catalog/rel/TableChange.java
@@ -0,0 +1,412 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Referred from Apache's connector/catalog implementation
+// sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableChange.java
+
+package com.datastrato.graviton.meta.catalog.rel;
+
+import com.datastrato.graviton.EntityChange;
+import io.substrait.type.Type;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+
+public interface TableChange extends EntityChange {
+
+ /**
+ * Create a TableChange for setting a table property.
+ *
+ * <p>If the property already exists, it will be replaced with the new value.
+ *
+ * @param property the property name
+ * @param value the new property value
+ * @return a TableChange for the addition
+ */
+ static TableChange setProperty(String property, String value) {
+ return new SetProperty(property, value);
+ }
+
+ /**
+ * Create a TableChange for removing a table property.
+ *
+ * <p>If the property does not exist, the change will succeed.
+ *
+ * @param property the property name
+ * @return a TableChange for the addition
+ */
+ static TableChange removeProperty(String property) {
+ return new RemoveProperty(property);
+ }
+
+ /**
+ * Create a TableChange for adding an optional column.
+ *
+ * <p>If the field already exists, the change will result in an {@link IllegalArgumentException}.
+ * If the new field is nested and its parent does not exist or is not a struct, the change will
+ * result in an {@link IllegalArgumentException}.
+ *
+ * @param fieldNames field names of the new column
+ * @param dataType the new column's data type
+ * @return a TableChange for the addition
+ */
+ static TableChange addColumn(String[] fieldNames, Type dataType) {
+ return new AddColumn(fieldNames, dataType, null, null);
+ }
+
+ /**
+ * Create a TableChange for adding a column.
+ *
+ * <p>If the field already exists, the change will result in an {@link IllegalArgumentException}.
+ * If the new field is nested and its parent does not exist or is not a struct, the change will
+ * result in an {@link IllegalArgumentException}.
+ *
+ * @param fieldNames field names of the new column
+ * @param dataType the new column's data type
+ * @param comment the new field's comment string
+ * @return a TableChange for the addition
+ */
+ static TableChange addColumn(String[] fieldNames, Type dataType, String comment) {
+ return new AddColumn(fieldNames, dataType, comment, null);
+ }
+
+ /**
+ * Create a TableChange for adding a column.
+ *
+ * <p>If the field already exists, the change will result in an {@link IllegalArgumentException}.
+ * If the new field is nested and its parent does not exist or is not a struct, the change will
+ * result in an {@link IllegalArgumentException}.
+ *
+ * @param fieldNames field names of the new column
+ * @param dataType the new column's data type
+ * @param comment the new field's comment string
+ * @param position the new columns's position
+ * @return a TableChange for the addition
+ */
+ static TableChange addColumn(
+ String[] fieldNames, Type dataType, String comment, ColumnPosition position) {
+ return new AddColumn(fieldNames, dataType, comment, position);
+ }
+
+ /**
+ * Create a TableChange for renaming a field.
+ *
+ * <p>The name is used to find the field to rename. The new name will replace the leaf field name.
+ * For example, renameColumn(["a", "b", "c"], "x") should produce column a.b.x.
+ *
+ * <p>If the field does not exist, the change will result in an {@link IllegalArgumentException}.
+ *
+ * @param fieldNames the current field names
+ * @param newName the new name
+ * @return a TableChange for the rename
+ */
+ static TableChange renameColumn(String[] fieldNames, String newName) {
+ return new RenameColumn(fieldNames, newName);
+ }
+
+ /**
+ * Create a TableChange for updating the type of a field that is nullable.
+ *
+ * <p>The field names are used to find the field to update.
+ *
+ * <p>If the field does not exist, the change will result in an {@link IllegalArgumentException}.
+ *
+ * @param fieldNames field names of the column to update
+ * @param newDataType the new data type
+ * @return a TableChange for the update
+ */
+ static TableChange updateColumnType(String[] fieldNames, Type newDataType) {
+ return new UpdateColumnType(fieldNames, newDataType);
+ }
+
+ /**
+ * Create a TableChange for updating the comment of a field.
+ *
+ * <p>The name is used to find the field to update.
+ *
+ * <p>If the field does not exist, the change will result in an {@link IllegalArgumentException}.
+ *
+ * @param fieldNames field names of the column to update
+ * @param newComment the new comment
+ * @return a TableChange for the update
+ */
+ static TableChange updateColumnComment(String[] fieldNames, String newComment) {
+ return new UpdateColumnComment(fieldNames, newComment);
+ }
+
+ /**
+ * Create a TableChange for updating the position of a field.
+ *
+ * <p>The name is used to find the field to update.
+ *
+ * <p>If the field does not exist, the change will result in an {@link IllegalArgumentException}.
+ *
+ * @param fieldNames field names of the column to update
+ * @param newPosition the new position
+ * @return a TableChange for the update
+ */
+ static TableChange updateColumnPosition(String[] fieldNames, ColumnPosition newPosition) {
+ return new UpdateColumnPosition(fieldNames, newPosition);
+ }
+
+ /**
+ * Create a TableChange for deleting a field.
+ *
+ * <p>If the field does not exist, the change will result in an {@link IllegalArgumentException}.
+ *
+ * @param fieldNames field names of the column to delete
+ * @param ifExists silence the error if column doesn't exist during drop
+ * @return a TableChange for the delete
+ */
+ static TableChange deleteColumn(String[] fieldNames, Boolean ifExists) {
+ return new DeleteColumn(fieldNames, ifExists);
+ }
+
+ /**
+ * A TableChange to set a table property.
+ *
+ * <p>If the property already exists, it must be replaced with the new value.
+ */
+ @EqualsAndHashCode
+ @Getter
+ final class SetProperty implements TableChange {
+ private final String property;
+ private final String value;
+
+ private SetProperty(String property, String value) {
+ this.property = property;
+ this.value = value;
+ }
+ }
+
+ /**
+ * A TableChange to remove a table property.
+ *
+ * <p>If the property does not exist, the change should succeed.
+ */
+ @EqualsAndHashCode
+ @Getter
+ final class RemoveProperty implements TableChange {
+ private final String property;
+
+ private RemoveProperty(String property) {
+ this.property = property;
+ }
+ }
+
+ interface ColumnPosition {
+
+ static ColumnPosition first() {
+ return First.INSTANCE;
+ }
+
+ static ColumnPosition after(String column) {
+ return new After(column);
+ }
+ }
+
+ /**
+ * Column position FIRST means the specified column should be the first column. Note that, the
+ * specified column may be a nested field, and then FIRST means this field should be the first one
+ * within the struct.
+ */
+ final class First implements ColumnPosition {
+ private static final First INSTANCE = new First();
+
+ private First() {}
+
+ @Override
+ public String toString() {
+ return "FIRST";
+ }
+ }
+
+ /**
+ * Column position AFTER means the specified column should be put after the given `column`. Note
+ * that, the specified column may be a nested field, and then the given `column` refers to a field
+ * in the same struct.
+ */
+ @EqualsAndHashCode
+ @Getter
+ final class After implements ColumnPosition {
+ private final String column;
+
+ private After(String column) {
+ assert column != null;
+ this.column = column;
+ }
+
+ @Override
+ public String toString() {
+ return "AFTER " + column;
+ }
+ }
+
+ interface ColumnChange extends TableChange {
+ String[] fieldNames();
+ }
+
+ /**
+ * A TableChange to add a field. The implementation may need to back-fill all the existing data to
+ * add this new column, or remember the column default value specified here and let the reader
+ * fill the column value when reading existing data that do not have this new column.
+ *
+ * <p>If the field already exists, the change must result in an {@link IllegalArgumentException}.
+ * If the new field is nested and its parent does not exist or is not a struct, the change must
+ * result in an {@link IllegalArgumentException}.
+ */
+ @EqualsAndHashCode
+ final class AddColumn implements ColumnChange {
+ private final String[] fieldNames;
+
+ @Getter private final Type dataType;
+
+ @Getter private final String comment;
+
+ @Getter private final ColumnPosition position;
+
+ private AddColumn(String[] fieldNames, Type dataType, String comment, ColumnPosition position) {
+ this.fieldNames = fieldNames;
+ this.dataType = dataType;
+ this.comment = comment;
+ this.position = position;
+ }
+
+ @Override
+ public String[] fieldNames() {
+ return fieldNames;
+ }
+ }
+
+ /**
+ * A TableChange to rename a field.
+ *
+ * <p>The name is used to find the field to rename. The new name will replace the leaf field name.
+ * For example, renameColumn("a.b.c", "x") should produce column a.b.x.
+ *
+ * <p>If the field does not exist, the change must result in an {@link IllegalArgumentException}.
+ */
+ @EqualsAndHashCode
+ final class RenameColumn implements ColumnChange {
+ private final String[] fieldNames;
+
+ @Getter private final String newName;
+
+ private RenameColumn(String[] fieldNames, String newName) {
+ this.fieldNames = fieldNames;
+ this.newName = newName;
+ }
+
+ @Override
+ public String[] fieldNames() {
+ return fieldNames;
+ }
+ }
+
+ /**
+ * A TableChange to update the type of a field.
+ *
+ * <p>The field names are used to find the field to update.
+ *
+ * <p>If the field does not exist, the change must result in an {@link IllegalArgumentException}.
+ */
+ @EqualsAndHashCode
+ final class UpdateColumnType implements ColumnChange {
+ private final String[] fieldNames;
+
+ @Getter private final Type newDataType;
+
+ private UpdateColumnType(String[] fieldNames, Type newDataType) {
+ this.fieldNames = fieldNames;
+ this.newDataType = newDataType;
+ }
+
+ @Override
+ public String[] fieldNames() {
+ return fieldNames;
+ }
+ }
+
+ /**
+ * A TableChange to update the comment of a field.
+ *
+ * <p>The field names are used to find the field to update.
+ *
+ * <p>If the field does not exist, the change must result in an {@link IllegalArgumentException}.
+ */
+ @EqualsAndHashCode
+ final class UpdateColumnComment implements ColumnChange {
+ private final String[] fieldNames;
+
+ @Getter private final String newComment;
+
+ private UpdateColumnComment(String[] fieldNames, String newComment) {
+ this.fieldNames = fieldNames;
+ this.newComment = newComment;
+ }
+
+ @Override
+ public String[] fieldNames() {
+ return fieldNames;
+ }
+ }
+
+ /**
+ * A TableChange to update the position of a field.
+ *
+ * <p>The field names are used to find the field to update.
+ *
+ * <p>If the field does not exist, the change must result in an {@link IllegalArgumentException}.
+ */
+ @EqualsAndHashCode
+ final class UpdateColumnPosition implements ColumnChange {
+ private final String[] fieldNames;
+
+ @Getter private final ColumnPosition position;
+
+ private UpdateColumnPosition(String[] fieldNames, ColumnPosition position) {
+ this.fieldNames = fieldNames;
+ this.position = position;
+ }
+
+ @Override
+ public String[] fieldNames() {
+ return fieldNames;
+ }
+ }
+
+ /**
+ * A TableChange to delete a field.
+ *
+ * <p>If the field does not exist, the change must result in an {@link IllegalArgumentException}.
+ */
+ @EqualsAndHashCode
+ final class DeleteColumn implements ColumnChange {
+ private final String[] fieldNames;
+
+ @Getter private final Boolean ifExists;
+
+ private DeleteColumn(String[] fieldNames, Boolean ifExists) {
+ this.fieldNames = fieldNames;
+ this.ifExists = ifExists;
+ }
+
+ @Override
+ public String[] fieldNames() {
+ return fieldNames;
+ }
+ }
+}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/proto/AuditInfoSerDe.java b/core/src/main/java/com/datastrato/graviton/proto/AuditInfoSerDe.java
similarity index 52%
rename from core/src/main/java/com/datastrato/graviton/schema/proto/AuditInfoSerDe.java
rename to core/src/main/java/com/datastrato/graviton/proto/AuditInfoSerDe.java
index a30c47f703..e4431dc96f 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/proto/AuditInfoSerDe.java
+++ b/core/src/main/java/com/datastrato/graviton/proto/AuditInfoSerDe.java
@@ -1,8 +1,8 @@
-package com.datastrato.graviton.schema.proto;
+package com.datastrato.graviton.proto;
-class AuditInfoSerDe implements ProtoSerDe<com.datastrato.graviton.schema.AuditInfo, AuditInfo> {
+class AuditInfoSerDe implements ProtoSerDe<com.datastrato.graviton.meta.AuditInfo, AuditInfo> {
@Override
- public AuditInfo serialize(com.datastrato.graviton.schema.AuditInfo auditInfo) {
+ public AuditInfo serialize(com.datastrato.graviton.meta.AuditInfo auditInfo) {
AuditInfo.Builder builder =
AuditInfo.newBuilder()
.setCreator(auditInfo.getCreator())
@@ -14,19 +14,13 @@ class AuditInfoSerDe implements ProtoSerDe<com.datastrato.graviton.schema.AuditI
.setLastModifiedTime(ProtoUtils.fromInstant(auditInfo.getLastModifiedTime()));
}
- if (auditInfo.getLastAccessUser() != null && auditInfo.getLastAccessTime() != null) {
- builder
- .setLastAccessUser(auditInfo.getLastAccessUser())
- .setLastAccessTime(ProtoUtils.fromInstant(auditInfo.getLastAccessTime()));
- }
-
return builder.build();
}
@Override
- public com.datastrato.graviton.schema.AuditInfo deserialize(AuditInfo p) {
- com.datastrato.graviton.schema.AuditInfo.Builder builder =
- new com.datastrato.graviton.schema.AuditInfo.Builder()
+ public com.datastrato.graviton.meta.AuditInfo deserialize(AuditInfo p) {
+ com.datastrato.graviton.meta.AuditInfo.Builder builder =
+ new com.datastrato.graviton.meta.AuditInfo.Builder()
.withCreator(p.getCreator())
.withCreateTime(ProtoUtils.toInstant(p.getCreateTime()));
@@ -36,12 +30,6 @@ class AuditInfoSerDe implements ProtoSerDe<com.datastrato.graviton.schema.AuditI
.withLastModifiedTime(ProtoUtils.toInstant(p.getLastModifiedTime()));
}
- if (p.hasLastAccessUser() && p.hasLastAccessTime()) {
- builder
- .withLastAccessUser(p.getLastAccessUser())
- .withLastAccessTime(ProtoUtils.toInstant(p.getLastAccessTime()));
- }
-
return builder.build();
}
}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/proto/LakehouseSerDe.java b/core/src/main/java/com/datastrato/graviton/proto/LakehouseSerDe.java
similarity index 53%
rename from core/src/main/java/com/datastrato/graviton/schema/proto/LakehouseSerDe.java
rename to core/src/main/java/com/datastrato/graviton/proto/LakehouseSerDe.java
index db7919a069..54e4d079ea 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/proto/LakehouseSerDe.java
+++ b/core/src/main/java/com/datastrato/graviton/proto/LakehouseSerDe.java
@@ -1,8 +1,8 @@
-package com.datastrato.graviton.schema.proto;
+package com.datastrato.graviton.proto;
-class LakehouseSerDe implements ProtoSerDe<com.datastrato.graviton.schema.Lakehouse, Lakehouse> {
+class LakehouseSerDe implements ProtoSerDe<com.datastrato.graviton.meta.Lakehouse, Lakehouse> {
@Override
- public Lakehouse serialize(com.datastrato.graviton.schema.Lakehouse lakehouse) {
+ public Lakehouse serialize(com.datastrato.graviton.meta.Lakehouse lakehouse) {
Lakehouse.Builder builder =
Lakehouse.newBuilder()
.setId(lakehouse.getId())
@@ -17,13 +17,20 @@ class LakehouseSerDe implements ProtoSerDe<com.datastrato.graviton.schema.Lakeho
builder.putAllProperties(lakehouse.getProperties());
}
+ SchemaVersion version =
+ SchemaVersion.newBuilder()
+ .setMajorNumber(lakehouse.getVersion().majorVersion)
+ .setMinorNumber(lakehouse.getVersion().minorVersion)
+ .build();
+ builder.setVersion(version);
+
return builder.build();
}
@Override
- public com.datastrato.graviton.schema.Lakehouse deserialize(Lakehouse p) {
- com.datastrato.graviton.schema.Lakehouse.Builder builder =
- new com.datastrato.graviton.schema.Lakehouse.Builder();
+ public com.datastrato.graviton.meta.Lakehouse deserialize(Lakehouse p) {
+ com.datastrato.graviton.meta.Lakehouse.Builder builder =
+ new com.datastrato.graviton.meta.Lakehouse.Builder();
builder
.withId(p.getId())
.withName(p.getName())
@@ -37,6 +44,11 @@ class LakehouseSerDe implements ProtoSerDe<com.datastrato.graviton.schema.Lakeho
builder.withProperties(p.getPropertiesMap());
}
+ com.datastrato.graviton.meta.SchemaVersion version =
+ com.datastrato.graviton.meta.SchemaVersion.forValues(
+ p.getVersion().getMajorNumber(), p.getVersion().getMinorNumber());
+ builder.withVersion(version);
+
return builder.build();
}
}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/proto/ProtoSerDe.java b/core/src/main/java/com/datastrato/graviton/proto/ProtoSerDe.java
similarity index 75%
rename from core/src/main/java/com/datastrato/graviton/schema/proto/ProtoSerDe.java
rename to core/src/main/java/com/datastrato/graviton/proto/ProtoSerDe.java
index 6836cf3b77..2fb5bfc01b 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/proto/ProtoSerDe.java
+++ b/core/src/main/java/com/datastrato/graviton/proto/ProtoSerDe.java
@@ -1,4 +1,4 @@
-package com.datastrato.graviton.schema.proto;
+package com.datastrato.graviton.proto;
import com.google.protobuf.MessageLite;
diff --git a/core/src/main/java/com/datastrato/graviton/schema/proto/ProtoSerDeException.java b/core/src/main/java/com/datastrato/graviton/proto/ProtoSerDeException.java
similarity index 83%
rename from core/src/main/java/com/datastrato/graviton/schema/proto/ProtoSerDeException.java
rename to core/src/main/java/com/datastrato/graviton/proto/ProtoSerDeException.java
index 17df17e552..6d44e21b9d 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/proto/ProtoSerDeException.java
+++ b/core/src/main/java/com/datastrato/graviton/proto/ProtoSerDeException.java
@@ -1,4 +1,4 @@
-package com.datastrato.graviton.schema.proto;
+package com.datastrato.graviton.proto;
public class ProtoSerDeException extends RuntimeException {
diff --git a/core/src/main/java/com/datastrato/graviton/schema/proto/ProtoUtils.java b/core/src/main/java/com/datastrato/graviton/proto/ProtoUtils.java
similarity index 71%
rename from core/src/main/java/com/datastrato/graviton/schema/proto/ProtoUtils.java
rename to core/src/main/java/com/datastrato/graviton/proto/ProtoUtils.java
index 806db56e3a..bec5e591fa 100644
--- a/core/src/main/java/com/datastrato/graviton/schema/proto/ProtoUtils.java
+++ b/core/src/main/java/com/datastrato/graviton/proto/ProtoUtils.java
@@ -1,6 +1,6 @@
-package com.datastrato.graviton.schema.proto;
+package com.datastrato.graviton.proto;
-import com.datastrato.graviton.schema.Entity;
+import com.datastrato.graviton.Entity;
import com.google.protobuf.MessageLite;
import com.google.protobuf.Parser;
import com.google.protobuf.Timestamp;
@@ -9,7 +9,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-class ProtoUtils {
+public class ProtoUtils {
private static final Map<
Class<? extends Entity>, ProtoSerDe<? extends Entity, ? extends MessageLite>>
ENTITY_TO_SERDE;
@@ -17,12 +17,8 @@ class ProtoUtils {
static {
Map<Class<? extends Entity>, ProtoSerDe<? extends Entity, ? extends MessageLite>> tmp =
new HashMap<>();
- tmp.put(com.datastrato.graviton.schema.AuditInfo.class, new AuditInfoSerDe());
- tmp.put(com.datastrato.graviton.schema.Tenant.class, new TenantSerDe());
- tmp.put(com.datastrato.graviton.schema.Lakehouse.class, new LakehouseSerDe());
- tmp.put(com.datastrato.graviton.schema.Zone.class, new ZoneSerDe());
- tmp.put(com.datastrato.graviton.schema.Table.class, new TableSerDe());
- tmp.put(com.datastrato.graviton.schema.Column.class, new ColumnSerDe());
+ tmp.put(com.datastrato.graviton.meta.AuditInfo.class, new AuditInfoSerDe());
+ tmp.put(com.datastrato.graviton.meta.Lakehouse.class, new LakehouseSerDe());
ENTITY_TO_SERDE = Collections.unmodifiableMap(tmp);
}
@@ -35,15 +31,21 @@ class ProtoUtils {
Map<Class<? extends MessageLite>, ProtoSerDe<? extends Entity, ? extends MessageLite>> tmp =
new HashMap<>();
tmp.put(AuditInfo.class, new AuditInfoSerDe());
- tmp.put(Tenant.class, new TenantSerDe());
tmp.put(Lakehouse.class, new LakehouseSerDe());
- tmp.put(Zone.class, new ZoneSerDe());
- tmp.put(Table.class, new TableSerDe());
- tmp.put(Column.class, new ColumnSerDe());
PROTO_TO_SERDE = Collections.unmodifiableMap(tmp);
}
+ private static final Map<Class<? extends Entity>, Parser<?>> ENTITY_TO_PARSER;
+
+ static {
+ Map<Class<? extends Entity>, Parser<?>> tmp = new HashMap<>();
+ tmp.put(com.datastrato.graviton.meta.AuditInfo.class, AuditInfo.parser());
+ tmp.put(com.datastrato.graviton.meta.Lakehouse.class, Lakehouse.parser());
+
+ ENTITY_TO_PARSER = Collections.unmodifiableMap(tmp);
+ }
+
private ProtoUtils() {}
public static Timestamp fromInstant(Instant instant) {
@@ -80,13 +82,13 @@ class ProtoUtils {
}
public static <T extends Entity, M extends MessageLite> T fromBytes(
- byte[] bytes, Class<T> clazz, Parser<M> parser) {
- if (!ENTITY_TO_SERDE.containsKey(clazz)) {
- throw new ProtoSerDeException("No proto deserializer for " + clazz.getName());
+ byte[] bytes, Class<T> clazz) {
+ if (!ENTITY_TO_SERDE.containsKey(clazz) || !ENTITY_TO_PARSER.containsKey(clazz)) {
+ throw new ProtoSerDeException("No proto deserializer or parser for " + clazz.getName());
}
try {
- M message = parser.parseFrom(bytes);
+ M message = (M) ENTITY_TO_PARSER.get(clazz).parseFrom(bytes);
ProtoSerDe<T, M> protoSerDe = (ProtoSerDe<T, M>) ENTITY_TO_SERDE.get(clazz);
return protoSerDe.deserialize(message);
diff --git a/core/src/main/java/com/datastrato/graviton/schema/Column.java b/core/src/main/java/com/datastrato/graviton/schema/Column.java
deleted file mode 100644
index b0c65db52b..0000000000
--- a/core/src/main/java/com/datastrato/graviton/schema/Column.java
+++ /dev/null
@@ -1,148 +0,0 @@
-package com.datastrato.graviton.schema;
-
-import com.datastrato.graviton.schema.json.JsonUtils;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import io.substrait.type.Type;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.Nullable;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.ToString;
-
-@Getter
-@EqualsAndHashCode
-@ToString
-public final class Column implements Entity, Auditable, HasIdentifier {
-
- public static final Field ID =
- Field.required("id", Integer.class, "The unique identifier of the column");
- public static final Field ENTITY_ID =
- Field.required(
- "entity_id",
- Long.class,
- "The unique identifier of the parent entity which this column belongs to");
- public static final Field ENTITY_SNAPSHOT_ID =
- Field.required(
- "entity_snapshot_id",
- Long.class,
- "The snapshot id of the parent entity which this column belongs to");
- public static final Field NAME = Field.required("name", String.class, "The name of the column");
- public static final Field TYPE = Field.required("type", Type.class, "The type of the column");
- public static final Field COMMENT =
- Field.optional("comment", String.class, "The comment of the column");
- public static final Field POSITION =
- Field.required("position", Integer.class, "The position of the column");
- public static final Field AUDIT_INFO =
- Field.required("audit_info", AuditInfo.class, "The audit info of the column");
-
- @JsonProperty("id")
- private Integer id;
-
- @JsonProperty("entity_id")
- private Long entityId;
-
- @JsonProperty("entity_snapshot_id")
- private Long entitySnapshotId;
-
- @JsonProperty("name")
- private String name;
-
- @JsonProperty("type")
- @JsonSerialize(using = JsonUtils.TypeSerializer.class)
- @JsonDeserialize(using = JsonUtils.TypeDeserializer.class)
- private Type type;
-
- @Nullable
- @JsonProperty("comment")
- private String comment;
-
- @JsonProperty("position")
- private Integer position;
-
- @JsonProperty("audit_info")
- private AuditInfo auditInfo;
-
- private Column() {}
-
- @Override
- public Map<Field, Object> fields() {
- Map<Field, Object> fields = new HashMap<>();
- fields.put(ID, id);
- fields.put(ENTITY_ID, entityId);
- fields.put(ENTITY_SNAPSHOT_ID, entitySnapshotId);
- fields.put(NAME, name);
- fields.put(TYPE, type);
- fields.put(COMMENT, comment);
- fields.put(POSITION, position);
- fields.put(AUDIT_INFO, auditInfo);
-
- return Collections.unmodifiableMap(fields);
- }
-
- @Override
- public AuditInfo auditInfo() {
- return auditInfo;
- }
-
- @Override
- public String name() {
- return name;
- }
-
- public static class Builder {
- private final Column column;
-
- public Builder() {
- column = new Column();
- }
-
- public Builder withId(Integer id) {
- column.id = id;
- return this;
- }
-
- public Builder withEntityId(Long entityId) {
- column.entityId = entityId;
- return this;
- }
-
- public Builder withEntitySnapshotId(Long entitySnapshotId) {
- column.entitySnapshotId = entitySnapshotId;
- return this;
- }
-
- public Builder withName(String name) {
- column.name = name;
- return this;
- }
-
- public Builder withType(Type type) {
- column.type = type;
- return this;
- }
-
- public Builder withComment(String comment) {
- column.comment = comment;
- return this;
- }
-
- public Builder withPosition(Integer position) {
- column.position = position;
- return this;
- }
-
- public Builder withAuditInfo(AuditInfo auditInfo) {
- column.auditInfo = auditInfo;
- return this;
- }
-
- public Column build() {
- column.validate();
- return column;
- }
- }
-}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/HasExtraInfo.java b/core/src/main/java/com/datastrato/graviton/schema/HasExtraInfo.java
deleted file mode 100644
index e66e7041d0..0000000000
--- a/core/src/main/java/com/datastrato/graviton/schema/HasExtraInfo.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.datastrato.graviton.schema;
-
-import com.fasterxml.jackson.annotation.JsonSubTypes;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-
-/** Interface for entities that have extra info. */
-public interface HasExtraInfo {
-
- @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
- @JsonSubTypes({@JsonSubTypes.Type(value = VirtualTableInfo.class, name = "VIRTUAL")})
- interface ExtraInfo extends Entity {}
-
- /**
- * Return the extra info of the entity.
- *
- * @return the extra info of the entity.
- */
- ExtraInfo extraInfo();
-}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/Table.java b/core/src/main/java/com/datastrato/graviton/schema/Table.java
deleted file mode 100644
index 017a35cd9b..0000000000
--- a/core/src/main/java/com/datastrato/graviton/schema/Table.java
+++ /dev/null
@@ -1,177 +0,0 @@
-package com.datastrato.graviton.schema;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.*;
-import javax.annotation.Nullable;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.ToString;
-
-@Getter
-@EqualsAndHashCode
-@ToString
-public class Table implements Entity, Auditable, HasExtraInfo, HasIdentifier {
- public enum TableType {
- VIRTUAL("VIRTUAL"),
- VIEW("VIEW"),
- EXTERNAL("EXTERNAL"),
- MANAGED("MANAGED");
-
- private final String typeStr;
-
- TableType(String typeStr) {
- this.typeStr = typeStr;
- }
-
- public String getTypeStr() {
- return typeStr;
- }
- }
-
- public static final Field ID =
- Field.required("id", Long.class, "The unique identifier of the table");
- public static final Field ZONE_ID =
- Field.required(
- "zone_id", Long.class, "The unique identifier of the zone which this table belongs to");
- public static final Field NAME = Field.required("name", String.class, "The name of the table");
- public static final Field COMMENT =
- Field.optional("comment", String.class, "The comment of the table");
- public static final Field TABLE_TYPE =
- Field.required("type", TableType.class, "The type of the table");
- public static final Field SNAPSHOT_ID =
- Field.required("snapshot_id", Long.class, "The snapshot id of the table");
- public static final Field PROPERTIES =
- Field.optional("properties", Map.class, "The properties of the table");
- public static final Field AUDIT_INFO =
- Field.required("audit_info", AuditInfo.class, "The audit info of the table");
- public static final Field EXTRA_INFO =
- Field.required("extra_info", HasExtraInfo.ExtraInfo.class, "The extra info of the table");
-
- @JsonProperty("id")
- private Long id;
-
- @JsonProperty("zone_id")
- private Long zoneId;
-
- @JsonProperty("name")
- private String name;
-
- @Nullable
- @JsonProperty("comment")
- private String comment;
-
- @JsonProperty("type")
- private TableType type;
-
- @JsonProperty("snapshot_id")
- private Long snapshotId;
-
- @Nullable
- @JsonProperty("properties")
- private Map<String, String> properties;
-
- @JsonProperty("audit_info")
- private AuditInfo auditInfo;
-
- @JsonProperty("extra_info")
- private HasExtraInfo.ExtraInfo extraInfo;
-
- @JsonProperty("columns")
- private List<Column> columns;
-
- private Table() {}
-
- @Override
- public Map<Field, Object> fields() {
- Map<Field, Object> fields = new HashMap<>();
- fields.put(ID, id);
- fields.put(ZONE_ID, zoneId);
- fields.put(NAME, name);
- fields.put(COMMENT, comment);
- fields.put(TABLE_TYPE, type);
- fields.put(SNAPSHOT_ID, snapshotId);
- fields.put(PROPERTIES, properties);
- fields.put(AUDIT_INFO, auditInfo);
- fields.put(EXTRA_INFO, extraInfo);
-
- return Collections.unmodifiableMap(fields);
- }
-
- @Override
- public AuditInfo auditInfo() {
- return auditInfo;
- }
-
- @Override
- public HasExtraInfo.ExtraInfo extraInfo() {
- return extraInfo;
- }
-
- @Override
- public String name() {
- return name;
- }
-
- public static class Builder {
- private final Table table;
-
- public Builder() {
- table = new Table();
- }
-
- public Builder withId(Long id) {
- table.id = id;
- return this;
- }
-
- public Builder withZoneId(Long zoneId) {
- table.zoneId = zoneId;
- return this;
- }
-
- public Builder withName(String name) {
- table.name = name;
- return this;
- }
-
- public Builder withComment(String comment) {
- table.comment = comment;
- return this;
- }
-
- public Builder withType(TableType type) {
- table.type = type;
- return this;
- }
-
- public Builder withSnapshotId(Long snapshotId) {
- table.snapshotId = snapshotId;
- return this;
- }
-
- public Builder withProperties(Map<String, String> properties) {
- table.properties = properties;
- return this;
- }
-
- public Builder withAuditInfo(AuditInfo auditInfo) {
- table.auditInfo = auditInfo;
- return this;
- }
-
- public Builder withExtraInfo(HasExtraInfo.ExtraInfo extraInfo) {
- table.extraInfo = extraInfo;
- return this;
- }
-
- public Builder withColumns(List<Column> columns) {
- table.columns = columns;
- return this;
- }
-
- public Table build() {
- table.validate();
- return table;
- }
- }
-}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/Tenant.java b/core/src/main/java/com/datastrato/graviton/schema/Tenant.java
deleted file mode 100644
index 3978ec4e6f..0000000000
--- a/core/src/main/java/com/datastrato/graviton/schema/Tenant.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package com.datastrato.graviton.schema;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.Nullable;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.ToString;
-
-@Getter
-@EqualsAndHashCode
-@ToString
-public final class Tenant implements Entity, Auditable, HasIdentifier {
-
- public static final Field ID =
- Field.required("id", Integer.class, "The unique identifier of the tenant");
- public static final Field NAME = Field.required("name", String.class, "The name of the tenant");
- public static final Field COMMENT =
- Field.optional("comment", String.class, "The comment of the tenant");
- public static final Field AUDIT_INFO =
- Field.required("audit_info", AuditInfo.class, "The audit info of the tenant");
- public static final Field VERSION =
- Field.required("version", SchemaVersion.class, "The version of the tenant");
-
- @JsonProperty("id")
- private Integer id;
-
- @JsonProperty("name")
- private String name;
-
- @Nullable
- @JsonProperty("comment")
- private String comment;
-
- @JsonProperty("audit_info")
- private AuditInfo auditInfo;
-
- @JsonProperty("version")
- private SchemaVersion version;
-
- private Tenant() {}
-
- @Override
- public Map<Field, Object> fields() {
- Map<Field, Object> fields = new HashMap<>();
- fields.put(ID, id);
- fields.put(NAME, name);
- fields.put(COMMENT, comment);
- fields.put(AUDIT_INFO, auditInfo);
- fields.put(VERSION, version);
-
- return Collections.unmodifiableMap(fields);
- }
-
- @Override
- public AuditInfo auditInfo() {
- return auditInfo;
- }
-
- @Override
- public String name() {
- return name;
- }
-
- public static class Builder {
- private final Tenant tenant;
-
- public Builder() {
- this.tenant = new Tenant();
- }
-
- public Builder withId(Integer id) {
- this.tenant.id = id;
- return this;
- }
-
- public Builder withName(String name) {
- this.tenant.name = name;
- return this;
- }
-
- public Builder withComment(String comment) {
- this.tenant.comment = comment;
- return this;
- }
-
- public Builder withAuditInfo(AuditInfo auditInfo) {
- this.tenant.auditInfo = auditInfo;
- return this;
- }
-
- public Builder withVersion(SchemaVersion version) {
- this.tenant.version = version;
- return this;
- }
-
- public Tenant build() {
- tenant.validate();
- return tenant;
- }
- }
-}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/VirtualTableInfo.java b/core/src/main/java/com/datastrato/graviton/schema/VirtualTableInfo.java
deleted file mode 100644
index 4ebcb63979..0000000000
--- a/core/src/main/java/com/datastrato/graviton/schema/VirtualTableInfo.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.datastrato.graviton.schema;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.ImmutableMap;
-import java.util.List;
-import java.util.Map;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.ToString;
-
-@Getter
-@EqualsAndHashCode
-@ToString
-public final class VirtualTableInfo implements HasExtraInfo.ExtraInfo {
-
- public static final Field CONNECTION_ID =
- Field.required("connection_id", Integer.class, "The unique identifier of the connection");
- public static final Field IDENTIFIER =
- Field.required("identifier", List.class, "The unique identifier of the table");
-
- @JsonProperty("connection_id")
- private final Integer connectionId;
-
- @JsonProperty("identifier")
- private final List<String> identifier;
-
- // Only for Jackson deserialization
- private VirtualTableInfo() {
- this.connectionId = null;
- this.identifier = null;
- }
-
- public VirtualTableInfo(Integer connectionId, List<String> identifier) {
- this.connectionId = connectionId;
- this.identifier = identifier;
- this.validate();
- }
-
- @Override
- public Map<Field, Object> fields() {
- return new ImmutableMap.Builder<Field, Object>()
- .put(CONNECTION_ID, connectionId)
- .put(IDENTIFIER, identifier)
- .build();
- }
-}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/Zone.java b/core/src/main/java/com/datastrato/graviton/schema/Zone.java
deleted file mode 100644
index b1a93ed35a..0000000000
--- a/core/src/main/java/com/datastrato/graviton/schema/Zone.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package com.datastrato.graviton.schema;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.Nullable;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.ToString;
-
-@Getter
-@EqualsAndHashCode
-@ToString
-public class Zone implements Entity, Auditable, HasIdentifier {
-
- public static final Field ID =
- Field.required("id", Long.class, "The unique identifier of the zone");
- public static final Field LAKEHOUSE_ID =
- Field.required("lakehouse_id", Long.class, "The unique identifier of the lakehouse");
- public static final Field NAME = Field.required("name", String.class, "The name of the zone");
- public static final Field COMMENT =
- Field.optional("comment", String.class, "The comment of the zone");
- public static final Field PROPERTIES =
- Field.optional("properties", Map.class, "The properties of the zone");
- public static final Field AUDIT_INFO =
- Field.required("audit_info", AuditInfo.class, "The audit info of the zone");
-
- @JsonProperty("id")
- private Long id;
-
- @JsonProperty("lakehouse_id")
- private Long lakehouseId;
-
- @JsonProperty("name")
- private String name;
-
- @Nullable
- @JsonProperty("comment")
- private String comment;
-
- @Nullable
- @JsonProperty("properties")
- private Map<String, String> properties;
-
- @JsonProperty("audit_info")
- private AuditInfo auditInfo;
-
- private Zone() {}
-
- @Override
- public Map<Field, Object> fields() {
- Map<Field, Object> fields = new HashMap<>();
- fields.put(ID, id);
- fields.put(LAKEHOUSE_ID, lakehouseId);
- fields.put(NAME, name);
- fields.put(COMMENT, comment);
- fields.put(PROPERTIES, properties);
- fields.put(AUDIT_INFO, auditInfo);
-
- return Collections.unmodifiableMap(fields);
- }
-
- @Override
- public AuditInfo auditInfo() {
- return auditInfo;
- }
-
- @Override
- public String name() {
- return name;
- }
-
- public static class Builder {
- private final Zone zone;
-
- public Builder() {
- zone = new Zone();
- }
-
- public Builder withId(Long id) {
- zone.id = id;
- return this;
- }
-
- public Builder withLakehouseId(Long lakehouseId) {
- zone.lakehouseId = lakehouseId;
- return this;
- }
-
- public Builder withName(String name) {
- zone.name = name;
- return this;
- }
-
- public Builder withComment(String comment) {
- zone.comment = comment;
- return this;
- }
-
- public Builder withProperties(Map<String, String> properties) {
- zone.properties = properties;
- return this;
- }
-
- public Builder withAuditInfo(AuditInfo auditInfo) {
- zone.auditInfo = auditInfo;
- return this;
- }
-
- public Zone build() {
- zone.validate();
- return zone;
- }
- }
-}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/proto/ColumnSerDe.java b/core/src/main/java/com/datastrato/graviton/schema/proto/ColumnSerDe.java
deleted file mode 100644
index e28bd9676b..0000000000
--- a/core/src/main/java/com/datastrato/graviton/schema/proto/ColumnSerDe.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.datastrato.graviton.schema.proto;
-
-import io.substrait.type.proto.FromProto;
-import io.substrait.type.proto.TypeProtoConverter;
-
-class ColumnSerDe implements ProtoSerDe<com.datastrato.graviton.schema.Column, Column> {
-
- @Override
- public Column serialize(com.datastrato.graviton.schema.Column column) {
- Column.Builder builder = Column.newBuilder();
- builder
- .setId(column.getId())
- .setName(column.getName())
- .setEntityId(column.getEntityId())
- .setEntitySnapshotId(column.getEntitySnapshotId())
- .setType(column.getType().accept(TypeProtoConverter.INSTANCE))
- .setPosition(column.getPosition())
- .setAuditInfo(new AuditInfoSerDe().serialize(column.auditInfo()));
-
- if (column.getComment() != null) {
- builder.setComment(column.getComment());
- }
-
- return builder.build();
- }
-
- @Override
- public com.datastrato.graviton.schema.Column deserialize(Column p) {
- com.datastrato.graviton.schema.Column.Builder builder =
- new com.datastrato.graviton.schema.Column.Builder();
- builder
- .withId(p.getId())
- .withName(p.getName())
- .withEntityId(p.getEntityId())
- .withEntitySnapshotId(p.getEntitySnapshotId())
- .withType(FromProto.from(p.getType()))
- .withPosition(p.getPosition())
- .withAuditInfo(new AuditInfoSerDe().deserialize(p.getAuditInfo()));
-
- if (p.hasComment()) {
- builder.withComment(p.getComment());
- }
-
- return builder.build();
- }
-}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/proto/TableSerDe.java b/core/src/main/java/com/datastrato/graviton/schema/proto/TableSerDe.java
deleted file mode 100644
index 942f11f2a8..0000000000
--- a/core/src/main/java/com/datastrato/graviton/schema/proto/TableSerDe.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package com.datastrato.graviton.schema.proto;
-
-import com.datastrato.graviton.schema.HasExtraInfo;
-import com.datastrato.graviton.schema.VirtualTableInfo;
-
-class TableSerDe implements ProtoSerDe<com.datastrato.graviton.schema.Table, Table> {
-
- @Override
- public Table serialize(com.datastrato.graviton.schema.Table table) {
- Table.Builder builder = Table.newBuilder();
- builder
- .setId(table.getId())
- .setZoneId(table.getZoneId())
- .setName(table.getName())
- .setType(Table.TableType.valueOf(table.getType().getTypeStr()))
- .setSnapshotId(table.getSnapshotId())
- .setAuditInfo(new AuditInfoSerDe().serialize(table.auditInfo()));
-
- if (table.getComment() != null) {
- builder.setComment(table.getComment());
- }
-
- if (table.getProperties() != null && !table.getProperties().isEmpty()) {
- builder.putAllProperties(table.getProperties());
- }
-
- setTableExtraInfo(builder, table.getType(), table.getExtraInfo());
-
- return builder.build();
- }
-
- @Override
- public com.datastrato.graviton.schema.Table deserialize(Table p) {
- com.datastrato.graviton.schema.Table.Builder builder =
- new com.datastrato.graviton.schema.Table.Builder();
- builder
- .withId(p.getId())
- .withZoneId(p.getZoneId())
- .withName(p.getName())
- .withType(com.datastrato.graviton.schema.Table.TableType.valueOf(p.getType().name()))
- .withSnapshotId(p.getSnapshotId())
- .withAuditInfo(new AuditInfoSerDe().deserialize(p.getAuditInfo()));
-
- if (p.hasComment()) {
- builder.withComment(p.getComment());
- }
-
- if (p.getPropertiesCount() > 0) {
- builder.withProperties(p.getPropertiesMap());
- }
-
- builder.withExtraInfo(
- getTableExtraInfo(
- com.datastrato.graviton.schema.Table.TableType.valueOf(p.getType().name()), p));
-
- return builder.build();
- }
-
- private void setTableExtraInfo(
- Table.Builder builder,
- com.datastrato.graviton.schema.Table.TableType tableType,
- HasExtraInfo.ExtraInfo tableExtraInfo) {
- switch (tableType) {
- case VIRTUAL:
- VirtualTableInfo virtualTableInfo = (VirtualTableInfo) tableExtraInfo;
- builder.setVirtualTable(
- Table.VirtualTableInfo.newBuilder()
- .setConnectionId(virtualTableInfo.getConnectionId())
- .addAllTableIdentifier(virtualTableInfo.getIdentifier())
- .build());
- break;
-
- case VIEW:
- case EXTERNAL:
- case MANAGED:
- // TODO. Add support for these types.
- throw new ProtoSerDeException("Table type " + tableType + " is not supported yet.");
-
- default:
- throw new ProtoSerDeException("Unknown table type " + tableType + ".");
- }
- }
-
- private HasExtraInfo.ExtraInfo getTableExtraInfo(
- com.datastrato.graviton.schema.Table.TableType tableType, Table p) {
- switch (tableType) {
- case VIRTUAL:
- if (!p.hasVirtualTable()) {
- throw new ProtoSerDeException("Virtual table info is missing.");
- }
-
- return new VirtualTableInfo(
- p.getVirtualTable().getConnectionId(), p.getVirtualTable().getTableIdentifierList());
-
- case VIEW:
- case EXTERNAL:
- case MANAGED:
- // TODO. Add support for these types.
- throw new ProtoSerDeException("Table type " + tableType + " is not supported yet.");
-
- default:
- throw new ProtoSerDeException("Unknown table type " + tableType + ".");
- }
- }
-}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/proto/TenantSerDe.java b/core/src/main/java/com/datastrato/graviton/schema/proto/TenantSerDe.java
deleted file mode 100644
index 54b48d3069..0000000000
--- a/core/src/main/java/com/datastrato/graviton/schema/proto/TenantSerDe.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.datastrato.graviton.schema.proto;
-
-class TenantSerDe implements ProtoSerDe<com.datastrato.graviton.schema.Tenant, Tenant> {
- @Override
- public Tenant serialize(com.datastrato.graviton.schema.Tenant tenant) {
- Tenant.Builder builder =
- Tenant.newBuilder()
- .setId(tenant.getId())
- .setName(tenant.getName())
- .setAuditInfo(new AuditInfoSerDe().serialize(tenant.auditInfo()));
-
- if (tenant.getComment() != null) {
- builder.setComment(tenant.getComment());
- }
-
- SchemaVersion version =
- SchemaVersion.newBuilder()
- .setMajorNumber(tenant.getVersion().majorVersion)
- .setMinorNumber(tenant.getVersion().minorVersion)
- .build();
-
- builder.setVersion(version);
-
- return builder.build();
- }
-
- @Override
- public com.datastrato.graviton.schema.Tenant deserialize(Tenant p) {
- com.datastrato.graviton.schema.Tenant.Builder builder =
- new com.datastrato.graviton.schema.Tenant.Builder();
- builder
- .withId(p.getId())
- .withName(p.getName())
- .withAuditInfo(new AuditInfoSerDe().deserialize(p.getAuditInfo()));
-
- if (p.hasComment()) {
- builder.withComment(p.getComment());
- }
-
- com.datastrato.graviton.schema.SchemaVersion version =
- com.datastrato.graviton.schema.SchemaVersion.forValues(
- p.getVersion().getMajorNumber(), p.getVersion().getMinorNumber());
- builder.withVersion(version);
-
- return builder.build();
- }
-}
diff --git a/core/src/main/java/com/datastrato/graviton/schema/proto/ZoneSerDe.java b/core/src/main/java/com/datastrato/graviton/schema/proto/ZoneSerDe.java
deleted file mode 100644
index 5e70cc5f6e..0000000000
--- a/core/src/main/java/com/datastrato/graviton/schema/proto/ZoneSerDe.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.datastrato.graviton.schema.proto;
-
-class ZoneSerDe implements ProtoSerDe<com.datastrato.graviton.schema.Zone, Zone> {
- @Override
- public Zone serialize(com.datastrato.graviton.schema.Zone zone) {
- Zone.Builder builder =
- Zone.newBuilder()
- .setId(zone.getId())
- .setLakehouseId(zone.getLakehouseId())
- .setName(zone.getName())
- .setAuditInfo(new AuditInfoSerDe().serialize(zone.auditInfo()));
-
- if (zone.getComment() != null) {
- builder.setComment(zone.getComment());
- }
-
- if (zone.getProperties() != null && !zone.getProperties().isEmpty()) {
- builder.putAllProperties(zone.getProperties());
- }
-
- return builder.build();
- }
-
- @Override
- public com.datastrato.graviton.schema.Zone deserialize(Zone p) {
- com.datastrato.graviton.schema.Zone.Builder builder =
- new com.datastrato.graviton.schema.Zone.Builder();
- builder
- .withId(p.getId())
- .withLakehouseId(p.getLakehouseId())
- .withName(p.getName())
- .withAuditInfo(new AuditInfoSerDe().deserialize(p.getAuditInfo()));
-
- if (p.hasComment()) {
- builder.withComment(p.getComment());
- }
-
- if (p.getPropertiesCount() > 0) {
- builder.withProperties(p.getPropertiesMap());
- }
-
- return builder.build();
- }
-}
diff --git a/core/src/test/java/com/datastrato/graviton/json/TestColumn.java b/core/src/test/java/com/datastrato/graviton/json/TestColumn.java
new file mode 100644
index 0000000000..2a1d9844a1
--- /dev/null
+++ b/core/src/test/java/com/datastrato/graviton/json/TestColumn.java
@@ -0,0 +1,78 @@
+package com.datastrato.graviton.json;
+
+import com.datastrato.graviton.Field;
+import com.datastrato.graviton.meta.AuditInfo;
+import com.datastrato.graviton.meta.catalog.rel.Column;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.substrait.type.Type;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+
+@EqualsAndHashCode
+@ToString
+public class TestColumn implements Column {
+
+ public static final Field NAME = Field.required("name", String.class, "The name of the column");
+ public static final Field COMMENT =
+ Field.optional("comment", String.class, "The comment of the column");
+ public static final Field TYPE = Field.required("type", Type.class, "The type of the column");
+ public static final Field AUDIT_INFO =
+ Field.required("audit_info", AuditInfo.class, "The audit info of the column");
+
+ private String name;
+
+ private String comment;
+
+ private Type dataType;
+
+ private AuditInfo auditInfo;
+
+ public TestColumn(String name, String comment, Type dataType, AuditInfo auditInfo) {
+ this.name = name;
+ this.comment = comment;
+ this.dataType = dataType;
+ this.auditInfo = auditInfo;
+
+ validate();
+ }
+
+ // For Jackson Deserialization only.
+ public TestColumn() {}
+
+ @Override
+ public Map<Field, Object> fields() {
+ Map<Field, Object> fields = new HashMap<>();
+ fields.put(NAME, name);
+ fields.put(COMMENT, comment);
+ fields.put(TYPE, dataType);
+ fields.put(AUDIT_INFO, auditInfo);
+
+ return Collections.unmodifiableMap(fields);
+ }
+
+ @JsonProperty("audit_info")
+ @Override
+ public AuditInfo auditInfo() {
+ return auditInfo;
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public Type dataType() {
+ return dataType;
+ }
+
+ @Nullable
+ @Override
+ public String comment() {
+ return comment;
+ }
+}
diff --git a/core/src/test/java/com/datastrato/graviton/json/TestEntityJsonSerDe.java b/core/src/test/java/com/datastrato/graviton/json/TestEntityJsonSerDe.java
new file mode 100644
index 0000000000..dd4f2f1e84
--- /dev/null
+++ b/core/src/test/java/com/datastrato/graviton/json/TestEntityJsonSerDe.java
@@ -0,0 +1,196 @@
+package com.datastrato.graviton.json;
+
+import com.datastrato.graviton.meta.*;
+import com.datastrato.graviton.meta.AuditInfo;
+import com.datastrato.graviton.meta.catalog.rel.Column;
+import com.datastrato.graviton.meta.catalog.rel.Table;
+import com.google.common.collect.ImmutableMap;
+import io.substrait.type.StringTypeVisitor;
+import io.substrait.type.TypeCreator;
+import java.time.Instant;
+import java.util.Map;
+import org.junit.jupiter.api.*;
+
+public class TestEntityJsonSerDe {
+
+ private final String auditInfoJson =
+ "{\"creator\":%s,\"create_time\":%s,\"last_modifier\":%s,\"last_modified_time\":%s}";
+
+ private final String lakehouseJson =
+ "{\"id\":%d,\"name\":%s,\"comment\":%s,\"properties\":%s,\"audit_info\":%s,"
+ + "\"version\":{\"major_version\":%d,\"minor_version\":%d}}";
+
+ private final String testColumnJson =
+ "{\"name\":%s,\"comment\":%s,\"type\":%s,\"audit_info\":%s}";
+
+ private final String testTableJson =
+ "{\"name\":%s,\"comment\":%s,\"properties\":%s,\"audit_info\":%s,\"columns\":[%s]}";
+
+ private String withQuotes(String str) {
+ return "\"" + str + "\"";
+ }
+
+ @Test
+ public void testAuditInfoJsonSerDe() throws Exception {
+ Instant now = Instant.now();
+ String creator = "creator";
+ String modifier = "modifier";
+ String accessor = "accessor";
+
+ // Test with required fields
+ AuditInfo info = new AuditInfo.Builder().withCreator(creator).withCreateTime(now).build();
+
+ String serJson = JsonUtils.objectMapper().writeValueAsString(info);
+ String expectedJson =
+ String.format(auditInfoJson, withQuotes(creator), withQuotes(now.toString()), null, null);
+ Assertions.assertEquals(expectedJson, serJson);
+ AuditInfo deserInfo = JsonUtils.objectMapper().readValue(serJson, AuditInfo.class);
+ Assertions.assertEquals(info, deserInfo);
+
+ // Test with optional fields
+ AuditInfo info1 =
+ new AuditInfo.Builder()
+ .withCreator(creator)
+ .withCreateTime(now)
+ .withLastModifier(modifier)
+ .withLastModifiedTime(now)
+ .build();
+
+ String serJson1 = JsonUtils.objectMapper().writeValueAsString(info1);
+ String expectedJson1 =
+ String.format(
+ auditInfoJson,
+ withQuotes(creator),
+ withQuotes(now.toString()),
+ withQuotes(modifier),
+ withQuotes(now.toString()));
+ Assertions.assertEquals(expectedJson1, serJson1);
+ AuditInfo deserInfo1 = JsonUtils.objectMapper().readValue(serJson1, AuditInfo.class);
+ Assertions.assertEquals(info1, deserInfo1);
+ }
+
+ @Test
+ public void testLakehouseSerDe() throws Exception {
+ Long id = 1L;
+ String name = "lakehouse";
+ String comment = "comment";
+ Map<String, String> properties = ImmutableMap.of("k1", "v1", "k2", "v2");
+ String creator = "creator";
+ Instant now = Instant.now();
+ AuditInfo info = new AuditInfo.Builder().withCreator(creator).withCreateTime(now).build();
+ SchemaVersion version = SchemaVersion.V_0_1;
+
+ // Test with required fields
+ Lakehouse lakehouse =
+ new Lakehouse.Builder()
+ .withId(id)
+ .withName(name)
+ .withComment(comment)
+ .withProperties(properties)
+ .withAuditInfo(info)
+ .withVersion(version)
+ .build();
+
+ String serJson = JsonUtils.objectMapper().writeValueAsString(lakehouse);
+ String expectedJson =
+ String.format(
+ lakehouseJson,
+ id,
+ withQuotes(name),
+ withQuotes(comment),
+ JsonUtils.objectMapper().writeValueAsString(properties),
+ String.format(
+ auditInfoJson, withQuotes(creator), withQuotes(now.toString()), null, null),
+ version.getMajorVersion(),
+ version.getMinorVersion());
+ Assertions.assertEquals(expectedJson, serJson);
+ Lakehouse deserLakehouse = JsonUtils.objectMapper().readValue(serJson, Lakehouse.class);
+ Assertions.assertEquals(lakehouse, deserLakehouse);
+
+ // Test with optional fields
+ Lakehouse lakehouse1 =
+ new Lakehouse.Builder()
+ .withId(id)
+ .withName(name)
+ .withAuditInfo(info)
+ .withVersion(version)
+ .build();
+
+ String serJson1 = JsonUtils.objectMapper().writeValueAsString(lakehouse1);
+ String expectedJson1 =
+ String.format(
+ lakehouseJson,
+ id,
+ withQuotes(name),
+ null,
+ null,
+ String.format(
+ auditInfoJson, withQuotes(creator), withQuotes(now.toString()), null, null),
+ version.getMajorVersion(),
+ version.getMinorVersion());
+ Assertions.assertEquals(expectedJson1, serJson1);
+ Lakehouse deserLakehouse1 = JsonUtils.objectMapper().readValue(serJson1, Lakehouse.class);
+ Assertions.assertEquals(lakehouse1, deserLakehouse1);
+ }
+
+ @Test
+ public void testColumnSerDe() throws Exception {
+ String name = "column";
+ io.substrait.type.Type type = TypeCreator.NULLABLE.I8;
+ String comment = "comment";
+ String creator = "creator";
+ Instant now = Instant.now();
+ AuditInfo info = new AuditInfo.Builder().withCreator(creator).withCreateTime(now).build();
+
+ // Test required fields
+ Column column = new TestColumn(name, comment, type, info);
+ String serJson = JsonUtils.objectMapper().writeValueAsString(column);
+ String expectedJson =
+ String.format(
+ testColumnJson,
+ withQuotes(name),
+ withQuotes(comment),
+ withQuotes(type.accept(new StringTypeVisitor())),
+ String.format(
+ auditInfoJson, withQuotes(creator), withQuotes(now.toString()), null, null),
+ type.nullable());
+ Assertions.assertEquals(expectedJson, serJson);
+ Column deserColumn = JsonUtils.objectMapper().readValue(serJson, TestColumn.class);
+ Assertions.assertEquals(column, deserColumn);
+ }
+
+ @Test
+ public void testTableSerDe() throws Exception {
+ String name = "column";
+ io.substrait.type.Type type = TypeCreator.NULLABLE.I8;
+ String comment = "comment";
+ String creator = "creator";
+ Instant now = Instant.now();
+ AuditInfo info = new AuditInfo.Builder().withCreator(creator).withCreateTime(now).build();
+
+ String tableName = "table";
+ String tableComment = "comment";
+ Map<String, String> properties = ImmutableMap.of("k1", "v1", "k2", "v2");
+
+ Column column = new TestColumn(name, comment, type, info);
+ Table table = new TestTable(tableName, tableComment, properties, info, new Column[] {column});
+
+ String serJson = JsonUtils.objectMapper().writeValueAsString(table);
+ String expectedJson =
+ String.format(
+ testTableJson,
+ withQuotes(tableName),
+ withQuotes(tableComment),
+ JsonUtils.objectMapper().writeValueAsString(properties),
+ String.format(
+ auditInfoJson, withQuotes(creator), withQuotes(now.toString()), null, null),
+ String.format(
+ testColumnJson,
+ withQuotes(name),
+ withQuotes(comment),
+ withQuotes(type.accept(new StringTypeVisitor())),
+ String.format(
+ auditInfoJson, withQuotes(creator), withQuotes(now.toString()), null, null)));
+ Assertions.assertEquals(expectedJson, serJson);
+ }
+}
diff --git a/core/src/test/java/com/datastrato/graviton/json/TestTable.java b/core/src/test/java/com/datastrato/graviton/json/TestTable.java
new file mode 100644
index 0000000000..95ba9490ba
--- /dev/null
+++ b/core/src/test/java/com/datastrato/graviton/json/TestTable.java
@@ -0,0 +1,86 @@
+package com.datastrato.graviton.json;
+
+import com.datastrato.graviton.Field;
+import com.datastrato.graviton.meta.AuditInfo;
+import com.datastrato.graviton.meta.catalog.rel.Column;
+import com.datastrato.graviton.meta.catalog.rel.Table;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class TestTable implements Table {
+
+ public static final Field NAME = Field.required("name", String.class, "The name of the table");
+ public static final Field COMMENT =
+ Field.optional("comment", String.class, "The comment of the table");
+ public static final Field PROPERTIES =
+ Field.optional("properties", Map.class, "The properties of the table");
+ public static final Field AUDIT_INFO =
+ Field.required("audit_info", AuditInfo.class, "The audit info of the table");
+
+ private String name;
+
+ private String comment;
+
+ private Map<String, String> properties;
+
+ private AuditInfo auditInfo;
+
+ private Column[] columns;
+
+ public TestTable(
+ String name,
+ String comment,
+ Map<String, String> properties,
+ AuditInfo auditInfo,
+ Column[] columns) {
+ this.name = name;
+ this.comment = comment;
+ this.properties = properties;
+ this.auditInfo = auditInfo;
+ this.columns = columns;
+
+ validate();
+ }
+
+ // For Jackson Deserialization only.
+ public TestTable() {}
+
+ @Override
+ public Map<Field, Object> fields() {
+ Map<Field, Object> fields = new HashMap<>();
+ fields.put(NAME, name);
+ fields.put(COMMENT, comment);
+ fields.put(PROPERTIES, properties);
+ fields.put(AUDIT_INFO, auditInfo);
+
+ return Collections.unmodifiableMap(fields);
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @JsonProperty("audit_info")
+ @Override
+ public AuditInfo auditInfo() {
+ return auditInfo;
+ }
+
+ @Override
+ public Column[] columns() {
+ return columns;
+ }
+
+ @Override
+ public String comment() {
+ return comment;
+ }
+
+ @Override
+ public Map<String, String> properties() {
+ return properties;
+ }
+}
diff --git a/core/src/test/java/com/datastrato/graviton/schema/TestAuditInfo.java b/core/src/test/java/com/datastrato/graviton/meta/TestAuditInfo.java
similarity index 67%
rename from core/src/test/java/com/datastrato/graviton/schema/TestAuditInfo.java
rename to core/src/test/java/com/datastrato/graviton/meta/TestAuditInfo.java
index cca243a4db..b2c98875c7 100644
--- a/core/src/test/java/com/datastrato/graviton/schema/TestAuditInfo.java
+++ b/core/src/test/java/com/datastrato/graviton/meta/TestAuditInfo.java
@@ -1,4 +1,4 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton.meta;
import java.time.Instant;
import org.junit.jupiter.api.Assertions;
@@ -11,7 +11,6 @@ public class TestAuditInfo {
Instant now = Instant.now();
String creator = "test";
String lastModifier = "test1";
- String lastAccessUser = "test2";
AuditInfo auditInfo =
new AuditInfo.Builder()
@@ -19,8 +18,6 @@ public class TestAuditInfo {
.withCreateTime(now)
.withLastModifier(lastModifier)
.withLastModifiedTime(now)
- .withLastAccessUser(lastAccessUser)
- .withLastAccessTime(now)
.build();
auditInfo.validate();
@@ -29,8 +26,6 @@ public class TestAuditInfo {
Assertions.assertEquals(now, auditInfo.getCreateTime());
Assertions.assertEquals(lastModifier, auditInfo.getLastModifier());
Assertions.assertEquals(now, auditInfo.getLastModifiedTime());
- Assertions.assertEquals(lastAccessUser, auditInfo.getLastAccessUser());
- Assertions.assertEquals(now, auditInfo.getLastAccessTime());
}
@Test
@@ -38,15 +33,12 @@ public class TestAuditInfo {
Instant now = Instant.now();
String creator = "test";
String lastModifier = "test1";
- String lastAccessUser = "test2";
AuditInfo auditInfo = new AuditInfo.Builder().withCreator(creator).withCreateTime(now).build();
auditInfo.validate();
Assertions.assertNull(auditInfo.getLastModifier());
Assertions.assertNull(auditInfo.getLastModifiedTime());
- Assertions.assertNull(auditInfo.getLastAccessUser());
- Assertions.assertNull(auditInfo.getLastAccessTime());
Throwable exception =
Assertions.assertThrows(
@@ -67,19 +59,5 @@ public class TestAuditInfo {
Assertions.assertEquals(
"last_modifier and last_modified_time must be both set or both not set",
exception1.getMessage());
-
- Throwable exception2 =
- Assertions.assertThrows(
- IllegalArgumentException.class,
- () -> {
- new AuditInfo.Builder()
- .withCreator(creator)
- .withCreateTime(now)
- .withLastAccessUser(lastAccessUser)
- .build();
- });
- Assertions.assertEquals(
- "last_access_user and last_access_time must be both set or both not set",
- exception2.getMessage());
}
}
diff --git a/core/src/test/java/com/datastrato/graviton/meta/TestCatalog.java b/core/src/test/java/com/datastrato/graviton/meta/TestCatalog.java
new file mode 100644
index 0000000000..dad2d2f4f6
--- /dev/null
+++ b/core/src/test/java/com/datastrato/graviton/meta/TestCatalog.java
@@ -0,0 +1,31 @@
+package com.datastrato.graviton.meta;
+
+import com.datastrato.graviton.Config;
+import java.io.IOException;
+
+public class TestCatalog extends BaseCatalog {
+
+ @Override
+ public void initialize(Config config) throws RuntimeException {}
+
+ @Override
+ public void close() throws IOException {}
+
+ public static class Builder extends BaseCatalog.BaseCatalogBuilder<Builder, TestCatalog> {
+
+ TestCatalog testCatalog = new TestCatalog();
+
+ @Override
+ protected TestCatalog internalBuild() {
+ testCatalog.id = id;
+ testCatalog.lakehouseId = lakehouseId;
+ testCatalog.name = name;
+ testCatalog.type = type;
+ testCatalog.comment = comment;
+ testCatalog.properties = properties;
+ testCatalog.auditInfo = auditInfo;
+
+ return testCatalog;
+ }
+ }
+}
diff --git a/core/src/test/java/com/datastrato/graviton/meta/TestEntity.java b/core/src/test/java/com/datastrato/graviton/meta/TestEntity.java
new file mode 100644
index 0000000000..39d8275f37
--- /dev/null
+++ b/core/src/test/java/com/datastrato/graviton/meta/TestEntity.java
@@ -0,0 +1,70 @@
+package com.datastrato.graviton.meta;
+
+import com.datastrato.graviton.Field;
+import com.google.common.collect.ImmutableMap;
+import java.time.Instant;
+import java.util.Map;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestEntity {
+ private final Instant now = Instant.now();
+
+ private final SchemaVersion version = SchemaVersion.V_0_1;
+ private final AuditInfo auditInfo =
+ new AuditInfo.Builder().withCreator("test").withCreateTime(now).build();
+
+ // Lakehouse test data
+ private final Long lakehouseId = 1L;
+ private final String lakehouseName = "testLakehouse";
+ private final Map<String, String> map = ImmutableMap.of("k1", "v1", "k2", "v2");
+
+ // Catalog test data
+ private final Long catalogId = 1L;
+ private final String catalogName = "testCatalog";
+ private final BaseCatalog.Type type = BaseCatalog.Type.RELATIONAL;
+ private final String catalogComment = "testComment";
+
+ @Test
+ public void testLakehouse() {
+ Lakehouse lakehouse =
+ new Lakehouse.Builder()
+ .withId(lakehouseId)
+ .withName(lakehouseName)
+ .withAuditInfo(auditInfo)
+ .withProperties(map)
+ .withVersion(version)
+ .build();
+
+ Map<Field, Object> fields = lakehouse.fields();
+ Assertions.assertEquals(lakehouseId, fields.get(Lakehouse.ID));
+ Assertions.assertEquals(lakehouseName, fields.get(Lakehouse.NAME));
+ Assertions.assertEquals(map, fields.get(Lakehouse.PROPERTIES));
+ Assertions.assertEquals(auditInfo, fields.get(Lakehouse.AUDIT_INFO));
+ Assertions.assertNull(fields.get(Lakehouse.COMMENT));
+ Assertions.assertEquals(version, fields.get(Lakehouse.SCHEMA_VERSION));
+ }
+
+ @Test
+ public void testCatalog() {
+ TestCatalog testCatalog =
+ new TestCatalog.Builder()
+ .withId(catalogId)
+ .withLakehouseId(lakehouseId)
+ .withName(catalogName)
+ .withComment(catalogComment)
+ .withType(type)
+ .withProperties(map)
+ .withAuditInfo(auditInfo)
+ .build();
+
+ Map<Field, Object> fields = testCatalog.fields();
+ Assertions.assertEquals(catalogId, fields.get(TestCatalog.ID));
+ Assertions.assertEquals(lakehouseId, fields.get(TestCatalog.LAKEHOUSE_ID));
+ Assertions.assertEquals(catalogName, fields.get(TestCatalog.NAME));
+ Assertions.assertEquals(catalogComment, fields.get(TestCatalog.COMMENT));
+ Assertions.assertEquals(type, fields.get(TestCatalog.TYPE));
+ Assertions.assertEquals(map, fields.get(TestCatalog.PROPERTIES));
+ Assertions.assertEquals(auditInfo, fields.get(TestCatalog.AUDIT_INFO));
+ }
+}
diff --git a/core/src/test/java/com/datastrato/graviton/schema/TestField.java b/core/src/test/java/com/datastrato/graviton/meta/TestField.java
similarity index 94%
rename from core/src/test/java/com/datastrato/graviton/schema/TestField.java
rename to core/src/test/java/com/datastrato/graviton/meta/TestField.java
index 5ce5162c74..1c8a921753 100644
--- a/core/src/test/java/com/datastrato/graviton/schema/TestField.java
+++ b/core/src/test/java/com/datastrato/graviton/meta/TestField.java
@@ -1,5 +1,6 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton.meta;
+import com.datastrato.graviton.Field;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
diff --git a/core/src/test/java/com/datastrato/graviton/schema/TestNameIdentifier.java b/core/src/test/java/com/datastrato/graviton/meta/TestNameIdentifier.java
similarity index 94%
rename from core/src/test/java/com/datastrato/graviton/schema/TestNameIdentifier.java
rename to core/src/test/java/com/datastrato/graviton/meta/TestNameIdentifier.java
index 551e7e0ac5..d789e3a75f 100644
--- a/core/src/test/java/com/datastrato/graviton/schema/TestNameIdentifier.java
+++ b/core/src/test/java/com/datastrato/graviton/meta/TestNameIdentifier.java
@@ -1,5 +1,7 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton.meta;
+import com.datastrato.graviton.NameIdentifier;
+import com.datastrato.graviton.Namespace;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
diff --git a/core/src/test/java/com/datastrato/graviton/schema/TestNamespace.java b/core/src/test/java/com/datastrato/graviton/meta/TestNamespace.java
similarity index 92%
rename from core/src/test/java/com/datastrato/graviton/schema/TestNamespace.java
rename to core/src/test/java/com/datastrato/graviton/meta/TestNamespace.java
index bbc6f3a1d0..0c009b2272 100644
--- a/core/src/test/java/com/datastrato/graviton/schema/TestNamespace.java
+++ b/core/src/test/java/com/datastrato/graviton/meta/TestNamespace.java
@@ -1,5 +1,6 @@
-package com.datastrato.graviton.schema;
+package com.datastrato.graviton.meta;
+import com.datastrato.graviton.Namespace;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
diff --git a/core/src/test/java/com/datastrato/graviton/proto/TestEntityProtoSerDe.java b/core/src/test/java/com/datastrato/graviton/proto/TestEntityProtoSerDe.java
new file mode 100644
index 0000000000..a5473d95f4
--- /dev/null
+++ b/core/src/test/java/com/datastrato/graviton/proto/TestEntityProtoSerDe.java
@@ -0,0 +1,117 @@
+package com.datastrato.graviton.proto;
+
+import com.datastrato.graviton.meta.SchemaVersion;
+import com.google.common.collect.ImmutableMap;
+import java.time.Instant;
+import java.util.Map;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestEntityProtoSerDe {
+
+ @Test
+ public void testAuditInfoSerDe() {
+ Instant now = Instant.now();
+ String creator = "creator";
+ String modifier = "modifier";
+ String accessor = "accessor";
+
+ com.datastrato.graviton.meta.AuditInfo auditInfo =
+ new com.datastrato.graviton.meta.AuditInfo.Builder()
+ .withCreator(creator)
+ .withCreateTime(now)
+ .withLastModifier(modifier)
+ .withLastModifiedTime(now)
+ .build();
+
+ AuditInfo auditInfoProto = ProtoUtils.toProto(auditInfo);
+ Assertions.assertEquals(creator, auditInfoProto.getCreator());
+ Assertions.assertEquals(now, ProtoUtils.toInstant(auditInfoProto.getCreateTime()));
+ Assertions.assertEquals(modifier, auditInfoProto.getLastModifier());
+ Assertions.assertEquals(now, ProtoUtils.toInstant(auditInfoProto.getLastModifiedTime()));
+
+ com.datastrato.graviton.meta.AuditInfo auditInfoFromProto =
+ ProtoUtils.fromProto(auditInfoProto);
+ Assertions.assertEquals(auditInfo, auditInfoFromProto);
+
+ // Test with optional fields
+ com.datastrato.graviton.meta.AuditInfo auditInfo1 =
+ new com.datastrato.graviton.meta.AuditInfo.Builder()
+ .withCreator(creator)
+ .withCreateTime(now)
+ .build();
+
+ AuditInfo auditInfoProto1 = ProtoUtils.toProto(auditInfo1);
+
+ Assertions.assertEquals(creator, auditInfoProto1.getCreator());
+ Assertions.assertEquals(now, ProtoUtils.toInstant(auditInfoProto1.getCreateTime()));
+
+ com.datastrato.graviton.meta.AuditInfo auditInfoFromProto1 =
+ ProtoUtils.fromProto(auditInfoProto1);
+ Assertions.assertEquals(auditInfo1, auditInfoFromProto1);
+
+ // Test from/to bytes
+ byte[] bytes = ProtoUtils.toBytes(auditInfo1);
+ com.datastrato.graviton.meta.AuditInfo auditInfoFromBytes =
+ ProtoUtils.fromBytes(bytes, com.datastrato.graviton.meta.AuditInfo.class);
+ Assertions.assertEquals(auditInfo1, auditInfoFromBytes);
+ }
+
+ @Test
+ public void testEntitiesSerDe() {
+ Instant now = Instant.now();
+ String creator = "creator";
+ Integer tenantId = 1;
+ SchemaVersion version = SchemaVersion.V_0_1;
+ Long lakehouseId = 1L;
+ String lakehouseName = "lakehouse";
+ Map<String, String> props = ImmutableMap.of("k1", "v1", "k2", "v2");
+
+ com.datastrato.graviton.meta.AuditInfo auditInfo =
+ new com.datastrato.graviton.meta.AuditInfo.Builder()
+ .withCreator(creator)
+ .withCreateTime(now)
+ .build();
+
+ // Test Lakehouse
+ com.datastrato.graviton.meta.Lakehouse lakehouse =
+ new com.datastrato.graviton.meta.Lakehouse.Builder()
+ .withId(lakehouseId)
+ .withName(lakehouseName)
+ .withProperties(props)
+ .withAuditInfo(auditInfo)
+ .withVersion(version)
+ .build();
+
+ Lakehouse lakehouseProto = ProtoUtils.toProto(lakehouse);
+ Assertions.assertEquals(props, lakehouseProto.getPropertiesMap());
+ com.datastrato.graviton.meta.Lakehouse lakehouseFromProto =
+ ProtoUtils.fromProto(lakehouseProto);
+ Assertions.assertEquals(lakehouse, lakehouseFromProto);
+
+ byte[] lakehouseBytes = ProtoUtils.toBytes(lakehouse);
+ com.datastrato.graviton.meta.Lakehouse lakehouseFromBytes =
+ ProtoUtils.fromBytes(lakehouseBytes, com.datastrato.graviton.meta.Lakehouse.class);
+ Assertions.assertEquals(lakehouse, lakehouseFromBytes);
+
+ // Test Lakehouse without props map
+ com.datastrato.graviton.meta.Lakehouse lakehouse1 =
+ new com.datastrato.graviton.meta.Lakehouse.Builder()
+ .withId(lakehouseId)
+ .withName(lakehouseName)
+ .withAuditInfo(auditInfo)
+ .withVersion(version)
+ .build();
+
+ Lakehouse lakehouseProto1 = ProtoUtils.toProto(lakehouse1);
+ Assertions.assertEquals(0, lakehouseProto1.getPropertiesCount());
+ com.datastrato.graviton.meta.Lakehouse lakehouseFromProto1 =
+ ProtoUtils.fromProto(lakehouseProto1);
+ Assertions.assertEquals(lakehouse1, lakehouseFromProto1);
+
+ byte[] lakehouseBytes1 = ProtoUtils.toBytes(lakehouse1);
+ com.datastrato.graviton.meta.Lakehouse lakehouseFromBytes1 =
+ ProtoUtils.fromBytes(lakehouseBytes1, com.datastrato.graviton.meta.Lakehouse.class);
+ Assertions.assertEquals(lakehouse1, lakehouseFromBytes1);
+ }
+}
diff --git a/core/src/test/java/com/datastrato/graviton/schema/TestEntity.java b/core/src/test/java/com/datastrato/graviton/schema/TestEntity.java
deleted file mode 100644
index df859dd646..0000000000
--- a/core/src/test/java/com/datastrato/graviton/schema/TestEntity.java
+++ /dev/null
@@ -1,154 +0,0 @@
-package com.datastrato.graviton.schema;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import io.substrait.type.Type;
-import io.substrait.type.TypeCreator;
-import java.time.Instant;
-import java.util.Map;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-public class TestEntity {
- private final Instant now = Instant.now();
-
- // Tenant test data
- private final Integer tenantId = 1;
- private final String tenantName = "testTenant";
- private final SchemaVersion version = SchemaVersion.V_0_1;
- private final AuditInfo auditInfo =
- new AuditInfo.Builder().withCreator("test").withCreateTime(now).build();
-
- // Lakehouse test data
- private final Long lakehouseId = 1L;
- private final String lakehouseName = "testLakehouse";
- private final Map<String, String> map = ImmutableMap.of("k1", "v1", "k2", "v2");
-
- // Zone test data
- private Long zoneId = 1L;
- private String zoneName = "testZone";
-
- // column test data
- private final Integer columnId = 1;
- private final String columnName = "testColumn";
- private final Long tableSnapshotId = 1L;
- private final Type columnType = TypeCreator.of(false).I8;
- private final Integer pos = 1;
-
- // table test data
- private final Long tableId = 1L;
- private final String tableName = "testTable";
- private final Table.TableType tableType = Table.TableType.VIRTUAL;
- private final HasExtraInfo.ExtraInfo extraInfo =
- new VirtualTableInfo(1, ImmutableList.of("test"));
-
- @Test
- public void testTenant() {
- Tenant tenant =
- new Tenant.Builder()
- .withId(tenantId)
- .withName(tenantName)
- .withAuditInfo(auditInfo)
- .withVersion(version)
- .build();
-
- Map<Field, Object> fields = tenant.fields();
- Assertions.assertEquals(tenantId, fields.get(Tenant.ID));
- Assertions.assertEquals(tenantName, fields.get(Tenant.NAME));
- Assertions.assertEquals(auditInfo, fields.get(Tenant.AUDIT_INFO));
- Assertions.assertEquals(version, fields.get(Tenant.VERSION));
- Assertions.assertNull(fields.get(Tenant.COMMENT));
-
- Throwable exception =
- Assertions.assertThrows(
- IllegalArgumentException.class, () -> new Tenant.Builder().withId(tenantId).build());
- Assertions.assertTrue(exception.getMessage().matches("Field .* is required"));
- }
-
- @Test
- public void testLakehouse() {
- Lakehouse lakehouse =
- new Lakehouse.Builder()
- .withId(lakehouseId)
- .withName(lakehouseName)
- .withAuditInfo(auditInfo)
- .withProperties(map)
- .build();
-
- Map<Field, Object> fields = lakehouse.fields();
- Assertions.assertEquals(lakehouseId, fields.get(Lakehouse.ID));
- Assertions.assertEquals(lakehouseName, fields.get(Lakehouse.NAME));
- Assertions.assertEquals(map, fields.get(Lakehouse.PROPERTIES));
- Assertions.assertEquals(auditInfo, fields.get(Lakehouse.AUDIT_INFO));
- Assertions.assertNull(fields.get(Lakehouse.COMMENT));
- }
-
- @Test
- public void testZone() {
- Zone zone =
- new Zone.Builder()
- .withId(zoneId)
- .withLakehouseId(lakehouseId)
- .withName(zoneName)
- .withAuditInfo(auditInfo)
- .withProperties(map)
- .build();
-
- Map<Field, Object> fields = zone.fields();
- Assertions.assertEquals(zoneId, fields.get(Zone.ID));
- Assertions.assertEquals(lakehouseId, fields.get(Zone.LAKEHOUSE_ID));
- Assertions.assertEquals(zoneName, fields.get(Zone.NAME));
- Assertions.assertEquals(map, fields.get(Zone.PROPERTIES));
- Assertions.assertEquals(auditInfo, fields.get(Zone.AUDIT_INFO));
- Assertions.assertNull(fields.get(Zone.COMMENT));
- }
-
- @Test
- public void testColumn() {
- Column column =
- new Column.Builder()
- .withId(columnId)
- .withEntityId(tableId)
- .withEntitySnapshotId(tableSnapshotId)
- .withName(columnName)
- .withType(columnType)
- .withPosition(pos)
- .withAuditInfo(auditInfo)
- .build();
-
- Map<Field, Object> fields = column.fields();
- Assertions.assertEquals(columnId, fields.get(Column.ID));
- Assertions.assertEquals(tableId, fields.get(Column.ENTITY_ID));
- Assertions.assertEquals(tableSnapshotId, fields.get(Column.ENTITY_SNAPSHOT_ID));
- Assertions.assertEquals(columnName, fields.get(Column.NAME));
- Assertions.assertEquals(columnType, fields.get(Column.TYPE));
- Assertions.assertEquals(pos, fields.get(Column.POSITION));
- Assertions.assertEquals(auditInfo, fields.get(Column.AUDIT_INFO));
- Assertions.assertNull(fields.get(Column.COMMENT));
- }
-
- @Test
- public void testTable() {
- Table table =
- new Table.Builder()
- .withId(tableId)
- .withZoneId(zoneId)
- .withName(tableName)
- .withType(tableType)
- .withSnapshotId(tableSnapshotId)
- .withAuditInfo(auditInfo)
- .withExtraInfo(extraInfo)
- .build();
-
- Map<Field, Object> fields = table.fields();
- Assertions.assertEquals(tableId, fields.get(Table.ID));
- Assertions.assertEquals(zoneId, fields.get(Table.ZONE_ID));
- Assertions.assertEquals(tableName, fields.get(Table.NAME));
- Assertions.assertEquals(tableType, fields.get(Table.TABLE_TYPE));
- Assertions.assertEquals(tableSnapshotId, fields.get(Table.SNAPSHOT_ID));
- Assertions.assertEquals(auditInfo, fields.get(Table.AUDIT_INFO));
- Assertions.assertEquals(extraInfo, fields.get(Table.EXTRA_INFO));
- Assertions.assertNull(fields.get(Table.COMMENT));
- Assertions.assertNull(fields.get(Table.PROPERTIES));
- }
-}
diff --git a/core/src/test/java/com/datastrato/graviton/schema/json/TestEntityJsonSerDe.java b/core/src/test/java/com/datastrato/graviton/schema/json/TestEntityJsonSerDe.java
deleted file mode 100644
index 0e3f0cd38b..0000000000
--- a/core/src/test/java/com/datastrato/graviton/schema/json/TestEntityJsonSerDe.java
+++ /dev/null
@@ -1,466 +0,0 @@
-package com.datastrato.graviton.schema.json;
-
-import com.datastrato.graviton.schema.*;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import io.substrait.type.StringTypeVisitor;
-import io.substrait.type.TypeCreator;
-import java.time.Instant;
-import java.util.List;
-import java.util.Map;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-public class TestEntityJsonSerDe {
-
- private final String auditInfoJson =
- "{\"creator\":%s,\"create_time\":%s,"
- + "\"last_modifier\":%s,\"last_modified_time\":%s,"
- + "\"last_access_user\":%s,\"last_access_time\":%s}";
-
- private final String tenantJson =
- "{\"id\":%d,\"name\":%s,\"comment\":%s,"
- + "\"audit_info\":%s,\"version\":{\"major_version\":%d,\"minor_version\":%d}}";
-
- private final String lakehouseJson =
- "{\"id\":%d,\"name\":%s,\"comment\":%s,\"properties\":%s,\"audit_info\":%s}";
-
- private final String zoneJson =
- "{\"id\":%d,\"lakehouse_id\":%d,\"name\":%s,\"comment\":%s,"
- + "\"properties\":%s,\"audit_info\":%s}";
-
- private final String columnJson =
- "{\"id\":%d,\"entity_id\":%d,\"entity_snapshot_id\":%d,\"name\":%s,"
- + "\"type\":%s,\"comment\":%s,\"position\":%d,\"audit_info\":%s}";
-
- private final String tableJson =
- "{\"id\":%d,\"zone_id\":%d,\"name\":%s,\"comment\":%s,\"type\":%s,\"snapshot_id\":%d,"
- + "\"properties\":%s,\"audit_info\":%s,"
- + "\"extra_info\":{\"type\":%s,\"connection_id\":%d,\"identifier\":%s},"
- + "\"columns\":[%s]}";
-
- private String withQuotes(String str) {
- return "\"" + str + "\"";
- }
-
- @Test
- public void testAuditInfoJsonSerDe() throws Exception {
- Instant now = Instant.now();
- String creator = "creator";
- String modifier = "modifier";
- String accessor = "accessor";
-
- // Test with required fields
- AuditInfo info = new AuditInfo.Builder().withCreator(creator).withCreateTime(now).build();
-
- String serJson = JsonUtils.objectMapper().writeValueAsString(info);
- String expectedJson =
- String.format(
- auditInfoJson, withQuotes(creator), withQuotes(now.toString()), null, null, null, null);
- Assertions.assertEquals(expectedJson, serJson);
- AuditInfo deserInfo = JsonUtils.objectMapper().readValue(serJson, AuditInfo.class);
- Assertions.assertEquals(info, deserInfo);
-
- // Test with optional fields
- AuditInfo info1 =
- new AuditInfo.Builder()
- .withCreator(creator)
- .withCreateTime(now)
- .withLastModifier(modifier)
- .withLastModifiedTime(now)
- .build();
-
- String serJson1 = JsonUtils.objectMapper().writeValueAsString(info1);
- String expectedJson1 =
- String.format(
- auditInfoJson,
- withQuotes(creator),
- withQuotes(now.toString()),
- withQuotes(modifier),
- withQuotes(now.toString()),
- null,
- null);
- Assertions.assertEquals(expectedJson1, serJson1);
- AuditInfo deserInfo1 = JsonUtils.objectMapper().readValue(serJson1, AuditInfo.class);
- Assertions.assertEquals(info1, deserInfo1);
-
- AuditInfo info2 =
- new AuditInfo.Builder()
- .withCreator(creator)
- .withCreateTime(now)
- .withLastModifier(modifier)
- .withLastModifiedTime(now)
- .withLastAccessUser(accessor)
- .withLastAccessTime(now)
- .build();
-
- String serJson2 = JsonUtils.objectMapper().writeValueAsString(info2);
- String expectedJson2 =
- String.format(
- auditInfoJson,
- withQuotes(creator),
- withQuotes(now.toString()),
- withQuotes(modifier),
- withQuotes(now.toString()),
- withQuotes(accessor),
- withQuotes(now.toString()));
- Assertions.assertEquals(expectedJson2, serJson2);
- AuditInfo deserInfo2 = JsonUtils.objectMapper().readValue(serJson2, AuditInfo.class);
- Assertions.assertEquals(info2, deserInfo2);
- }
-
- @Test
- public void testTenantSerDe() throws Exception {
- Integer id = 1;
- String name = "tenant";
- String comment = "comment";
- String creator = "creator";
- Instant now = Instant.now();
- AuditInfo info = new AuditInfo.Builder().withCreator(creator).withCreateTime(now).build();
- SchemaVersion version = SchemaVersion.V_0_1;
-
- // Test with required fields
- Tenant tenant =
- new Tenant.Builder()
- .withId(id)
- .withName(name)
- .withComment(comment)
- .withAuditInfo(info)
- .withVersion(version)
- .build();
-
- String serJson = JsonUtils.objectMapper().writeValueAsString(tenant);
- String expectedJson =
- String.format(
- tenantJson,
- id,
- withQuotes(name),
- withQuotes(comment),
- String.format(
- auditInfoJson,
- withQuotes(creator),
- withQuotes(now.toString()),
- null,
- null,
- null,
- null),
- version.getMajorVersion(),
- version.getMinorVersion());
- Assertions.assertEquals(expectedJson, serJson);
- Tenant deserTenant = JsonUtils.objectMapper().readValue(serJson, Tenant.class);
- Assertions.assertEquals(tenant, deserTenant);
-
- // Test with optional fields
- Tenant tenant1 =
- new Tenant.Builder()
- .withId(id)
- .withName(name)
- .withAuditInfo(info)
- .withVersion(version)
- .build();
-
- String serJson1 = JsonUtils.objectMapper().writeValueAsString(tenant1);
- String expectedJson1 =
- String.format(
- tenantJson,
- id,
- withQuotes(name),
- null,
- String.format(
- auditInfoJson,
- withQuotes(creator),
- withQuotes(now.toString()),
- null,
- null,
- null,
- null),
- version.getMajorVersion(),
- version.getMinorVersion());
- Assertions.assertEquals(expectedJson1, serJson1);
- Tenant deserTenant1 = JsonUtils.objectMapper().readValue(serJson1, Tenant.class);
- Assertions.assertEquals(tenant1, deserTenant1);
- }
-
- @Test
- public void testLakehouseSerDe() throws Exception {
- Long id = 1L;
- String name = "lakehouse";
- String comment = "comment";
- Map<String, String> properties = ImmutableMap.of("k1", "v1", "k2", "v2");
- String creator = "creator";
- Instant now = Instant.now();
- AuditInfo info = new AuditInfo.Builder().withCreator(creator).withCreateTime(now).build();
-
- // Test with required fields
- Lakehouse lakehouse =
- new Lakehouse.Builder()
- .withId(id)
- .withName(name)
- .withComment(comment)
- .withProperties(properties)
- .withAuditInfo(info)
- .build();
-
- String serJson = JsonUtils.objectMapper().writeValueAsString(lakehouse);
- String expectedJson =
- String.format(
- lakehouseJson,
- id,
- withQuotes(name),
- withQuotes(comment),
- JsonUtils.objectMapper().writeValueAsString(properties),
- String.format(
- auditInfoJson,
- withQuotes(creator),
- withQuotes(now.toString()),
- null,
- null,
- null,
- null));
- Assertions.assertEquals(expectedJson, serJson);
- Lakehouse deserLakehouse = JsonUtils.objectMapper().readValue(serJson, Lakehouse.class);
- Assertions.assertEquals(lakehouse, deserLakehouse);
-
- // Test with optional fields
- Lakehouse lakehouse1 =
- new Lakehouse.Builder().withId(id).withName(name).withAuditInfo(info).build();
-
- String serJson1 = JsonUtils.objectMapper().writeValueAsString(lakehouse1);
- String expectedJson1 =
- String.format(
- lakehouseJson,
- id,
- withQuotes(name),
- null,
- null,
- String.format(
- auditInfoJson,
- withQuotes(creator),
- withQuotes(now.toString()),
- null,
- null,
- null,
- null));
- Assertions.assertEquals(expectedJson1, serJson1);
- Lakehouse deserLakehouse1 = JsonUtils.objectMapper().readValue(serJson1, Lakehouse.class);
- Assertions.assertEquals(lakehouse1, deserLakehouse1);
- }
-
- @Test
- public void testZoneSerDe() throws Exception {
- Long id = 1L;
- Long lakehouseId = 2L;
- String name = "zone";
- String comment = "comment";
- String creator = "creator";
- Instant now = Instant.now();
- AuditInfo info = new AuditInfo.Builder().withCreator(creator).withCreateTime(now).build();
- Map<String, String> properties = ImmutableMap.of("k1", "v1", "k2", "v2");
-
- // Test with required fields
- Zone zone =
- new Zone.Builder()
- .withId(id)
- .withLakehouseId(lakehouseId)
- .withName(name)
- .withComment(comment)
- .withProperties(properties)
- .withAuditInfo(info)
- .build();
-
- String serJson = JsonUtils.objectMapper().writeValueAsString(zone);
- String expectedJson =
- String.format(
- zoneJson,
- id,
- lakehouseId,
- withQuotes(name),
- withQuotes(comment),
- JsonUtils.objectMapper().writeValueAsString(properties),
- String.format(
- auditInfoJson,
- withQuotes(creator),
- withQuotes(now.toString()),
- null,
- null,
- null,
- null));
- Assertions.assertEquals(expectedJson, serJson);
- Zone deserZone = JsonUtils.objectMapper().readValue(serJson, Zone.class);
- Assertions.assertEquals(zone, deserZone);
-
- // Test with optional fields
- Zone zone1 =
- new Zone.Builder()
- .withId(id)
- .withLakehouseId(lakehouseId)
- .withName(name)
- .withAuditInfo(info)
- .build();
-
- String serJson1 = JsonUtils.objectMapper().writeValueAsString(zone1);
- String expectedJson1 =
- String.format(
- zoneJson,
- id,
- lakehouseId,
- withQuotes(name),
- null,
- null,
- String.format(
- auditInfoJson,
- withQuotes(creator),
- withQuotes(now.toString()),
- null,
- null,
- null,
- null));
- Assertions.assertEquals(expectedJson1, serJson1);
- Zone deserZone1 = JsonUtils.objectMapper().readValue(serJson1, Zone.class);
- Assertions.assertEquals(zone1, deserZone1);
- }
-
- @Test
- public void testColumnSerDe() throws Exception {
- Integer id = 1;
- Long entityId = 1L;
- Long entitySnapshotId = 2L;
- String name = "column";
- io.substrait.type.Type type = TypeCreator.NULLABLE.I8;
- String comment = "comment";
- Integer position = 1;
- String creator = "creator";
- Instant now = Instant.now();
- AuditInfo info = new AuditInfo.Builder().withCreator(creator).withCreateTime(now).build();
-
- // Test required fields
- Column column =
- new Column.Builder()
- .withId(id)
- .withEntityId(entityId)
- .withEntitySnapshotId(entitySnapshotId)
- .withName(name)
- .withType(type)
- .withComment(comment)
- .withPosition(position)
- .withAuditInfo(info)
- .build();
-
- String serJson = JsonUtils.objectMapper().writeValueAsString(column);
- String expectedJson =
- String.format(
- columnJson,
- id,
- entityId,
- entitySnapshotId,
- withQuotes(name),
- withQuotes(type.accept(new StringTypeVisitor())),
- withQuotes(comment),
- position,
- String.format(
- auditInfoJson,
- withQuotes(creator),
- withQuotes(now.toString()),
- null,
- null,
- null,
- null));
- Assertions.assertEquals(expectedJson, serJson);
- Column deserColumn = JsonUtils.objectMapper().readValue(serJson, Column.class);
- Assertions.assertEquals(column, deserColumn);
- }
-
- @Test
- public void testTableSerDe() throws Exception {
- Integer columnId = 1;
- Long tableId = 1L;
- Long tableSnapshotId = 2L;
- String name = "column";
- io.substrait.type.Type type = TypeCreator.NULLABLE.I8;
- String comment = "comment";
- Integer position = 1;
- String creator = "creator";
- Instant now = Instant.now();
- AuditInfo info = new AuditInfo.Builder().withCreator(creator).withCreateTime(now).build();
-
- Long zoneId = 2L;
- String tableName = "table";
- String tableComment = "comment";
- Table.TableType tableType = Table.TableType.VIRTUAL;
- Map<String, String> properties = ImmutableMap.of("k1", "v1", "k2", "v2");
-
- Integer connectionId = 1;
- List<String> identifiers = ImmutableList.of("db1", "tabl1");
- HasExtraInfo.ExtraInfo extraInfo = new VirtualTableInfo(connectionId, identifiers);
-
- Column column =
- new Column.Builder()
- .withId(columnId)
- .withEntityId(tableId)
- .withEntitySnapshotId(tableSnapshotId)
- .withName(name)
- .withType(type)
- .withComment(comment)
- .withPosition(position)
- .withAuditInfo(info)
- .build();
-
- Table table =
- new Table.Builder()
- .withId(tableId)
- .withZoneId(zoneId)
- .withName(tableName)
- .withComment(tableComment)
- .withSnapshotId(tableSnapshotId)
- .withProperties(properties)
- .withExtraInfo(extraInfo)
- .withAuditInfo(info)
- .withType(tableType)
- .withColumns(ImmutableList.of(column))
- .build();
-
- String serJson = JsonUtils.objectMapper().writeValueAsString(table);
- String expectedJson =
- String.format(
- tableJson,
- tableId,
- zoneId,
- withQuotes(tableName),
- withQuotes(tableComment),
- withQuotes(tableType.getTypeStr()),
- tableSnapshotId,
- JsonUtils.objectMapper().writeValueAsString(properties),
- String.format(
- auditInfoJson,
- withQuotes(creator),
- withQuotes(now.toString()),
- null,
- null,
- null,
- null),
- withQuotes(tableType.getTypeStr()),
- connectionId,
- JsonUtils.objectMapper().writeValueAsString(identifiers),
- String.format(
- columnJson,
- columnId,
- tableId,
- tableSnapshotId,
- withQuotes(name),
- withQuotes(type.accept(new StringTypeVisitor())),
- withQuotes(comment),
- position,
- String.format(
- auditInfoJson,
- withQuotes(creator),
- withQuotes(now.toString()),
- null,
- null,
- null,
- null)));
- Assertions.assertEquals(expectedJson, serJson);
-
- Table deserTable = JsonUtils.objectMapper().readValue(serJson, Table.class);
- Assertions.assertEquals(table, deserTable);
- }
-}
diff --git a/core/src/test/java/com/datastrato/graviton/schema/proto/TestEntityProtoSerDe.java b/core/src/test/java/com/datastrato/graviton/schema/proto/TestEntityProtoSerDe.java
deleted file mode 100644
index afbc253e03..0000000000
--- a/core/src/test/java/com/datastrato/graviton/schema/proto/TestEntityProtoSerDe.java
+++ /dev/null
@@ -1,247 +0,0 @@
-package com.datastrato.graviton.schema.proto;
-
-import com.datastrato.graviton.schema.HasExtraInfo;
-import com.datastrato.graviton.schema.SchemaVersion;
-import com.datastrato.graviton.schema.VirtualTableInfo;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import io.substrait.type.Type;
-import io.substrait.type.TypeCreator;
-import java.time.Instant;
-import java.util.Map;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-public class TestEntityProtoSerDe {
-
- @Test
- public void testAuditInfoSerDe() {
- Instant now = Instant.now();
- String creator = "creator";
- String modifier = "modifier";
- String accessor = "accessor";
-
- com.datastrato.graviton.schema.AuditInfo auditInfo =
- new com.datastrato.graviton.schema.AuditInfo.Builder()
- .withCreator(creator)
- .withCreateTime(now)
- .withLastModifier(modifier)
- .withLastModifiedTime(now)
- .withLastAccessUser(accessor)
- .withLastAccessTime(now)
- .build();
-
- AuditInfo auditInfoProto = ProtoUtils.toProto(auditInfo);
- Assertions.assertEquals(creator, auditInfoProto.getCreator());
- Assertions.assertEquals(now, ProtoUtils.toInstant(auditInfoProto.getCreateTime()));
- Assertions.assertEquals(modifier, auditInfoProto.getLastModifier());
- Assertions.assertEquals(now, ProtoUtils.toInstant(auditInfoProto.getLastModifiedTime()));
- Assertions.assertEquals(accessor, auditInfoProto.getLastAccessUser());
- Assertions.assertEquals(now, ProtoUtils.toInstant(auditInfoProto.getLastAccessTime()));
-
- com.datastrato.graviton.schema.AuditInfo auditInfoFromProto =
- ProtoUtils.fromProto(auditInfoProto);
- Assertions.assertEquals(auditInfo, auditInfoFromProto);
-
- // Test with optional fields
- com.datastrato.graviton.schema.AuditInfo auditInfo1 =
- new com.datastrato.graviton.schema.AuditInfo.Builder()
- .withCreator(creator)
- .withCreateTime(now)
- .build();
-
- AuditInfo auditInfoProto1 = ProtoUtils.toProto(auditInfo1);
-
- Assertions.assertEquals(creator, auditInfoProto1.getCreator());
- Assertions.assertEquals(now, ProtoUtils.toInstant(auditInfoProto1.getCreateTime()));
-
- com.datastrato.graviton.schema.AuditInfo auditInfoFromProto1 =
- ProtoUtils.fromProto(auditInfoProto1);
- Assertions.assertEquals(auditInfo1, auditInfoFromProto1);
-
- // Test from/to bytes
- byte[] bytes = ProtoUtils.toBytes(auditInfo1);
- com.datastrato.graviton.schema.AuditInfo auditInfoFromBytes =
- ProtoUtils.fromBytes(
- bytes, com.datastrato.graviton.schema.AuditInfo.class, AuditInfo.parser());
- Assertions.assertEquals(auditInfo1, auditInfoFromBytes);
- }
-
- @Test
- public void testEntitiesSerDe() {
- Instant now = Instant.now();
- String creator = "creator";
- Integer tenantId = 1;
- String tenantName = "tenant";
- SchemaVersion version = SchemaVersion.V_0_1;
- Long lakehouseId = 1L;
- String lakehouseName = "lakehouse";
- Map<String, String> props = ImmutableMap.of("k1", "v1", "k2", "v2");
- Long zoneId = 1L;
- String zoneName = "zone";
- Type columnType = TypeCreator.NULLABLE.STRING;
-
- com.datastrato.graviton.schema.AuditInfo auditInfo =
- new com.datastrato.graviton.schema.AuditInfo.Builder()
- .withCreator(creator)
- .withCreateTime(now)
- .build();
-
- // Test Tenant
- com.datastrato.graviton.schema.Tenant tenant =
- new com.datastrato.graviton.schema.Tenant.Builder()
- .withId(tenantId)
- .withName(tenantName)
- .withVersion(version)
- .withAuditInfo(auditInfo)
- .build();
-
- Tenant tenantProto = ProtoUtils.toProto(tenant);
- com.datastrato.graviton.schema.Tenant tenantFromProto = ProtoUtils.fromProto(tenantProto);
- Assertions.assertEquals(tenant, tenantFromProto);
-
- byte[] tenantBytes = ProtoUtils.toBytes(tenant);
- com.datastrato.graviton.schema.Tenant tenantFromBytes =
- ProtoUtils.fromBytes(
- tenantBytes, com.datastrato.graviton.schema.Tenant.class, Tenant.parser());
- Assertions.assertEquals(tenant, tenantFromBytes);
-
- // Test Lakehouse
- com.datastrato.graviton.schema.Lakehouse lakehouse =
- new com.datastrato.graviton.schema.Lakehouse.Builder()
- .withId(lakehouseId)
- .withName(lakehouseName)
- .withProperties(props)
- .withAuditInfo(auditInfo)
- .build();
-
- Lakehouse lakehouseProto = ProtoUtils.toProto(lakehouse);
- Assertions.assertEquals(props, lakehouseProto.getPropertiesMap());
- com.datastrato.graviton.schema.Lakehouse lakehouseFromProto =
- ProtoUtils.fromProto(lakehouseProto);
- Assertions.assertEquals(lakehouse, lakehouseFromProto);
-
- byte[] lakehouseBytes = ProtoUtils.toBytes(lakehouse);
- com.datastrato.graviton.schema.Lakehouse lakehouseFromBytes =
- ProtoUtils.fromBytes(
- lakehouseBytes, com.datastrato.graviton.schema.Lakehouse.class, Lakehouse.parser());
- Assertions.assertEquals(lakehouse, lakehouseFromBytes);
-
- // Test Lakehouse without props map
- com.datastrato.graviton.schema.Lakehouse lakehouse1 =
- new com.datastrato.graviton.schema.Lakehouse.Builder()
- .withId(lakehouseId)
- .withName(lakehouseName)
- .withAuditInfo(auditInfo)
- .build();
-
- Lakehouse lakehouseProto1 = ProtoUtils.toProto(lakehouse1);
- Assertions.assertEquals(0, lakehouseProto1.getPropertiesCount());
- com.datastrato.graviton.schema.Lakehouse lakehouseFromProto1 =
- ProtoUtils.fromProto(lakehouseProto1);
- Assertions.assertEquals(lakehouse1, lakehouseFromProto1);
-
- byte[] lakehouseBytes1 = ProtoUtils.toBytes(lakehouse1);
- com.datastrato.graviton.schema.Lakehouse lakehouseFromBytes1 =
- ProtoUtils.fromBytes(
- lakehouseBytes1, com.datastrato.graviton.schema.Lakehouse.class, Lakehouse.parser());
- Assertions.assertEquals(lakehouse1, lakehouseFromBytes1);
-
- // Test Zone
- com.datastrato.graviton.schema.Zone zone =
- new com.datastrato.graviton.schema.Zone.Builder()
- .withId(zoneId)
- .withLakehouseId(lakehouseId)
- .withName(zoneName)
- .withAuditInfo(auditInfo)
- .build();
-
- Zone zoneProto = ProtoUtils.toProto(zone);
- com.datastrato.graviton.schema.Zone zoneFromProto = ProtoUtils.fromProto(zoneProto);
- Assertions.assertEquals(zone, zoneFromProto);
-
- byte[] zoneBytes = ProtoUtils.toBytes(zone);
- com.datastrato.graviton.schema.Zone zoneFromBytes =
- ProtoUtils.fromBytes(zoneBytes, com.datastrato.graviton.schema.Zone.class, Zone.parser());
- Assertions.assertEquals(zone, zoneFromBytes);
-
- // Test Column
- com.datastrato.graviton.schema.Column column =
- new com.datastrato.graviton.schema.Column.Builder()
- .withId(1)
- .withEntityId(1L)
- .withEntitySnapshotId(1L)
- .withName("col1")
- .withType(columnType)
- .withPosition(1)
- .withAuditInfo(auditInfo)
- .build();
-
- Column columnProto = ProtoUtils.toProto(column);
- com.datastrato.graviton.schema.Column columnFromProto = ProtoUtils.fromProto(columnProto);
- Assertions.assertEquals(column, columnFromProto);
- Assertions.assertEquals(columnType, columnFromProto.getType());
-
- byte[] columnBytes = ProtoUtils.toBytes(column);
- com.datastrato.graviton.schema.Column columnFromBytes =
- ProtoUtils.fromBytes(
- columnBytes, com.datastrato.graviton.schema.Column.class, Column.parser());
- Assertions.assertEquals(column, columnFromBytes);
- }
-
- @Test
- public void testTableSerDe() {
- com.datastrato.graviton.schema.Table.TableType tableType =
- com.datastrato.graviton.schema.Table.TableType.VIRTUAL;
- HasExtraInfo.ExtraInfo extraInfo = new VirtualTableInfo(1, ImmutableList.of("db", "table"));
- com.datastrato.graviton.schema.AuditInfo auditInfo =
- new com.datastrato.graviton.schema.AuditInfo.Builder()
- .withCreator("creator")
- .withCreateTime(Instant.now())
- .build();
-
- com.datastrato.graviton.schema.Table table =
- new com.datastrato.graviton.schema.Table.Builder()
- .withId(1L)
- .withZoneId(1L)
- .withName("table")
- .withType(tableType)
- .withSnapshotId(1L)
- .withAuditInfo(auditInfo)
- .withExtraInfo(extraInfo)
- .build();
-
- Table tableProto = ProtoUtils.toProto(table);
- Assertions.assertEquals(tableType.getTypeStr(), tableProto.getType().name());
-
- com.datastrato.graviton.schema.Table tableFromProto = ProtoUtils.fromProto(tableProto);
- Assertions.assertEquals(extraInfo, tableFromProto.getExtraInfo());
- Assertions.assertEquals(table, tableFromProto);
-
- byte[] tableBytes = ProtoUtils.toBytes(table);
- com.datastrato.graviton.schema.Table tableFromBytes =
- ProtoUtils.fromBytes(
- tableBytes, com.datastrato.graviton.schema.Table.class, Table.parser());
- Assertions.assertEquals(table, tableFromBytes);
-
- // Test Table with unsupported type
- com.datastrato.graviton.schema.Table table1 =
- new com.datastrato.graviton.schema.Table.Builder()
- .withId(1L)
- .withZoneId(1L)
- .withName("table")
- .withType(com.datastrato.graviton.schema.Table.TableType.VIEW)
- .withSnapshotId(1L)
- .withAuditInfo(auditInfo)
- .withExtraInfo(extraInfo)
- .build();
-
- Throwable exception =
- Assertions.assertThrows(
- ProtoSerDeException.class,
- () -> {
- ProtoUtils.toProto(table1);
- });
- Assertions.assertEquals("Table type VIEW is not supported yet.", exception.getMessage());
- }
-}
diff --git a/schema/build.gradle.kts b/meta/build.gradle.kts
similarity index 84%
rename from schema/build.gradle.kts
rename to meta/build.gradle.kts
index 270ddea271..3b0cc3ad0b 100644
--- a/schema/build.gradle.kts
+++ b/meta/build.gradle.kts
@@ -19,8 +19,8 @@ dependencies {
sourceSets {
main {
- proto.srcDir("schema/src/main/proto")
- resources.srcDir("schema/src/main/resources")
+ proto.srcDir("meta/src/main/proto")
+ resources.srcDir("meta/src/main/resources")
}
}
diff --git a/meta/src/main/proto/graviton_meta.proto b/meta/src/main/proto/graviton_meta.proto
new file mode 100644
index 0000000000..d094cdbb50
--- /dev/null
+++ b/meta/src/main/proto/graviton_meta.proto
@@ -0,0 +1,54 @@
+syntax = "proto3";
+
+import "google/protobuf/timestamp.proto";
+
+option java_multiple_files = true;
+option java_package = "com.datastrato.graviton.proto";
+
+/**
+ * The version of schema definition. Schema is backward compatible within the
+ * same major version. The minor version is used for schema evolution.
+ */
+message SchemaVersion {
+ uint32 major_number = 1;
+ uint32 minor_number = 2;
+}
+
+/**
+ * The AuditInfo message is used to record the audit information of a resource.
+ */
+message AuditInfo {
+ string creator = 1;
+ google.protobuf.Timestamp create_time = 2;
+ optional string last_modifier = 3;
+ optional google.protobuf.Timestamp last_modified_time = 4;
+}
+
+/**
+ * The Lakehouse message is used to record the lakehouse information. Lakehouse is used track all
+ the metadata of the data lake, data warehouse, and data mart.
+ */
+message Lakehouse {
+ uint64 id = 1;
+ string name = 2;
+ optional string comment = 3;
+ map<string, string> properties = 4;
+ AuditInfo audit_info = 5;
+ SchemaVersion version = 6;
+}
+
+message Catalog {
+ enum Type {
+ REL = 0; // Catalog Type for Relational Data Structure, like db.table.
+ FILE = 1; // Catalog Type for File System (including HDFS, S3, etc.), like path/to/file.
+ STREAM = 2; // Catalog Type for Streaming Data, like kafka://topic.
+ }
+
+ uint64 id = 1;
+ uint64 lakehouse_id = 2;
+ string name = 3;
+ Type type = 4;
+ optional string comment = 5;
+ map<string, string> properties = 6;
+ AuditInfo audit_info = 7;
+}
\ No newline at end of file
diff --git a/schema/src/main/proto/schema.proto b/schema/src/main/proto/schema.proto
deleted file mode 100644
index ba19ebc2a2..0000000000
--- a/schema/src/main/proto/schema.proto
+++ /dev/null
@@ -1,119 +0,0 @@
-syntax = "proto3";
-
-import "google/protobuf/timestamp.proto";
-import "substrait/type.proto";
-
-option java_multiple_files = true;
-option java_package = "com.datastrato.graviton.schema.proto";
-
-/**
- * The version of schema definition. Schema is backward compatible within the
- * same major version. The minor version is used for schema evolution.
- */
-message SchemaVersion {
- uint32 major_number = 1;
- uint32 minor_number = 2;
-}
-
-/**
- * The AuditInfo message is used to record the audit information of a resource.
- */
-message AuditInfo {
- string creator = 1;
- google.protobuf.Timestamp create_time = 2;
- optional string last_modifier = 3;
- optional google.protobuf.Timestamp last_modified_time = 4;
- optional string last_access_user = 5;
- optional google.protobuf.Timestamp last_access_time = 6;
-}
-
-/**
- * The Tenant message is used to record the tenant information.
- */
-message Tenant {
- uint32 id = 1;
- string name = 2;
- optional string comment = 3;
- AuditInfo audit_info = 4;
- SchemaVersion version = 5;
-}
-
-/**
- * The Lakehouse message is used to record the lakehouse information. Lakehouse is used track all
- the information of the data lake, data warehouse, and data mart.
- */
-message Lakehouse {
- uint64 id = 1;
- string name = 2;
- optional string comment = 3;
- map<string, string> properties = 4;
- AuditInfo audit_info = 5;
-}
-
-/**
- * The Zone message is used to record the zone information. Zone is a second level of container
- * to organize all the tables and other entities.
- */
-message Zone {
- uint64 id = 1;
- uint64 lakehouse_id = 2;
- string name = 3;
- optional string comment = 4;
- map<string, string> properties = 5;
- AuditInfo audit_info = 6;
-}
-
-/**
- * The Column message is used to record the column information. Column uses Substrait's type
- * system to define the column type, follows the Substrait's type serialization and deserialization.
- */
-message Column {
- uint32 id = 1;
- uint64 entity_id = 2;
- uint64 entity_snapshot_id = 3;
- string name = 4;
- substrait.Type type = 5;
- optional string comment = 6;
- uint32 position = 7;
- AuditInfo audit_info = 8;
-}
-
-/**
- * The Table message is used to record the table information. Table is used to describe the
- * the information of a structured data set.
- */
-message Table {
- // VirtualTable is mainly used as a reference to a table in a remote system.
- message VirtualTableInfo {
- uint32 connection_id = 1;
- repeated string table_identifier = 2;
- }
-
- message ViewTableInfo {}
- message ExternalTableInfo {}
- message ManagedTableInfo {}
-
- enum TableType {
- VIRTUAL = 0;
- VIEW = 1;
- EXTERNAL = 2;
- TYPE_MANAGED = 3;
- }
-
- uint64 id = 1;
- uint64 zone_id = 2;
- string name = 3;
- TableType type = 4;
-
- oneof extra_info {
- VirtualTableInfo virtual_table = 5;
- ViewTableInfo view_table = 6;
- ExternalTableInfo external_table = 7;
- ManagedTableInfo managed_table = 8;
- }
-
- uint64 snapshot_id = 9;
- map<string, string> properties = 10;
- AuditInfo audit_info = 11;
- optional string comment = 12;
-}
\ No newline at end of file
diff --git a/server/src/main/java/com/datastrato/graviton/server/GravitonServer.java b/server/src/main/java/com/datastrato/graviton/server/GravitonServer.java
index 132a7d3c3c..3e03daa266 100644
--- a/server/src/main/java/com/datastrato/graviton/server/GravitonServer.java
+++ b/server/src/main/java/com/datastrato/graviton/server/GravitonServer.java
@@ -1,6 +1,6 @@
package com.datastrato.graviton.server;
-import com.datastrato.graviton.BaseTenantOperations;
+import com.datastrato.graviton.meta.BaseLakehouseOperations;
import com.datastrato.graviton.server.web.JettyServer;
import com.datastrato.graviton.server.web.ObjectMapperProvider;
import com.datastrato.graviton.server.web.VersioningFilter;
@@ -47,7 +47,7 @@ public class GravitonServer extends ResourceConfig {
new AbstractBinder() {
@Override
protected void configure() {
- bind(BaseTenantOperations.class).to(BaseTenantOperations.class).ranked(1);
+ bind(BaseLakehouseOperations.class).to(BaseLakehouseOperations.class).ranked(1);
}
});
register(ObjectMapperProvider.class).register(JacksonFeature.class);
diff --git a/server/src/main/java/com/datastrato/graviton/server/web/ObjectMapperProvider.java b/server/src/main/java/com/datastrato/graviton/server/web/ObjectMapperProvider.java
index 67ef061caf..a57005b832 100644
--- a/server/src/main/java/com/datastrato/graviton/server/web/ObjectMapperProvider.java
+++ b/server/src/main/java/com/datastrato/graviton/server/web/ObjectMapperProvider.java
@@ -1,6 +1,6 @@
package com.datastrato.graviton.server.web;
-import com.datastrato.graviton.schema.json.JsonUtils;
+import com.datastrato.graviton.json.JsonUtils;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.ws.rs.ext.ContextResolver;
diff --git a/server/src/main/java/com/datastrato/graviton/server/web/rest/TenantCreateRequest.java b/server/src/main/java/com/datastrato/graviton/server/web/rest/LakehouseCreateRequest.java
similarity index 67%
rename from server/src/main/java/com/datastrato/graviton/server/web/rest/TenantCreateRequest.java
rename to server/src/main/java/com/datastrato/graviton/server/web/rest/LakehouseCreateRequest.java
index 5c7e34c79d..e21d13c462 100644
--- a/server/src/main/java/com/datastrato/graviton/server/web/rest/TenantCreateRequest.java
+++ b/server/src/main/java/com/datastrato/graviton/server/web/rest/LakehouseCreateRequest.java
@@ -2,6 +2,7 @@ package com.datastrato.graviton.server.web.rest;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
+import java.util.Map;
import java.util.Optional;
import javax.annotation.Nullable;
import lombok.EqualsAndHashCode;
@@ -11,25 +12,30 @@ import lombok.ToString;
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString
-public class TenantCreateRequest extends BaseRequest {
+public class LakehouseCreateRequest extends BaseRequest {
@JsonProperty("name")
- public String name;
+ private String name;
@Nullable
@JsonProperty("comment")
- public String comment;
+ private String comment;
+
+ @Nullable
+ @JsonProperty("properties")
+ private Map<String, String> properties;
// Only for Jackson deserialization
- TenantCreateRequest() {
- this(null, null);
+ LakehouseCreateRequest() {
+ this(null, null, null);
}
- TenantCreateRequest(String name, String comment) {
+ LakehouseCreateRequest(String name, String comment, Map<String, String> properties) {
super();
this.name = Optional.ofNullable(name).map(String::trim).orElse(null);
this.comment = Optional.ofNullable(comment).map(String::trim).orElse(null);
+ this.properties = properties;
}
@Override
diff --git a/server/src/main/java/com/datastrato/graviton/server/web/rest/LakehouseOperations.java b/server/src/main/java/com/datastrato/graviton/server/web/rest/LakehouseOperations.java
new file mode 100644
index 0000000000..be94bea50f
--- /dev/null
+++ b/server/src/main/java/com/datastrato/graviton/server/web/rest/LakehouseOperations.java
@@ -0,0 +1,110 @@
+package com.datastrato.graviton.server.web.rest;
+
+import com.datastrato.graviton.NameIdentifier;
+import com.datastrato.graviton.meta.*;
+import com.datastrato.graviton.server.web.Utils;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("/lakehouses")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class LakehouseOperations {
+
+ private static final Logger LOG = LoggerFactory.getLogger(LakehouseOperations.class);
+
+ private final BaseLakehouseOperations ops;
+
+ @Context private HttpServletRequest httpRequest;
+
+ @Inject
+ public LakehouseOperations(BaseLakehouseOperations ops) {
+ this.ops = ops;
+ }
+
+ @POST
+ @Produces("application/vnd.graviton.v1+json")
+ public Response create(LakehouseCreateRequest request) {
+ try {
+ request.validate();
+ } catch (IllegalArgumentException e) {
+ LOG.error("Failed to validate create Lakehouse arguments {}", request, e);
+
+ return Utils.illegalArguments(e.getMessage());
+ }
+
+ LakehouseCreate create =
+ LakehouseCreate.create(
+ request.getName(),
+ request.getComment(),
+ request.getProperties(),
+ Utils.remoteUser(httpRequest));
+ NameIdentifier ident = NameIdentifier.parse(request.getName());
+
+ try {
+ Lakehouse lakehouse = ops.createEntity(ident, create);
+ return Utils.ok(new LakehouseResponse(lakehouse));
+
+ } catch (Exception e) {
+ LOG.error("Failed to create lakehouse", e);
+
+ return Utils.internalError(e.getMessage());
+ }
+ }
+
+ // TODO. Are we going to use id or name to get Entity? @Jerry
+ @GET
+ @Path("{name}")
+ @Produces("application/vnd.graviton.v1+json")
+ public Response get(@PathParam("name") String lakehouseName) {
+ if (lakehouseName == null || lakehouseName.isEmpty()) {
+ return Utils.illegalArguments("Tenant name is required");
+ }
+
+ NameIdentifier identifier = NameIdentifier.parse(lakehouseName);
+ try {
+ Lakehouse lakehouse = ops.loadEntity(identifier);
+ if (lakehouse == null) {
+ LOG.warn("Failed to find lakehouse by name {}", lakehouseName);
+ return Utils.notFound("Failed to find lakehouse by name " + lakehouseName);
+ } else {
+ return Utils.ok(new LakehouseResponse(lakehouse));
+ }
+
+ } catch (Exception e) {
+ LOG.error("Failed to get lakehouse by name {}", lakehouseName, e);
+
+ return Utils.internalError(e.getMessage());
+ }
+ }
+
+ @DELETE
+ @Path("{name}")
+ @Produces("application/vnd.graviton.v1+json")
+ public Response delete(@PathParam("name") String lakehouseName) {
+ if (lakehouseName == null || lakehouseName.isEmpty()) {
+ return Utils.illegalArguments("Lakehouse name is required");
+ }
+
+ NameIdentifier identifier = NameIdentifier.parse(lakehouseName);
+ try {
+ boolean dropped = ops.dropEntity(identifier);
+ if (dropped) {
+ return Utils.ok();
+ } else {
+ LOG.warn("Failed to delete lakehouse by name {}", lakehouseName);
+ return Utils.internalError("Failed to delete lakehouse by name " + lakehouseName);
+ }
+
+ } catch (Exception e) {
+ LOG.error("Failed to delete lakehouse by name {}", lakehouseName, e);
+ return Utils.internalError(e.getMessage());
+ }
+ }
+}
diff --git a/server/src/main/java/com/datastrato/graviton/server/web/rest/TenantResponse.java b/server/src/main/java/com/datastrato/graviton/server/web/rest/LakehouseResponse.java
similarity index 54%
rename from server/src/main/java/com/datastrato/graviton/server/web/rest/TenantResponse.java
rename to server/src/main/java/com/datastrato/graviton/server/web/rest/LakehouseResponse.java
index cf61ff2e8f..7d9b453827 100644
--- a/server/src/main/java/com/datastrato/graviton/server/web/rest/TenantResponse.java
+++ b/server/src/main/java/com/datastrato/graviton/server/web/rest/LakehouseResponse.java
@@ -1,6 +1,6 @@
package com.datastrato.graviton.server.web.rest;
-import com.datastrato.graviton.schema.Tenant;
+import com.datastrato.graviton.meta.Lakehouse;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@@ -9,19 +9,19 @@ import lombok.ToString;
@Getter
@ToString
@EqualsAndHashCode(callSuper = true)
-public class TenantResponse extends BaseResponse {
+public class LakehouseResponse extends BaseResponse {
- @JsonProperty("tenant")
- Tenant tenant;
+ @JsonProperty("lakehouse")
+ private final Lakehouse lakehouse;
- TenantResponse(Tenant tenant) {
+ LakehouseResponse(Lakehouse lakehouse) {
super(0, null, null);
- this.tenant = tenant;
+ this.lakehouse = lakehouse;
}
// This is the constructor that is used by Jackson deserializer
- TenantResponse() {
+ LakehouseResponse() {
super();
- this.tenant = null;
+ this.lakehouse = null;
}
}
diff --git a/server/src/main/java/com/datastrato/graviton/server/web/rest/TenantOperations.java b/server/src/main/java/com/datastrato/graviton/server/web/rest/TenantOperations.java
deleted file mode 100644
index 034bcb9c35..0000000000
--- a/server/src/main/java/com/datastrato/graviton/server/web/rest/TenantOperations.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package com.datastrato.graviton.server.web.rest;
-
-import com.datastrato.graviton.BaseTenantOperations;
-import com.datastrato.graviton.schema.AuditInfo;
-import com.datastrato.graviton.schema.NameIdentifier;
-import com.datastrato.graviton.schema.SchemaVersion;
-import com.datastrato.graviton.schema.Tenant;
-import com.datastrato.graviton.server.web.Utils;
-import java.time.Instant;
-import java.util.Optional;
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.*;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Path("/tenants")
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-public class TenantOperations {
-
- private static final Logger LOG = LoggerFactory.getLogger(TenantOperations.class);
-
- private final BaseTenantOperations ops;
-
- @Context private HttpServletRequest httpRequest;
-
- @Inject
- public TenantOperations(BaseTenantOperations ops) {
- this.ops = ops;
- }
-
- @POST
- @Produces("application/vnd.graviton.v1+json")
- public Response create(TenantCreateRequest request) {
- try {
- request.validate();
- } catch (IllegalArgumentException e) {
- LOG.error("Failed to validate create tenant arguments {}", request, e);
-
- return Utils.illegalArguments(e.getMessage());
- }
-
- AuditInfo auditInfo =
- new AuditInfo.Builder()
- .withCreator(Utils.remoteUser(httpRequest))
- .withCreateTime(Instant.now())
- .build();
-
- Tenant.Builder builder =
- new Tenant.Builder()
- .withId(1) // TODO. ID generator should be designed later. @Jerry
- .withName(request.getName())
- .withVersion(SchemaVersion.V_0_1)
- .withAuditInfo(auditInfo);
- Optional.ofNullable(request.getComment()).ifPresent(builder::withComment);
-
- Tenant tenant = builder.build();
-
- try {
- ops.create(tenant);
- return Utils.ok(new TenantResponse(tenant));
-
- } catch (Exception e) {
- LOG.error("Failed to create tenant {}", tenant, e);
-
- return Utils.internalError(e.getMessage());
- }
- }
-
- // TODO. Are we going to use id or name to get Entity? @Jerry
- @GET
- @Path("{name}")
- @Produces("application/vnd.graviton.v1+json")
- public Response get(@PathParam("name") String tenantName) {
- if (tenantName == null || tenantName.isEmpty()) {
- return Utils.illegalArguments("Tenant name is required");
- }
-
- NameIdentifier identifier = NameIdentifier.parse(tenantName);
- try {
- Tenant tenant = ops.get(identifier);
- if (tenant == null) {
- LOG.warn("Failed to find tenant by name {}", tenantName);
- return Utils.notFound("Failed to find tenant by name " + tenantName);
- } else {
- return Utils.ok(new TenantResponse(tenant));
- }
-
- } catch (Exception e) {
- LOG.error("Failed to get tenant by name {}", tenantName, e);
-
- return Utils.internalError(e.getMessage());
- }
- }
-
- @DELETE
- @Path("{name}")
- @Produces("application/vnd.graviton.v1+json")
- public Response delete(@PathParam("name") String tenantName) {
- if (tenantName == null || tenantName.isEmpty()) {
- return Utils.illegalArguments("Tenant name is required");
- }
-
- NameIdentifier identifier = NameIdentifier.parse(tenantName);
- try {
- ops.delete(identifier);
- return Utils.ok();
-
- } catch (Exception e) {
- LOG.error("Failed to delete tenant by name {}", tenantName, e);
-
- return Utils.internalError(e.getMessage());
- }
- }
-}
diff --git a/server/src/test/java/com/datastrato/graviton/server/web/rest/TestTenantOperations.java b/server/src/test/java/com/datastrato/graviton/server/web/rest/TestLakehouseOperations.java
similarity index 60%
rename from server/src/test/java/com/datastrato/graviton/server/web/rest/TestTenantOperations.java
rename to server/src/test/java/com/datastrato/graviton/server/web/rest/TestLakehouseOperations.java
index 7e9f79c419..1b45a608b4 100644
--- a/server/src/test/java/com/datastrato/graviton/server/web/rest/TestTenantOperations.java
+++ b/server/src/test/java/com/datastrato/graviton/server/web/rest/TestLakehouseOperations.java
@@ -3,10 +3,11 @@ package com.datastrato.graviton.server.web.rest;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
-import com.datastrato.graviton.BaseTenantOperations;
-import com.datastrato.graviton.schema.AuditInfo;
-import com.datastrato.graviton.schema.SchemaVersion;
-import com.datastrato.graviton.schema.Tenant;
+import com.datastrato.graviton.meta.AuditInfo;
+import com.datastrato.graviton.meta.BaseLakehouseOperations;
+import com.datastrato.graviton.meta.Lakehouse;
+import com.datastrato.graviton.meta.SchemaVersion;
+import com.google.common.collect.ImmutableMap;
import java.time.Instant;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.client.Entity;
@@ -19,7 +20,7 @@ import org.glassfish.jersey.test.JerseyTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-public class TestTenantOperations extends JerseyTest {
+public class TestLakehouseOperations extends JerseyTest {
private static class MockServletRequestFactory extends ServletRequestFactoryBase {
@Override
@@ -30,17 +31,17 @@ public class TestTenantOperations extends JerseyTest {
}
}
- private BaseTenantOperations tenantOperations = mock(BaseTenantOperations.class);
+ private BaseLakehouseOperations lakehouseOperations = mock(BaseLakehouseOperations.class);
@Override
protected Application configure() {
ResourceConfig resourceConfig = new ResourceConfig();
- resourceConfig.register(TenantOperations.class);
+ resourceConfig.register(LakehouseOperations.class);
resourceConfig.register(
new AbstractBinder() {
@Override
protected void configure() {
- bind(tenantOperations).to(BaseTenantOperations.class).ranked(2);
+ bind(lakehouseOperations).to(BaseLakehouseOperations.class).ranked(2);
bindFactory(MockServletRequestFactory.class).to(HttpServletRequest.class);
}
});
@@ -49,11 +50,26 @@ public class TestTenantOperations extends JerseyTest {
}
@Test
- public void testCreateTenant() {
- TenantCreateRequest req = new TenantCreateRequest("tenant", "comment");
+ public void testCreateLakehouse() {
+ LakehouseCreateRequest req =
+ new LakehouseCreateRequest("lakehouse", "comment", ImmutableMap.of("k1", "v1"));
+ Instant now = Instant.now();
+
+ Lakehouse mockLakehouse =
+ new Lakehouse.Builder()
+ .withId(1L)
+ .withName("lakehouse")
+ .withComment("comment")
+ .withProperties(ImmutableMap.of("k1", "v1"))
+ .withAuditInfo(
+ new AuditInfo.Builder().withCreator("graviton").withCreateTime(now).build())
+ .withVersion(SchemaVersion.V_0_1)
+ .build();
+
+ when(lakehouseOperations.createEntity(any(), any())).thenReturn(mockLakehouse);
Response resp =
- target("/tenants")
+ target("/lakehouses")
.request(MediaType.APPLICATION_JSON_TYPE)
.accept("application/vnd.graviton.v1+json")
.post(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE));
@@ -61,18 +77,19 @@ public class TestTenantOperations extends JerseyTest {
Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getMediaType());
- TenantResponse tenantResponse = resp.readEntity(TenantResponse.class);
- Assertions.assertEquals(0, tenantResponse.getCode());
- Assertions.assertNull(tenantResponse.getMessage());
- Assertions.assertNull(tenantResponse.getType());
+ LakehouseResponse lakehouseResponse = resp.readEntity(LakehouseResponse.class);
+ Assertions.assertEquals(0, lakehouseResponse.getCode());
+ Assertions.assertNull(lakehouseResponse.getMessage());
+ Assertions.assertNull(lakehouseResponse.getType());
- Tenant tenant = tenantResponse.getTenant();
- Assertions.assertEquals("tenant", tenant.getName());
- Assertions.assertEquals("comment", tenant.getComment());
+ Lakehouse lakehouse = lakehouseResponse.getLakehouse();
+ Assertions.assertEquals("lakehouse", lakehouse.getName());
+ Assertions.assertEquals("comment", lakehouse.getComment());
+ Assertions.assertEquals(ImmutableMap.of("k1", "v1"), lakehouse.getProperties());
- TenantCreateRequest req1 = new TenantCreateRequest(null, null);
+ LakehouseCreateRequest req1 = new LakehouseCreateRequest(null, null, null);
Response resp1 =
- target("/tenants")
+ target("/lakehouses")
.request(MediaType.APPLICATION_JSON_TYPE)
.accept("application/vnd.graviton.v1+json")
.post(Entity.entity(req1, MediaType.APPLICATION_JSON_TYPE));
@@ -86,23 +103,23 @@ public class TestTenantOperations extends JerseyTest {
}
@Test
- public void testGetTenant() {
- String tenantName = "test";
- int id = 1;
+ public void testGetLakehouse() {
+ String lakehouseName = "test";
+ Long id = 1L;
Instant now = Instant.now();
AuditInfo info = new AuditInfo.Builder().withCreator("graviton").withCreateTime(now).build();
- Tenant tenant =
- new Tenant.Builder()
- .withName(tenantName)
+ Lakehouse lakehouse =
+ new Lakehouse.Builder()
+ .withName(lakehouseName)
.withId(id)
.withAuditInfo(info)
.withVersion(SchemaVersion.V_0_1)
.build();
- when(tenantOperations.get(any())).thenReturn(tenant);
+ when(lakehouseOperations.loadEntity(any())).thenReturn(lakehouse);
Response resp =
- target("/tenants/" + tenantName)
+ target("/lakehouses/" + lakehouseName)
.request(MediaType.APPLICATION_JSON_TYPE)
.accept("application/vnd.graviton.v1+json")
.get();
@@ -110,19 +127,19 @@ public class TestTenantOperations extends JerseyTest {
Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getMediaType());
- TenantResponse tenantResponse = resp.readEntity(TenantResponse.class);
- Assertions.assertEquals(0, tenantResponse.getCode());
- Assertions.assertNull(tenantResponse.getMessage());
- Assertions.assertNull(tenantResponse.getType());
+ LakehouseResponse lakehouseResponse = resp.readEntity(LakehouseResponse.class);
+ Assertions.assertEquals(0, lakehouseResponse.getCode());
+ Assertions.assertNull(lakehouseResponse.getMessage());
+ Assertions.assertNull(lakehouseResponse.getType());
- Tenant tenant1 = tenantResponse.getTenant();
- Assertions.assertEquals(tenant, tenant1);
+ Lakehouse lakehouse1 = lakehouseResponse.getLakehouse();
+ Assertions.assertEquals(lakehouse, lakehouse1);
// Test when specified tenant is not found.
- when(tenantOperations.get(any())).thenReturn(null);
+ when(lakehouseOperations.loadEntity(any())).thenReturn(null);
Response resp1 =
- target("/tenants/" + tenantName)
+ target("/lakehouses/" + lakehouseName)
.request(MediaType.APPLICATION_JSON_TYPE)
.accept("application/vnd.graviton.v1+json")
.get();
@@ -133,13 +150,13 @@ public class TestTenantOperations extends JerseyTest {
Assertions.assertEquals(ErrorType.NOT_FOUND.errorCode(), baseResponse.getCode());
Assertions.assertEquals(ErrorType.NOT_FOUND.errorType(), baseResponse.getType());
Assertions.assertEquals(
- "Failed to find tenant by name " + tenantName, baseResponse.getMessage());
+ "Failed to find lakehouse by name " + lakehouseName, baseResponse.getMessage());
// Test with internal error
- when(tenantOperations.get(any())).thenThrow(new RuntimeException("Internal error"));
+ when(lakehouseOperations.loadEntity(any())).thenThrow(new RuntimeException("Internal error"));
Response resp2 =
- target("/tenants/" + tenantName)
+ target("/lakehouses/" + lakehouseName)
.request(MediaType.APPLICATION_JSON_TYPE)
.accept("application/vnd.graviton.v1+json")
.get();
@@ -154,9 +171,10 @@ public class TestTenantOperations extends JerseyTest {
}
@Test
- public void testDeleteTenant() {
+ public void testDeleteLakehouse() {
+ when(lakehouseOperations.dropEntity(any())).thenReturn(true);
Response resp =
- target("/tenants/test")
+ target("/lakehouses/test")
.request(MediaType.APPLICATION_JSON_TYPE)
.accept("application/vnd.graviton.v1+json")
.delete();
@@ -164,10 +182,10 @@ public class TestTenantOperations extends JerseyTest {
Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
// Test throw an exception when deleting tenant.
- doThrow(new RuntimeException("Internal error")).when(tenantOperations).delete(any());
+ doThrow(new RuntimeException("Internal error")).when(lakehouseOperations).dropEntity(any());
Response resp1 =
- target("/tenants/test")
+ target("/lakehouses/test")
.request(MediaType.APPLICATION_JSON_TYPE)
.accept("application/vnd.graviton.v1+json")
.delete();
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 4f26a80f36..6f51454930 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -1,3 +1,3 @@
rootProject.name = "Graviton"
-include("api", "core", "schema", "server")
+include("core", "meta", "server")