Skip to content

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

[#12] feat(schema): Implement the schema metadata and type system (#15)

Saisai Shao15db9b52ef35
diff --git a/build.gradle.kts b/build.gradle.kts
index 6b46c4022b..529b0e5cae 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,5 +1,6 @@
import com.diffplug.gradle.spotless.SpotlessExtension
import com.diffplug.gradle.spotless.SpotlessPlugin
+import com.github.vlsi.gradle.dsl.configureEach
plugins {
`maven-publish`
@@ -21,9 +22,16 @@ java {
}
allprojects {
- repositories { mavenCentral() }
+ repositories {
+ mavenCentral()
+ mavenLocal()
+ }
+
+ tasks.configureEach<Test> {
+ useJUnitPlatform()
+ }
- group = "com.datastrato.catalog"
+ group = "com.datastrato.unified_catalog"
version = "${version}"
plugins.withType<SpotlessPlugin>().configureEach {
diff --git a/core/build.gradle.kts b/core/build.gradle.kts
new file mode 100644
index 0000000000..40af1d6641
--- /dev/null
+++ b/core/build.gradle.kts
@@ -0,0 +1,28 @@
+plugins {
+ `maven-publish`
+ id("java")
+ id("idea")
+ id("com.diffplug.spotless")
+}
+
+dependencies {
+ implementation(project(":schema"));
+ implementation(libs.protobuf.java.util) {
+ exclude("com.google.guava", "guava")
+ .because("Brings in Guava for Andriod, which we don't want (and breaks multimaps).")
+ }
+ implementation(libs.substrait.java.core)
+ implementation(libs.jackson.databind)
+ implementation(libs.jackson.annotations)
+ implementation(libs.jackson.datatype.jdk8)
+ implementation(libs.guava)
+
+ compileOnly(libs.lombok)
+ annotationProcessor(libs.lombok)
+ testCompileOnly(libs.lombok)
+ testAnnotationProcessor(libs.lombok)
+
+ testImplementation(libs.junit.jupiter.api)
+ testImplementation(libs.junit.jupiter.params)
+ testRuntimeOnly(libs.junit.jupiter.engine)
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/datastrato/unified_catalog/schema/AuditInfo.java b/core/src/main/java/com/datastrato/unified_catalog/schema/AuditInfo.java
new file mode 100644
index 0000000000..17c93b44ed
--- /dev/null
+++ b/core/src/main/java/com/datastrato/unified_catalog/schema/AuditInfo.java
@@ -0,0 +1,128 @@
+package com.datastrato.unified_catalog.schema;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import java.time.Instant;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+
+@Getter
+@EqualsAndHashCode
+public final class AuditInfo implements Entity {
+ public static final Field CREATOR =
+ Field.required("creator", String.class, "The name of user who creates the entity");
+ public static final Field CREATE_TIME =
+ Field.required("create_time", Instant.class, "The time when the entity is created");
+ public static final Field LAST_MODIFIER =
+ Field.optional(
+ "last_modifier", String.class, "The name of user who last modifies the 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;
+
+ @JsonProperty("create_time")
+ private Instant createTime;
+
+ @Nullable
+ @JsonProperty("last_modifier")
+ private String lastModifier;
+
+ @Nullable
+ @JsonProperty("last_modified_time")
+ private Instant lastModifiedTime;
+
+ @Nullable
+ @JsonProperty("last_access_user")
+ private String lastAccessUser;
+
+ @Nullable
+ @JsonProperty("last_access_time")
+ private Instant lastAccessTime;
+
+ private AuditInfo() {}
+
+ @Override
+ public void validate() throws IllegalArgumentException {
+ CREATOR.validate(creator);
+ CREATE_TIME.validate(createTime);
+
+ Preconditions.checkArgument(
+ 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
+ public Map<Field, Object> fields() {
+ Map<Field, Object> fields = new HashMap<>();
+ fields.put(CREATOR, creator);
+ 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);
+ }
+
+ public static class Builder {
+ private AuditInfo auditInfo;
+
+ public Builder() {
+ this.auditInfo = new AuditInfo();
+ }
+
+ public Builder withCreator(String creator) {
+ this.auditInfo.creator = creator;
+ return this;
+ }
+
+ public Builder withCreateTime(Instant createTime) {
+ this.auditInfo.createTime = createTime;
+ return this;
+ }
+
+ public Builder withLastModifier(String lastModifier) {
+ this.auditInfo.lastModifier = lastModifier;
+ return this;
+ }
+
+ public Builder withLastModifiedTime(Instant lastModifiedTime) {
+ this.auditInfo.lastModifiedTime = lastModifiedTime;
+ 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/unified_catalog/schema/Auditable.java b/core/src/main/java/com/datastrato/unified_catalog/schema/Auditable.java
new file mode 100644
index 0000000000..ce2b4e6d3f
--- /dev/null
+++ b/core/src/main/java/com/datastrato/unified_catalog/schema/Auditable.java
@@ -0,0 +1,11 @@
+package com.datastrato.unified_catalog.schema;
+
+public interface Auditable {
+
+ /**
+ * Returns the audit information of the entity.
+ *
+ * @return AuditInfo
+ */
+ AuditInfo auditInfo();
+}
diff --git a/core/src/main/java/com/datastrato/unified_catalog/schema/Column.java b/core/src/main/java/com/datastrato/unified_catalog/schema/Column.java
new file mode 100644
index 0000000000..c9754c9aa1
--- /dev/null
+++ b/core/src/main/java/com/datastrato/unified_catalog/schema/Column.java
@@ -0,0 +1,136 @@
+package com.datastrato.unified_catalog.schema;
+
+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.Getter;
+
+@Getter
+@EqualsAndHashCode
+public final class Column implements Entity, Auditable {
+
+ 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")
+ 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;
+ }
+
+ 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/unified_catalog/schema/Entity.java b/core/src/main/java/com/datastrato/unified_catalog/schema/Entity.java
new file mode 100644
index 0000000000..d6939cdba3
--- /dev/null
+++ b/core/src/main/java/com/datastrato/unified_catalog/schema/Entity.java
@@ -0,0 +1,23 @@
+package com.datastrato.unified_catalog.schema;
+
+import java.io.Serializable;
+import java.util.Map;
+
+public interface Entity extends Serializable {
+
+ /**
+ * Validates the entity if the field arguments are valid.
+ *
+ * @throws IllegalArgumentException throws IllegalArgumentException if the validation is failed.
+ */
+ default void validate() throws IllegalArgumentException {
+ fields().forEach(Field::validate);
+ }
+
+ /**
+ * Returns the schema of the entity with values.
+ *
+ * @return Map of Field to Object to represent the schema of the entity with values.
+ */
+ Map<Field, Object> fields();
+}
diff --git a/core/src/main/java/com/datastrato/unified_catalog/schema/Field.java b/core/src/main/java/com/datastrato/unified_catalog/schema/Field.java
new file mode 100644
index 0000000000..1f04e251f0
--- /dev/null
+++ b/core/src/main/java/com/datastrato/unified_catalog/schema/Field.java
@@ -0,0 +1,91 @@
+package com.datastrato.unified_catalog.schema;
+
+import lombok.EqualsAndHashCode;
+
+@EqualsAndHashCode
+public class Field {
+ // The name of the field
+ private String fieldName;
+
+ // The type class of the field
+ private Class<?> typeClass;
+
+ // The detailed description of the field
+ private String description;
+
+ // Whether this field is optional or required
+ private boolean optional;
+
+ private Field() {}
+
+ public static Field required(String fieldName, Class<?> typeClass, String description) {
+ return new Builder(false)
+ .withName(fieldName)
+ .withTypeClass(typeClass)
+ .withDescription(description)
+ .build();
+ }
+
+ public static Field optional(String fieldName, Class<?> typeClass, String description) {
+ return new Builder(true)
+ .withName(fieldName)
+ .withTypeClass(typeClass)
+ .withDescription(description)
+ .build();
+ }
+
+ public static Field required(String fieldName, Class<?> typeClass) {
+ return new Builder(false).withName(fieldName).withTypeClass(typeClass).build();
+ }
+
+ public static Field optional(String fieldName, Class<?> typeClass) {
+ return new Builder(true).withName(fieldName).withTypeClass(typeClass).build();
+ }
+
+ public <T> void validate(T fieldValue) {
+ if (fieldValue == null && !optional) {
+ throw new IllegalArgumentException("Field " + fieldName + " is required");
+ }
+
+ if (fieldValue != null && !typeClass.isAssignableFrom(fieldValue.getClass())) {
+ throw new IllegalArgumentException(
+ "Field " + fieldName + " is not of type " + typeClass.getName());
+ }
+ }
+
+ public static class Builder {
+ private final Field field;
+
+ public Builder(boolean isOptional) {
+ field = new Field();
+ field.optional = isOptional;
+ }
+
+ public Builder withName(String name) {
+ field.fieldName = name;
+ return this;
+ }
+
+ public Builder withTypeClass(Class<?> typeClass) {
+ field.typeClass = typeClass;
+ return this;
+ }
+
+ public Builder withDescription(String description) {
+ field.description = description;
+ return this;
+ }
+
+ public Field build() {
+ if (field.fieldName == null) {
+ throw new IllegalArgumentException("Field name is required");
+ }
+
+ if (field.typeClass == null) {
+ throw new IllegalArgumentException("Field type class is required");
+ }
+
+ return field;
+ }
+ }
+}
diff --git a/core/src/main/java/com/datastrato/unified_catalog/schema/Lakehouse.java b/core/src/main/java/com/datastrato/unified_catalog/schema/Lakehouse.java
new file mode 100644
index 0000000000..6b19dd5a63
--- /dev/null
+++ b/core/src/main/java/com/datastrato/unified_catalog/schema/Lakehouse.java
@@ -0,0 +1,99 @@
+package com.datastrato.unified_catalog.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;
+
+@Getter
+@EqualsAndHashCode
+public class Lakehouse implements Entity, Auditable {
+
+ public static final Field ID =
+ Field.required("id", Long.class, "The unique identifier of the lakehouse");
+ public static final Field NAME =
+ Field.required("name", String.class, "The name of the lakehouse");
+ public static final Field COMMENT =
+ Field.optional("comment", String.class, "The comment of the lakehouse");
+ public static final Field PROPERTIES =
+ 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");
+
+ @JsonProperty("id")
+ private Long id;
+
+ @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 Lakehouse() {}
+
+ @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(PROPERTIES, properties);
+ fields.put(AUDIT_INFO, auditInfo);
+
+ return Collections.unmodifiableMap(fields);
+ }
+
+ @Override
+ public AuditInfo auditInfo() {
+ return auditInfo;
+ }
+
+ public static class Builder {
+ private final Lakehouse lakehouse;
+
+ public Builder() {
+ lakehouse = new Lakehouse();
+ }
+
+ public Builder withId(Long id) {
+ lakehouse.id = id;
+ return this;
+ }
+
+ public Builder withName(String name) {
+ lakehouse.name = name;
+ return this;
+ }
+
+ public Builder withComment(String comment) {
+ lakehouse.comment = comment;
+ return this;
+ }
+
+ public Builder withProperties(Map<String, String> properties) {
+ lakehouse.properties = properties;
+ return this;
+ }
+
+ public Builder withAuditInfo(AuditInfo auditInfo) {
+ lakehouse.auditInfo = auditInfo;
+ return this;
+ }
+
+ public Lakehouse build() {
+ lakehouse.validate();
+ return lakehouse;
+ }
+ }
+}
diff --git a/core/src/main/java/com/datastrato/unified_catalog/schema/SchemaVersion.java b/core/src/main/java/com/datastrato/unified_catalog/schema/SchemaVersion.java
new file mode 100644
index 0000000000..57f113a974
--- /dev/null
+++ b/core/src/main/java/com/datastrato/unified_catalog/schema/SchemaVersion.java
@@ -0,0 +1,21 @@
+package com.datastrato.unified_catalog.schema;
+
+public enum SchemaVersion {
+ V_0_1(0, 1);
+
+ public final int majorVersion;
+ public final int minorVersion;
+
+ SchemaVersion(int majorVersion, int minorVersion) {
+ this.majorVersion = majorVersion;
+ this.minorVersion = minorVersion;
+ }
+
+ public int getMajorVersion() {
+ return majorVersion;
+ }
+
+ public int getMinorVersion() {
+ return minorVersion;
+ }
+}
diff --git a/core/src/main/java/com/datastrato/unified_catalog/schema/Table.java b/core/src/main/java/com/datastrato/unified_catalog/schema/Table.java
new file mode 100644
index 0000000000..0eec5e9fa6
--- /dev/null
+++ b/core/src/main/java/com/datastrato/unified_catalog/schema/Table.java
@@ -0,0 +1,170 @@
+package com.datastrato.unified_catalog.schema;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.*;
+import javax.annotation.Nullable;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+
+@Getter
+@EqualsAndHashCode
+public class Table implements Entity, Auditable, hasExtraInfo {
+ 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;
+ }
+
+ 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/unified_catalog/schema/Tenant.java b/core/src/main/java/com/datastrato/unified_catalog/schema/Tenant.java
new file mode 100644
index 0000000000..beb2d9b60e
--- /dev/null
+++ b/core/src/main/java/com/datastrato/unified_catalog/schema/Tenant.java
@@ -0,0 +1,97 @@
+package com.datastrato.unified_catalog.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;
+
+@Getter
+@EqualsAndHashCode
+public final class Tenant implements Entity, Auditable {
+
+ 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;
+ }
+
+ 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/unified_catalog/schema/VirtualTableInfo.java b/core/src/main/java/com/datastrato/unified_catalog/schema/VirtualTableInfo.java
new file mode 100644
index 0000000000..991f019b54
--- /dev/null
+++ b/core/src/main/java/com/datastrato/unified_catalog/schema/VirtualTableInfo.java
@@ -0,0 +1,38 @@
+package com.datastrato.unified_catalog.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;
+
+@Getter
+@EqualsAndHashCode
+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;
+
+ 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/unified_catalog/schema/Zone.java b/core/src/main/java/com/datastrato/unified_catalog/schema/Zone.java
new file mode 100644
index 0000000000..4751e51de5
--- /dev/null
+++ b/core/src/main/java/com/datastrato/unified_catalog/schema/Zone.java
@@ -0,0 +1,109 @@
+package com.datastrato.unified_catalog.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;
+
+@Getter
+@EqualsAndHashCode
+public class Zone implements Entity, Auditable {
+
+ 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;
+ }
+
+ 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/unified_catalog/schema/hasExtraInfo.java b/core/src/main/java/com/datastrato/unified_catalog/schema/hasExtraInfo.java
new file mode 100644
index 0000000000..8abe75e02c
--- /dev/null
+++ b/core/src/main/java/com/datastrato/unified_catalog/schema/hasExtraInfo.java
@@ -0,0 +1,13 @@
+package com.datastrato.unified_catalog.schema;
+
+/** Interface for entities that have extra info. */
+public interface hasExtraInfo {
+ 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/test/java/com/datastrato/unified_catalog/schema/TestAuditInfo.java b/core/src/test/java/com/datastrato/unified_catalog/schema/TestAuditInfo.java
new file mode 100644
index 0000000000..3320a644e2
--- /dev/null
+++ b/core/src/test/java/com/datastrato/unified_catalog/schema/TestAuditInfo.java
@@ -0,0 +1,85 @@
+package com.datastrato.unified_catalog.schema;
+
+import java.time.Instant;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestAuditInfo {
+
+ @Test
+ public void testAuditInfoField() {
+ Instant now = Instant.now();
+ String creator = "test";
+ String lastModifier = "test1";
+ String lastAccessUser = "test2";
+
+ AuditInfo auditInfo =
+ new AuditInfo.Builder()
+ .withCreator(creator)
+ .withCreateTime(now)
+ .withLastModifier(lastModifier)
+ .withLastModifiedTime(now)
+ .withLastAccessUser(lastAccessUser)
+ .withLastAccessTime(now)
+ .build();
+
+ auditInfo.validate();
+
+ Assertions.assertEquals(creator, auditInfo.getCreator());
+ 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
+ public void testAuditInfoValidate() {
+ 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(
+ IllegalArgumentException.class,
+ () -> new AuditInfo.Builder().withCreator(creator).build());
+ Assertions.assertEquals("Field create_time is required", exception.getMessage());
+
+ Throwable exception1 =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ new AuditInfo.Builder()
+ .withCreator(creator)
+ .withCreateTime(now)
+ .withLastModifier(lastModifier)
+ .build();
+ });
+ 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/unified_catalog/schema/TestEntity.java b/core/src/test/java/com/datastrato/unified_catalog/schema/TestEntity.java
new file mode 100644
index 0000000000..23074f0c74
--- /dev/null
+++ b/core/src/test/java/com/datastrato/unified_catalog/schema/TestEntity.java
@@ -0,0 +1,154 @@
+package com.datastrato.unified_catalog.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/unified_catalog/schema/TestField.java b/core/src/test/java/com/datastrato/unified_catalog/schema/TestField.java
new file mode 100644
index 0000000000..f425e999a2
--- /dev/null
+++ b/core/src/test/java/com/datastrato/unified_catalog/schema/TestField.java
@@ -0,0 +1,37 @@
+package com.datastrato.unified_catalog.schema;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestField {
+
+ @Test
+ public void testFieldRequired() {
+ Field required = Field.required("test", String.class, "test");
+ required.validate("test");
+ Throwable exception =
+ Assertions.assertThrows(IllegalArgumentException.class, () -> required.validate(null));
+ Assertions.assertEquals("Field test is required", exception.getMessage());
+ }
+
+ @Test
+ public void testFieldOptional() {
+ Field optional = Field.optional("test", String.class, "test");
+ optional.validate("test");
+ optional.validate(null);
+ }
+
+ @Test
+ public void testTypeUnmatched() {
+ Field required = Field.required("test", String.class, "test");
+ Throwable exception =
+ Assertions.assertThrows(IllegalArgumentException.class, () -> required.validate(1));
+ Assertions.assertEquals("Field test is not of type java.lang.String", exception.getMessage());
+
+ Field optional = Field.optional("test1", Integer.class, "test");
+ Throwable exception1 =
+ Assertions.assertThrows(IllegalArgumentException.class, () -> optional.validate(1L));
+ Assertions.assertEquals(
+ "Field test1 is not of type java.lang.Integer", exception1.getMessage());
+ }
+}
diff --git a/gradle.properties b/gradle.properties
index e773d3d923..c4280a441d 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -2,12 +2,6 @@ org.gradle.parallel=true
# Build cache can be disabled with --no-build-cache option
org.gradle.caching=true
-# plugins
-com.google.protobuf.version=0.9.2
-org.jetbrains.gradle.plugin.idea-ext.version=0.5
-kotlin.version=1.5.31
-com.github.vlsi.vlsi-release-plugins.version=1.74
-
#version that is going to be updated automatically by releases
version = 0.1.0
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index fadd28c467..3e014185f3 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -1,6 +1,10 @@
[versions]
junit = "5.8.1"
protoc = "3.17.3"
+substrait = "0.9.0"
+jackson = "2.13.4"
+guava = "29.0-jre"
+lombok = "1.18.20"
protobuf-plugin = "0.9.2"
spotless-plugin = '6.11.0'
gradle-extensions-plugin = '1.74'
@@ -8,6 +12,16 @@ publish-plugin = '1.1.0'
[libraries]
protobuf-java = { group = "com.google.protobuf", name = "protobuf-java", version.ref = "protoc" }
+protobuf-java-util = { group = "com.google.protobuf", name = "protobuf-java-util", version.ref = "protoc" }
+substrait-java-core = { group = "io.substrait", name = "core", version.ref = "substrait" }
+jackson-databind = { group = "com.fasterxml.jackson.core", name = "jackson-databind", version.ref = "jackson" }
+jackson-annotations = { group = "com.fasterxml.jackson.core", name = "jackson-annotations", version.ref = "jackson" }
+jackson-datatype-jdk8 = { group = "com.fasterxml.jackson.datatype", name = "jackson-datatype-jdk8", version.ref = "jackson" }
+guava = { group = "com.google.guava", name = "guava", version.ref = "guava" }
+lombok = { group = "org.projectlombok", name = "lombok", version.ref = "lombok" }
+junit-jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" }
+junit-jupiter-params = { group = "org.junit.jupiter", name = "junit-jupiter-params", version.ref = "junit" }
+junit-jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine"}
[bundles]
diff --git a/schema/build.gradle.kts b/schema/build.gradle.kts
index 0c5168a636..e224362c4c 100644
--- a/schema/build.gradle.kts
+++ b/schema/build.gradle.kts
@@ -10,6 +10,7 @@ plugins {
dependencies {
implementation(libs.protobuf.java)
+ implementation(libs.substrait.java.core)
}
sourceSets {
diff --git a/schema/src/main/proto/schema.proto b/schema/src/main/proto/schema.proto
index 99871af7b7..d5ccebe9cf 100644
--- a/schema/src/main/proto/schema.proto
+++ b/schema/src/main/proto/schema.proto
@@ -1,92 +1,117 @@
syntax = "proto3";
-import "google/protobuf/empty.proto";
+import "google/protobuf/timestamp.proto";
+import "substrait/type.proto";
option java_multiple_files = true;
-option java_package = "com.datastrato.catalog.proto";
+option java_package = "com.datastrato.unified_catalog.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 {
- // Schema version number.
uint32 major_number = 1;
uint32 minor_number = 2;
- uint32 patch_number = 3;
}
-message Tenant {
- string tenant_name = 1;
- string comment = 2;
- int64 create_time = 3;
- SchemaVersion version = 4;
-}
-
-message Catalog {
- string catalog_name = 1;
- string comment = 2;
- int64 create_time = 3;
+/**
+ * The AuditInfo message is used to record the audit information of a resource.
+ */
+message AuditInfo {
+ string creator = 1;
+ google.protobuf.Timestamp create_time = 2;
+ string last_modifier = 3;
+ google.protobuf.Timestamp last_modified_time = 4;
+ string last_access_user = 5;
+ google.protobuf.Timestamp last_access_time = 6;
}
-message Schema {
- string schema_name = 1;
- string comment = 2;
- map<string, string> properties = 3;
- int64 create_time = 4;
+/**
+ * The Tenant message is used to record the tenant information.
+ */
+message Tenant {
+ uint32 id = 1;
+ string name = 2;
+ string comment = 3;
+ AuditInfo audit_info = 4;
+ SchemaVersion version = 5;
}
-enum Nullability {
- NULLABILITY_UNSPECIFIED = 0;
- NULLABILITY_REQUIRED = 1;
- NULLABILITY_OPTIONAL = 2;
+/**
+ * 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;
+ string comment = 3;
+ map<string, string> properties = 4;
+ AuditInfo audit_info = 5;
}
-enum Type {
- BOOLEAN = 0;
- I8 = 1;
- I16 = 2;
- I32 = 3;
- I64 = 4;
- FP32 = 5;
- FP64 = 6;
- STRING = 7;
- TIMESTAMP = 8;
- DATE = 9;
- TIME = 10;
- INTERVAL_YEAR = 11;
- INTERVAL_DAY = 12;
- TIMESTAMP_TZ = 13;
- UUID = 14;
-
- FIXED_CHAR = 15;
- VARCHAR = 16;
- FIXED_BINARY = 17;
- DECIMAL = 18;
-
- STRUCT = 19;
- LIST = 20;
- MAP = 21;
+/**
+ * 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;
+ 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 {
- int32 column_id = 1;
- string column_name = 2;
- string comment = 3;
- Type column_type = 4;
- Nullability nullability = 5;
+ uint32 id = 1;
+ uint64 entity_id = 2;
+ uint64 entity_snapshot_id = 3;
+ string name = 4;
+ substrait.Type type = 5;
+ string comment = 6;
+ uint32 position = 7;
}
+/**
+ * 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 {
- TYPE_MANAGED = 0;
- TYPE_EXTERNAL = 1;
- TYPE_VIEW = 2;
+ VIRTUAL = 0;
+ VIEW = 1;
+ EXTERNAL = 2;
+ TYPE_MANAGED = 3;
}
- int32 table_id = 1;
- string table_name = 2;
- TableType table_type = 3;
- repeated Column columns = 4;
- int64 create_time = 5;
- int64 last_access_time = 6;
+ 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;
+ }
- string view_expanded_text = 7;
- string view_original_text = 8;
+ uint64 snapshot_id = 9;
+ map<string, string> properties = 10;
+ AuditInfo audit_info = 11;
}
\ No newline at end of file