Skip to content

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

[#4867] feat(core): Add storage support for columns in Gravitino (#5078)

Jerry Shao5f73e62b8aea
diff --git a/common/src/main/java/org/apache/gravitino/json/JsonUtils.java b/common/src/main/java/org/apache/gravitino/json/JsonUtils.java
index ce80965b6a..f0f79bd454 100644
--- a/common/src/main/java/org/apache/gravitino/json/JsonUtils.java
+++ b/common/src/main/java/org/apache/gravitino/json/JsonUtils.java
@@ -33,6 +33,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.cfg.EnumFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
@@ -291,7 +292,13 @@ public class JsonUtils {
.build()
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.registerModule(new JavaTimeModule())
- .registerModule(new Jdk8Module());
+ .registerModule(new Jdk8Module())
+ .registerModule(
+ new SimpleModule()
+ .addDeserializer(Type.class, new TypeDeserializer())
+ .addSerializer(Type.class, new TypeSerializer())
+ .addDeserializer(Expression.class, new ColumnDefaultValueDeserializer())
+ .addSerializer(Expression.class, new ColumnDefaultValueSerializer()));
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/meta/ColumnEntity.java b/core/src/main/java/org/apache/gravitino/meta/ColumnEntity.java
index eb56636178..5b89bfce5d 100644
--- a/core/src/main/java/org/apache/gravitino/meta/ColumnEntity.java
+++ b/core/src/main/java/org/apache/gravitino/meta/ColumnEntity.java
@@ -28,6 +28,7 @@ import org.apache.gravitino.Audit;
import org.apache.gravitino.Auditable;
import org.apache.gravitino.Entity;
import org.apache.gravitino.Field;
+import org.apache.gravitino.rel.Column;
import org.apache.gravitino.rel.expressions.Expression;
import org.apache.gravitino.rel.types.Type;
@@ -198,6 +199,11 @@ public class ColumnEntity implements Entity, Auditable {
public ColumnEntity build() {
columnEntity.validate();
+
+ if (columnEntity.defaultValue == null) {
+ columnEntity.defaultValue = Column.DEFAULT_VALUE_NOT_SET;
+ }
+
return columnEntity;
}
}
diff --git a/core/src/main/java/org/apache/gravitino/meta/TableEntity.java b/core/src/main/java/org/apache/gravitino/meta/TableEntity.java
index e5a6627703..197eed6d33 100644
--- a/core/src/main/java/org/apache/gravitino/meta/TableEntity.java
+++ b/core/src/main/java/org/apache/gravitino/meta/TableEntity.java
@@ -20,7 +20,8 @@ package org.apache.gravitino.meta;
import com.google.common.base.Objects;
import com.google.common.collect.Maps;
-import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
import lombok.ToString;
import org.apache.gravitino.Auditable;
@@ -38,7 +39,7 @@ public class TableEntity implements Entity, Auditable, HasIdentifier {
public static final Field AUDIT_INFO =
Field.required("audit_info", AuditInfo.class, "The audit details of the table");
public static final Field COLUMNS =
- Field.optional("columns", ColumnEntity[].class, "The columns of the table");
+ Field.optional("columns", List.class, "The columns of the table");
private Long id;
@@ -48,7 +49,7 @@ public class TableEntity implements Entity, Auditable, HasIdentifier {
private Namespace namespace;
- private ColumnEntity[] columns;
+ private List<ColumnEntity> columns;
/**
* Returns a map of the fields and their corresponding values for this table.
@@ -116,7 +117,7 @@ public class TableEntity implements Entity, Auditable, HasIdentifier {
return namespace;
}
- public ColumnEntity[] columns() {
+ public List<ColumnEntity> columns() {
return columns;
}
@@ -134,12 +135,12 @@ public class TableEntity implements Entity, Auditable, HasIdentifier {
&& Objects.equal(name, baseTable.name)
&& Objects.equal(namespace, baseTable.namespace)
&& Objects.equal(auditInfo, baseTable.auditInfo)
- && Arrays.equals(columns, baseTable.columns);
+ && Objects.equal(columns, baseTable.columns);
}
@Override
public int hashCode() {
- return Objects.hashCode(id, name, auditInfo, Arrays.hashCode(columns));
+ return Objects.hashCode(id, name, auditInfo, columns);
}
public static class Builder {
@@ -170,13 +171,18 @@ public class TableEntity implements Entity, Auditable, HasIdentifier {
return this;
}
- public Builder withColumns(ColumnEntity[] columns) {
+ public Builder withColumns(List<ColumnEntity> columns) {
tableEntity.columns = columns;
return this;
}
public TableEntity build() {
tableEntity.validate();
+
+ if (tableEntity.columns == null) {
+ tableEntity.columns = Collections.emptyList();
+ }
+
return tableEntity;
}
}
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java b/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java
index 1ed1385557..5a6eb2e09a 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java
@@ -57,6 +57,7 @@ import org.apache.gravitino.storage.relational.service.MetalakeMetaService;
import org.apache.gravitino.storage.relational.service.OwnerMetaService;
import org.apache.gravitino.storage.relational.service.RoleMetaService;
import org.apache.gravitino.storage.relational.service.SchemaMetaService;
+import org.apache.gravitino.storage.relational.service.TableColumnMetaService;
import org.apache.gravitino.storage.relational.service.TableMetaService;
import org.apache.gravitino.storage.relational.service.TagMetaService;
import org.apache.gravitino.storage.relational.service.TopicMetaService;
@@ -292,6 +293,8 @@ public class JDBCBackend implements RelationalBackend {
.deleteTagMetasByLegacyTimeline(
legacyTimeline, GARBAGE_COLLECTOR_SINGLE_DELETION_LIMIT);
case COLUMN:
+ return TableColumnMetaService.getInstance()
+ .deleteColumnsByLegacyTimeline(legacyTimeline, GARBAGE_COLLECTOR_SINGLE_DELETION_LIMIT);
case AUDIT:
return 0;
// TODO: Implement hard delete logic for these entity types.
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/database/H2Database.java b/core/src/main/java/org/apache/gravitino/storage/relational/database/H2Database.java
index 4214a9baed..c2c2bbf63c 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/database/H2Database.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/database/H2Database.java
@@ -58,7 +58,7 @@ public class H2Database implements JDBCDatabase {
Statement statement = connection.createStatement()) {
String sqlContent =
FileUtils.readFileToString(
- new File(gravitinoHome + "/scripts/h2/schema-0.6.0-h2.sql"), StandardCharsets.UTF_8);
+ new File(gravitinoHome + "/scripts/h2/schema-0.7.0-h2.sql"), StandardCharsets.UTF_8);
statement.execute(sqlContent);
} catch (Exception e) {
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableColumnMapper.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableColumnMapper.java
new file mode 100644
index 0000000000..2214d8fd35
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableColumnMapper.java
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.storage.relational.mapper;
+
+import java.util.List;
+import org.apache.gravitino.storage.relational.po.ColumnPO;
+import org.apache.ibatis.annotations.DeleteProvider;
+import org.apache.ibatis.annotations.InsertProvider;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.SelectProvider;
+import org.apache.ibatis.annotations.UpdateProvider;
+
+public interface TableColumnMapper {
+
+ String COLUMN_TABLE_NAME = "table_column_version_info";
+
+ @SelectProvider(
+ type = TableColumnSQLProviderFactory.class,
+ method = "listColumnPOsByTableIdAndVersion")
+ List<ColumnPO> listColumnPOsByTableIdAndVersion(
+ @Param("tableId") Long tableId, @Param("tableVersion") Long tableVersion);
+
+ @InsertProvider(type = TableColumnSQLProviderFactory.class, method = "insertColumnPOs")
+ void insertColumnPOs(@Param("columnPOs") List<ColumnPO> columnPOs);
+
+ @UpdateProvider(type = TableColumnSQLProviderFactory.class, method = "softDeleteColumnsByTableId")
+ Integer softDeleteColumnsByTableId(@Param("tableId") Long tableId);
+
+ @UpdateProvider(
+ type = TableColumnSQLProviderFactory.class,
+ method = "softDeleteColumnsByMetalakeId")
+ Integer softDeleteColumnsByMetalakeId(@Param("metalakeId") Long metalakeId);
+
+ @UpdateProvider(
+ type = TableColumnSQLProviderFactory.class,
+ method = "softDeleteColumnsByCatalogId")
+ Integer softDeleteColumnsByCatalogId(@Param("catalogId") Long catalogId);
+
+ @UpdateProvider(
+ type = TableColumnSQLProviderFactory.class,
+ method = "softDeleteColumnsBySchemaId")
+ Integer softDeleteColumnsBySchemaId(@Param("schemaId") Long schemaId);
+
+ @DeleteProvider(
+ type = TableColumnSQLProviderFactory.class,
+ method = "deleteColumnPOsByLegacyTimeline")
+ Integer deleteColumnPOsByLegacyTimeline(
+ @Param("legacyTimeline") Long legacyTimeline, @Param("limit") int limit);
+}
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableColumnSQLProviderFactory.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableColumnSQLProviderFactory.java
new file mode 100644
index 0000000000..f85cf72d83
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableColumnSQLProviderFactory.java
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.storage.relational.mapper;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.storage.relational.JDBCBackend;
+import org.apache.gravitino.storage.relational.mapper.provider.base.TableColumnBaseSQLProvider;
+import org.apache.gravitino.storage.relational.mapper.provider.postgresql.TableColumnPostgreSQLProvider;
+import org.apache.gravitino.storage.relational.po.ColumnPO;
+import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper;
+import org.apache.ibatis.annotations.Param;
+
+public class TableColumnSQLProviderFactory {
+
+ static class TableColumnH2Provider extends TableColumnBaseSQLProvider {}
+
+ static class TableColumnMySQLProvider extends TableColumnBaseSQLProvider {}
+
+ private static final Map<JDBCBackend.JDBCBackendType, TableColumnBaseSQLProvider>
+ TABLE_COLUMN_SQL_PROVIDERS =
+ ImmutableMap.of(
+ JDBCBackend.JDBCBackendType.MYSQL, new TableColumnMySQLProvider(),
+ JDBCBackend.JDBCBackendType.H2, new TableColumnH2Provider(),
+ JDBCBackend.JDBCBackendType.POSTGRESQL, new TableColumnPostgreSQLProvider());
+
+ public static TableColumnBaseSQLProvider getProvider() {
+ String databaseId =
+ SqlSessionFactoryHelper.getInstance()
+ .getSqlSessionFactory()
+ .getConfiguration()
+ .getDatabaseId();
+ JDBCBackend.JDBCBackendType jdbcBackendType =
+ JDBCBackend.JDBCBackendType.fromString(databaseId);
+ return TABLE_COLUMN_SQL_PROVIDERS.get(jdbcBackendType);
+ }
+
+ public static String listColumnPOsByTableIdAndVersion(
+ @Param("tableId") Long tableId, @Param("tableVersion") Long tableVersion) {
+ return getProvider().listColumnPOsByTableIdAndVersion(tableId, tableVersion);
+ }
+
+ public static String insertColumnPOs(@Param("columnPOs") List<ColumnPO> columnPOs) {
+ return getProvider().insertColumnPOs(columnPOs);
+ }
+
+ public static String softDeleteColumnsByTableId(@Param("tableId") Long tableId) {
+ return getProvider().softDeleteColumnsByTableId(tableId);
+ }
+
+ public static String deleteColumnPOsByLegacyTimeline(
+ @Param("legacyTimeline") Long legacyTimeline, @Param("limit") int limit) {
+ return getProvider().deleteColumnPOsByLegacyTimeline(legacyTimeline, limit);
+ }
+
+ public static String softDeleteColumnsByMetalakeId(@Param("metalakeId") Long metalakeId) {
+ return getProvider().softDeleteColumnsByMetalakeId(metalakeId);
+ }
+
+ public static String softDeleteColumnsByCatalogId(@Param("catalogId") Long catalogId) {
+ return getProvider().softDeleteColumnsByCatalogId(catalogId);
+ }
+
+ public static String softDeleteColumnsBySchemaId(@Param("schemaId") Long schemaId) {
+ return getProvider().softDeleteColumnsBySchemaId(schemaId);
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/TableColumnBaseSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/TableColumnBaseSQLProvider.java
new file mode 100644
index 0000000000..0af9889ba6
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/TableColumnBaseSQLProvider.java
@@ -0,0 +1,104 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.storage.relational.mapper.provider.base;
+
+import java.util.List;
+import org.apache.gravitino.storage.relational.mapper.TableColumnMapper;
+import org.apache.gravitino.storage.relational.po.ColumnPO;
+import org.apache.ibatis.annotations.Param;
+
+public class TableColumnBaseSQLProvider {
+
+ public String listColumnPOsByTableIdAndVersion(
+ @Param("tableId") Long tableId, @Param("tableVersion") Long tableVersion) {
+ return "SELECT t1.column_id AS columnId, t1.column_name AS columnName,"
+ + " t1.metalake_id AS metalakeId, t1.catalog_id AS catalogId,"
+ + " t1.schema_id AS schemaId, t1.table_id AS tableId,"
+ + " t1.table_version AS tableVersion, t1.column_type AS columnType,"
+ + " t1.column_comment AS columnComment, t1.column_nullable AS nullable,"
+ + " t1.column_auto_increment AS autoIncrement,"
+ + " t1.column_default_value AS defaultValue, t1.column_op_type AS columnOpType,"
+ + " t1.deleted_at AS deletedAt, t1.audit_info AS auditInfo"
+ + " FROM "
+ + TableColumnMapper.COLUMN_TABLE_NAME
+ + " t1 JOIN ("
+ + " SELECT column_id, MAX(table_version) AS max_table_version"
+ + " FROM "
+ + TableColumnMapper.COLUMN_TABLE_NAME
+ + " WHERE table_id = #{tableId} AND table_version <= #{tableVersion} AND deleted_at = 0"
+ + " GROUP BY column_id) t2"
+ + " ON t1.column_id = t2.column_id AND t1.table_version = t2.max_table_version";
+ }
+
+ public String insertColumnPOs(@Param("columnPOs") List<ColumnPO> columnPOs) {
+ return "<script>"
+ + "INSERT INTO "
+ + TableColumnMapper.COLUMN_TABLE_NAME
+ + "(column_id, column_name, metalake_id, catalog_id, schema_id, table_id, table_version,"
+ + " column_type, column_comment, column_nullable, column_auto_increment, "
+ + " column_default_value, column_op_type, deleted_at, audit_info)"
+ + " VALUES "
+ + "<foreach collection='columnPOs' item='item' separator=','>"
+ + "(#{item.columnId}, #{item.columnName}, #{item.metalakeId}, #{item.catalogId},"
+ + " #{item.schemaId}, #{item.tableId}, #{item.tableVersion}, #{item.columnType}, "
+ + " #{item.columnComment}, #{item.nullable}, #{item.autoIncrement}, #{item.defaultValue},"
+ + " #{item.columnOpType}, #{item.deletedAt}, #{item.auditInfo})"
+ + "</foreach>"
+ + "</script>";
+ }
+
+ public String softDeleteColumnsByTableId(@Param("tableId") Long tableId) {
+ return "UPDATE "
+ + TableColumnMapper.COLUMN_TABLE_NAME
+ + " SET deleted_at = (UNIX_TIMESTAMP() * 1000.0)"
+ + " + EXTRACT(MICROSECOND FROM CURRENT_TIMESTAMP(3)) / 1000"
+ + " WHERE table_id = #{tableId} AND deleted_at = 0";
+ }
+
+ public String softDeleteColumnsByMetalakeId(@Param("metalakeId") Long metalakeId) {
+ return "UPDATE "
+ + TableColumnMapper.COLUMN_TABLE_NAME
+ + " SET deleted_at = (UNIX_TIMESTAMP() * 1000.0)"
+ + " + EXTRACT(MICROSECOND FROM CURRENT_TIMESTAMP(3)) / 1000"
+ + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0";
+ }
+
+ public String softDeleteColumnsByCatalogId(@Param("catalogId") Long catalogId) {
+ return "UPDATE "
+ + TableColumnMapper.COLUMN_TABLE_NAME
+ + " SET deleted_at = (UNIX_TIMESTAMP() * 1000.0)"
+ + " + EXTRACT(MICROSECOND FROM CURRENT_TIMESTAMP(3)) / 1000"
+ + " WHERE catalog_id = #{catalogId} AND deleted_at = 0";
+ }
+
+ public String softDeleteColumnsBySchemaId(@Param("schemaId") Long schemaId) {
+ return "UPDATE "
+ + TableColumnMapper.COLUMN_TABLE_NAME
+ + " SET deleted_at = (UNIX_TIMESTAMP() * 1000.0)"
+ + " + EXTRACT(MICROSECOND FROM CURRENT_TIMESTAMP(3)) / 1000"
+ + " WHERE schema_id = #{schemaId} AND deleted_at = 0";
+ }
+
+ public String deleteColumnPOsByLegacyTimeline(
+ @Param("legacyTimeline") Long legacyTimeline, @Param("limit") int limit) {
+ return "DELETE FROM "
+ + TableColumnMapper.COLUMN_TABLE_NAME
+ + " WHERE deleted_at > 0 AND deleted_at < #{legacyTimeline} LIMIT #{limit}";
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/TableColumnPostgreSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/TableColumnPostgreSQLProvider.java
new file mode 100644
index 0000000000..bf99438c8b
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/TableColumnPostgreSQLProvider.java
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.storage.relational.mapper.provider.postgresql;
+
+import org.apache.gravitino.storage.relational.mapper.TableColumnMapper;
+import org.apache.gravitino.storage.relational.mapper.provider.base.TableColumnBaseSQLProvider;
+import org.apache.ibatis.annotations.Param;
+
+public class TableColumnPostgreSQLProvider extends TableColumnBaseSQLProvider {
+
+ @Override
+ public String softDeleteColumnsByTableId(@Param("tableId") Long tableId) {
+ return "UPDATE "
+ + TableColumnMapper.COLUMN_TABLE_NAME
+ + " SET deleted_at = floor(extract(epoch from((current_timestamp -"
+ + " timestamp '1970-01-01 00:00:00')*1000)))"
+ + " WHERE table_id = #{tableId} AND deleted_at = 0";
+ }
+
+ @Override
+ public String softDeleteColumnsByMetalakeId(@Param("metalakeId") Long metalakeId) {
+ return "UPDATE "
+ + TableColumnMapper.COLUMN_TABLE_NAME
+ + " SET deleted_at = floor(extract(epoch from((current_timestamp -"
+ + " timestamp '1970-01-01 00:00:00')*1000)))"
+ + " WHERE metalake_id = #{metalakeId} AND deleted_at = 0";
+ }
+
+ @Override
+ public String softDeleteColumnsByCatalogId(@Param("catalogId") Long catalogId) {
+ return "UPDATE "
+ + TableColumnMapper.COLUMN_TABLE_NAME
+ + " SET deleted_at = floor(extract(epoch from((current_timestamp -"
+ + " timestamp '1970-01-01 00:00:00')*1000)))"
+ + " WHERE catalog_id = #{catalogId} AND deleted_at = 0";
+ }
+
+ @Override
+ public String softDeleteColumnsBySchemaId(@Param("schemaId") Long schemaId) {
+ return "UPDATE "
+ + TableColumnMapper.COLUMN_TABLE_NAME
+ + " SET deleted_at = floor(extract(epoch from((current_timestamp -"
+ + " timestamp '1970-01-01 00:00:00')*1000)))"
+ + " WHERE schema_id = #{schemaId} AND deleted_at = 0";
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/po/ColumnPO.java b/core/src/main/java/org/apache/gravitino/storage/relational/po/ColumnPO.java
new file mode 100644
index 0000000000..46c79f9732
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/po/ColumnPO.java
@@ -0,0 +1,269 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.storage.relational.po;
+
+import com.google.common.base.Preconditions;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import org.apache.commons.lang3.StringUtils;
+
+@EqualsAndHashCode
+@Getter
+public class ColumnPO {
+
+ public enum ColumnOpType {
+ CREATE((byte) 1),
+ UPDATE((byte) 2),
+ DELETE((byte) 3);
+
+ private final byte value;
+
+ ColumnOpType(byte value) {
+ this.value = value;
+ }
+
+ public byte value() {
+ return value;
+ }
+ }
+
+ public enum Nullable {
+ TRUE((byte) 0, true),
+ FALSE((byte) 1, false);
+
+ private final byte value;
+
+ private final boolean nullable;
+
+ Nullable(byte value, boolean nullable) {
+ this.value = value;
+ this.nullable = nullable;
+ }
+
+ public Byte value() {
+ return value;
+ }
+
+ public boolean nullable() {
+ return nullable;
+ }
+
+ public static Nullable fromValue(byte value) {
+ for (Nullable nullable : values()) {
+ if (nullable.value == value) {
+ return nullable;
+ }
+ }
+ throw new IllegalArgumentException("Invalid nullable value: " + value);
+ }
+
+ public static Nullable fromBoolean(boolean nullable) {
+ for (Nullable nullableEnum : values()) {
+ if (nullableEnum.nullable == nullable) {
+ return nullableEnum;
+ }
+ }
+ throw new IllegalArgumentException("Invalid nullable boolean value: " + nullable);
+ }
+ }
+
+ public enum AutoIncrement {
+ TRUE((byte) 0, true),
+ FALSE((byte) 1, false);
+
+ private final byte value;
+
+ private final boolean autoIncrement;
+
+ AutoIncrement(Byte value, boolean autoIncrement) {
+ this.value = value;
+ this.autoIncrement = autoIncrement;
+ }
+
+ public Byte value() {
+ return value;
+ }
+
+ public boolean autoIncrement() {
+ return autoIncrement;
+ }
+
+ public static AutoIncrement fromValue(byte value) {
+ for (AutoIncrement autoIncrement : values()) {
+ if (autoIncrement.value == value) {
+ return autoIncrement;
+ }
+ }
+ throw new IllegalArgumentException("Invalid auto increment value: " + value);
+ }
+
+ public static AutoIncrement fromBoolean(boolean autoIncrement) {
+ for (AutoIncrement autoIncrementEnum : values()) {
+ if (autoIncrementEnum.autoIncrement == autoIncrement) {
+ return autoIncrementEnum;
+ }
+ }
+ throw new IllegalArgumentException("Invalid auto increment boolean value: " + autoIncrement);
+ }
+ }
+
+ private Long columnId;
+
+ private String columnName;
+
+ private Long metalakeId;
+
+ private Long catalogId;
+
+ private Long schemaId;
+
+ private Long tableId;
+
+ private Long tableVersion;
+
+ private String columnType;
+
+ private String columnComment;
+
+ private Byte nullable;
+
+ private Byte autoIncrement;
+
+ private String defaultValue;
+
+ private Byte columnOpType;
+
+ private Long deletedAt;
+
+ private String auditInfo;
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ private ColumnPO() {}
+
+ public static class Builder {
+
+ private final ColumnPO columnPO;
+
+ private Builder() {
+ columnPO = new ColumnPO();
+ }
+
+ public Builder withColumnId(Long columnId) {
+ columnPO.columnId = columnId;
+ return this;
+ }
+
+ public Builder withColumnName(String columnName) {
+ columnPO.columnName = columnName;
+ return this;
+ }
+
+ public Builder withMetalakeId(Long metalakeId) {
+ columnPO.metalakeId = metalakeId;
+ return this;
+ }
+
+ public Builder withCatalogId(Long catalogId) {
+ columnPO.catalogId = catalogId;
+ return this;
+ }
+
+ public Builder withSchemaId(Long schemaId) {
+ columnPO.schemaId = schemaId;
+ return this;
+ }
+
+ public Builder withTableId(Long tableId) {
+ columnPO.tableId = tableId;
+ return this;
+ }
+
+ public Builder withTableVersion(Long tableVersion) {
+ columnPO.tableVersion = tableVersion;
+ return this;
+ }
+
+ public Builder withColumnType(String columnType) {
+ columnPO.columnType = columnType;
+ return this;
+ }
+
+ public Builder withColumnComment(String columnComment) {
+ columnPO.columnComment = columnComment;
+ return this;
+ }
+
+ public Builder withNullable(Byte nullable) {
+ columnPO.nullable = nullable;
+ return this;
+ }
+
+ public Builder withAutoIncrement(Byte autoIncrement) {
+ columnPO.autoIncrement = autoIncrement;
+ return this;
+ }
+
+ public Builder withDefaultValue(String defaultValue) {
+ columnPO.defaultValue = defaultValue;
+ return this;
+ }
+
+ public Builder withColumnOpType(Byte columnOpType) {
+ columnPO.columnOpType = columnOpType;
+ return this;
+ }
+
+ public Builder withDeletedAt(Long deletedAt) {
+ columnPO.deletedAt = deletedAt;
+ return this;
+ }
+
+ public Builder withAuditInfo(String auditInfo) {
+ columnPO.auditInfo = auditInfo;
+ return this;
+ }
+
+ public ColumnPO build() {
+ Preconditions.checkArgument(columnPO.columnId != null, "Column id is required");
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(columnPO.columnName),
+ "Column name is required and cannot be blank");
+ Preconditions.checkArgument(columnPO.metalakeId != null, "Metalake id is required");
+ Preconditions.checkArgument(columnPO.catalogId != null, "Catalog id is required");
+ Preconditions.checkArgument(columnPO.schemaId != null, "Schema id is required");
+ Preconditions.checkArgument(columnPO.tableId != null, "Table id is required");
+ Preconditions.checkArgument(columnPO.tableVersion != null, "Table version is required");
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(columnPO.columnType),
+ "Column type is required and cannot be blank");
+ Preconditions.checkArgument(columnPO.nullable != null, "Nullable is required");
+ Preconditions.checkArgument(columnPO.autoIncrement != null, "Auto increment is required");
+ Preconditions.checkArgument(
+ columnPO.columnOpType != null, "Column operation type is required");
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(columnPO.auditInfo), "Audit info is required and cannot be blank");
+ Preconditions.checkArgument(columnPO.deletedAt != null, "Deleted at is required");
+
+ return columnPO;
+ }
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/service/CatalogMetaService.java b/core/src/main/java/org/apache/gravitino/storage/relational/service/CatalogMetaService.java
index a6d462d429..6e6e8aaa41 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/service/CatalogMetaService.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/service/CatalogMetaService.java
@@ -38,6 +38,7 @@ import org.apache.gravitino.storage.relational.mapper.FilesetMetaMapper;
import org.apache.gravitino.storage.relational.mapper.FilesetVersionMapper;
import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
import org.apache.gravitino.storage.relational.mapper.SchemaMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.TableColumnMapper;
import org.apache.gravitino.storage.relational.mapper.TableMetaMapper;
import org.apache.gravitino.storage.relational.mapper.TopicMetaMapper;
import org.apache.gravitino.storage.relational.po.CatalogPO;
@@ -211,6 +212,10 @@ public class CatalogMetaService {
SessionUtils.doWithoutCommit(
TableMetaMapper.class,
mapper -> mapper.softDeleteTableMetasByCatalogId(catalogId)),
+ () ->
+ SessionUtils.doWithoutCommit(
+ TableColumnMapper.class,
+ mapper -> mapper.softDeleteColumnsByCatalogId(catalogId)),
() ->
SessionUtils.doWithoutCommit(
FilesetMetaMapper.class,
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/service/MetalakeMetaService.java b/core/src/main/java/org/apache/gravitino/storage/relational/service/MetalakeMetaService.java
index d7bdb9d1ff..dab3ba1dc5 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/service/MetalakeMetaService.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/service/MetalakeMetaService.java
@@ -41,6 +41,7 @@ import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
import org.apache.gravitino.storage.relational.mapper.RoleMetaMapper;
import org.apache.gravitino.storage.relational.mapper.SchemaMetaMapper;
import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
+import org.apache.gravitino.storage.relational.mapper.TableColumnMapper;
import org.apache.gravitino.storage.relational.mapper.TableMetaMapper;
import org.apache.gravitino.storage.relational.mapper.TagMetaMapper;
import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
@@ -191,6 +192,10 @@ public class MetalakeMetaService {
SessionUtils.doWithoutCommit(
TableMetaMapper.class,
mapper -> mapper.softDeleteTableMetasByMetalakeId(metalakeId)),
+ () ->
+ SessionUtils.doWithoutCommit(
+ TableColumnMapper.class,
+ mapper -> mapper.softDeleteColumnsByMetalakeId(metalakeId)),
() ->
SessionUtils.doWithoutCommit(
FilesetMetaMapper.class,
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/service/SchemaMetaService.java b/core/src/main/java/org/apache/gravitino/storage/relational/service/SchemaMetaService.java
index 3e11678116..d2b125f1c3 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/service/SchemaMetaService.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/service/SchemaMetaService.java
@@ -37,6 +37,7 @@ import org.apache.gravitino.storage.relational.mapper.FilesetMetaMapper;
import org.apache.gravitino.storage.relational.mapper.FilesetVersionMapper;
import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
import org.apache.gravitino.storage.relational.mapper.SchemaMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.TableColumnMapper;
import org.apache.gravitino.storage.relational.mapper.TableMetaMapper;
import org.apache.gravitino.storage.relational.mapper.TopicMetaMapper;
import org.apache.gravitino.storage.relational.po.SchemaPO;
@@ -197,6 +198,10 @@ public class SchemaMetaService {
SessionUtils.doWithoutCommit(
TableMetaMapper.class,
mapper -> mapper.softDeleteTableMetasBySchemaId(schemaId)),
+ () ->
+ SessionUtils.doWithoutCommit(
+ TableColumnMapper.class,
+ mapper -> mapper.softDeleteColumnsBySchemaId(schemaId)),
() ->
SessionUtils.doWithoutCommit(
FilesetMetaMapper.class,
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/service/TableColumnMetaService.java b/core/src/main/java/org/apache/gravitino/storage/relational/service/TableColumnMetaService.java
new file mode 100644
index 0000000000..7ec975d45f
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/service/TableColumnMetaService.java
@@ -0,0 +1,135 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.storage.relational.service;
+
+import com.google.common.collect.Lists;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.gravitino.meta.ColumnEntity;
+import org.apache.gravitino.meta.TableEntity;
+import org.apache.gravitino.storage.relational.mapper.TableColumnMapper;
+import org.apache.gravitino.storage.relational.po.ColumnPO;
+import org.apache.gravitino.storage.relational.po.TablePO;
+import org.apache.gravitino.storage.relational.utils.POConverters;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+
+public class TableColumnMetaService {
+
+ private static final TableColumnMetaService INSTANCE = new TableColumnMetaService();
+
+ private TableColumnMetaService() {}
+
+ public static TableColumnMetaService getInstance() {
+ return INSTANCE;
+ }
+
+ List<ColumnPO> getColumnsByTableIdAndVersion(Long tableId, Long version) {
+ List<ColumnPO> columnPOs =
+ SessionUtils.getWithoutCommit(
+ TableColumnMapper.class,
+ mapper -> mapper.listColumnPOsByTableIdAndVersion(tableId, version));
+
+ // Filter out the deleted columns
+ return columnPOs.stream()
+ .filter(c -> c.getColumnOpType() != ColumnPO.ColumnOpType.DELETE.value())
+ .collect(Collectors.toList());
+ }
+
+ void insertColumnPOs(TablePO tablePO, List<ColumnEntity> columnEntities) {
+ List<ColumnPO> columnPOs =
+ POConverters.initializeColumnPOs(tablePO, columnEntities, ColumnPO.ColumnOpType.CREATE);
+
+ // insertColumnPOs will be done in insertTable transaction, so we don't do commit here.
+ SessionUtils.doWithoutCommit(
+ TableColumnMapper.class, mapper -> mapper.insertColumnPOs(columnPOs));
+ }
+
+ boolean deleteColumnsByTableId(Long tableId) {
+ // deleteColumns will be done in deleteTable transaction, so we don't do commit here.
+ Integer result =
+ SessionUtils.doWithCommitAndFetchResult(
+ TableColumnMapper.class, mapper -> mapper.softDeleteColumnsByTableId(tableId));
+ return result > 0;
+ }
+
+ public int deleteColumnsByLegacyTimeline(Long legacyTimeline, int limit) {
+ // deleteColumns will be done in the outside transaction, so we don't do commit here.
+ return SessionUtils.doWithoutCommitAndFetchResult(
+ TableColumnMapper.class,
+ mapper -> mapper.deleteColumnPOsByLegacyTimeline(legacyTimeline, limit));
+ }
+
+ boolean isColumnUpdated(TableEntity oldTable, TableEntity newTable) {
+ Map<Long, ColumnEntity> oldColumns =
+ oldTable.columns() == null
+ ? Collections.emptyMap()
+ : oldTable.columns().stream()
+ .collect(Collectors.toMap(ColumnEntity::id, Function.identity()));
+
+ Map<Long, ColumnEntity> newColumns =
+ newTable.columns() == null
+ ? Collections.emptyMap()
+ : newTable.columns().stream()
+ .collect(Collectors.toMap(ColumnEntity::id, Function.identity()));
+
+ return oldColumns.size() != newColumns.size() || !oldColumns.equals(newColumns);
+ }
+
+ void updateColumnPOsFromTableDiff(
+ TableEntity oldTable, TableEntity newTable, TablePO newTablePO) {
+ Map<Long, ColumnEntity> oldColumns =
+ oldTable.columns() == null
+ ? Collections.emptyMap()
+ : oldTable.columns().stream()
+ .collect(Collectors.toMap(ColumnEntity::id, Function.identity()));
+ Map<Long, ColumnEntity> newColumns =
+ newTable.columns() == null
+ ? Collections.emptyMap()
+ : newTable.columns().stream()
+ .collect(Collectors.toMap(ColumnEntity::id, Function.identity()));
+
+ List<ColumnPO> columnPOsToInsert = Lists.newArrayList();
+ for (ColumnEntity newColumn : newColumns.values()) {
+ ColumnEntity oldColumn = oldColumns.get(newColumn.id());
+ if (oldColumn == null || !oldColumn.equals(newColumn)) {
+ columnPOsToInsert.add(
+ POConverters.initializeColumnPO(newTablePO, newColumn, ColumnPO.ColumnOpType.UPDATE));
+ }
+ }
+
+ for (ColumnEntity oldColumn : oldColumns.values()) {
+ if (!newColumns.containsKey(oldColumn.id())) {
+ columnPOsToInsert.add(
+ POConverters.initializeColumnPO(newTablePO, oldColumn, ColumnPO.ColumnOpType.DELETE));
+ }
+ }
+
+ // If there is no change, directly return
+ if (columnPOsToInsert.isEmpty()) {
+ return;
+ }
+
+ // updateColumns will be done in updateTable transaction, so we don't do commit here.
+ SessionUtils.doWithoutCommit(
+ TableColumnMapper.class, mapper -> mapper.insertColumnPOs(columnPOsToInsert));
+ }
+}
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/service/TableMetaService.java b/core/src/main/java/org/apache/gravitino/storage/relational/service/TableMetaService.java
index 87a2df50ee..ed7afe748d 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/service/TableMetaService.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/service/TableMetaService.java
@@ -22,6 +22,8 @@ import com.google.common.base.Preconditions;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import org.apache.gravitino.Entity;
import org.apache.gravitino.HasIdentifier;
@@ -32,6 +34,7 @@ import org.apache.gravitino.exceptions.NoSuchEntityException;
import org.apache.gravitino.meta.TableEntity;
import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
import org.apache.gravitino.storage.relational.mapper.TableMetaMapper;
+import org.apache.gravitino.storage.relational.po.ColumnPO;
import org.apache.gravitino.storage.relational.po.TablePO;
import org.apache.gravitino.storage.relational.utils.ExceptionUtils;
import org.apache.gravitino.storage.relational.utils.POConverters;
@@ -49,21 +52,6 @@ public class TableMetaService {
private TableMetaService() {}
- public TablePO getTablePOBySchemaIdAndName(Long schemaId, String tableName) {
- TablePO tablePO =
- SessionUtils.getWithoutCommit(
- TableMetaMapper.class,
- mapper -> mapper.selectTableMetaBySchemaIdAndName(schemaId, tableName));
-
- if (tablePO == null) {
- throw new NoSuchEntityException(
- NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
- Entity.EntityType.TABLE.name().toLowerCase(),
- tableName);
- }
- return tablePO;
- }
-
// Table may be deleted, so the TablePO may be null.
public TablePO getTablePOById(Long tableId) {
TablePO tablePO =
@@ -94,8 +82,11 @@ public class TableMetaService {
CommonMetaService.getInstance().getParentEntityIdByNamespace(identifier.namespace());
TablePO tablePO = getTablePOBySchemaIdAndName(schemaId, identifier.name());
+ List<ColumnPO> columnPOs =
+ TableColumnMetaService.getInstance()
+ .getColumnsByTableIdAndVersion(tablePO.getTableId(), tablePO.getCurrentVersion());
- return POConverters.fromTablePO(tablePO, identifier.namespace());
+ return POConverters.fromTableAndColumnPOs(tablePO, columnPOs, identifier.namespace());
}
public List<TableEntity> listTablesByNamespace(Namespace namespace) {
@@ -117,16 +108,34 @@ public class TableMetaService {
TablePO.Builder builder = TablePO.builder();
fillTablePOBuilderParentEntityId(builder, tableEntity.namespace());
- SessionUtils.doWithCommit(
- TableMetaMapper.class,
- mapper -> {
- TablePO po = POConverters.initializeTablePOWithVersion(tableEntity, builder);
+ AtomicReference<TablePO> tablePORef = new AtomicReference<>();
+ SessionUtils.doMultipleWithCommit(
+ () ->
+ SessionUtils.doWithoutCommit(
+ TableMetaMapper.class,
+ mapper -> {
+ TablePO po = POConverters.initializeTablePOWithVersion(tableEntity, builder);
+ tablePORef.set(po);
+ if (overwrite) {
+ mapper.insertTableMetaOnDuplicateKeyUpdate(po);
+ } else {
+ mapper.insertTableMeta(po);
+ }
+ }),
+ () -> {
+ // We need to delete the columns first if we want to overwrite the table.
if (overwrite) {
- mapper.insertTableMetaOnDuplicateKeyUpdate(po);
- } else {
- mapper.insertTableMeta(po);
+ TableColumnMetaService.getInstance()
+ .deleteColumnsByTableId(tablePORef.get().getTableId());
+ }
+ },
+ () -> {
+ if (tableEntity.columns() != null && !tableEntity.columns().isEmpty()) {
+ TableColumnMetaService.getInstance()
+ .insertColumnPOs(tablePORef.get(), tableEntity.columns());
}
});
+
} catch (RuntimeException re) {
ExceptionUtils.checkSQLException(
re, Entity.EntityType.TABLE, tableEntity.nameIdentifier().toString());
@@ -144,30 +153,47 @@ public class TableMetaService {
CommonMetaService.getInstance().getParentEntityIdByNamespace(identifier.namespace());
TablePO oldTablePO = getTablePOBySchemaIdAndName(schemaId, tableName);
- TableEntity oldTableEntity = POConverters.fromTablePO(oldTablePO, identifier.namespace());
- TableEntity newEntity = (TableEntity) updater.apply((E) oldTableEntity);
+ List<ColumnPO> oldTableColumns =
+ TableColumnMetaService.getInstance()
+ .getColumnsByTableIdAndVersion(oldTablePO.getTableId(), oldTablePO.getCurrentVersion());
+ TableEntity oldTableEntity =
+ POConverters.fromTableAndColumnPOs(oldTablePO, oldTableColumns, identifier.namespace());
+
+ TableEntity newTableEntity = (TableEntity) updater.apply((E) oldTableEntity);
Preconditions.checkArgument(
- Objects.equals(oldTableEntity.id(), newEntity.id()),
+ Objects.equals(oldTableEntity.id(), newTableEntity.id()),
"The updated table entity id: %s should be same with the table entity id before: %s",
- newEntity.id(),
+ newTableEntity.id(),
oldTableEntity.id());
- Integer updateResult;
+ boolean isColumnChanged =
+ TableColumnMetaService.getInstance().isColumnUpdated(oldTableEntity, newTableEntity);
+ TablePO newTablePO =
+ POConverters.updateTablePOWithVersion(oldTablePO, newTableEntity, isColumnChanged);
+
+ final AtomicInteger updateResult = new AtomicInteger(0);
try {
- updateResult =
- SessionUtils.doWithCommitAndFetchResult(
- TableMetaMapper.class,
- mapper ->
- mapper.updateTableMeta(
- POConverters.updateTablePOWithVersion(oldTablePO, newEntity), oldTablePO));
+ SessionUtils.doMultipleWithCommit(
+ () ->
+ updateResult.set(
+ SessionUtils.doWithoutCommitAndFetchResult(
+ TableMetaMapper.class,
+ mapper -> mapper.updateTableMeta(newTablePO, oldTablePO))),
+ () -> {
+ if (updateResult.get() > 0 && isColumnChanged) {
+ TableColumnMetaService.getInstance()
+ .updateColumnPOsFromTableDiff(oldTableEntity, newTableEntity, newTablePO);
+ }
+ });
+
} catch (RuntimeException re) {
ExceptionUtils.checkSQLException(
- re, Entity.EntityType.TABLE, newEntity.nameIdentifier().toString());
+ re, Entity.EntityType.TABLE, newTableEntity.nameIdentifier().toString());
throw re;
}
- if (updateResult > 0) {
- return newEntity;
+ if (updateResult.get() > 0) {
+ return newTableEntity;
} else {
throw new IOException("Failed to update the entity: " + identifier);
}
@@ -183,26 +209,35 @@ public class TableMetaService {
Long tableId = getTableIdBySchemaIdAndName(schemaId, tableName);
+ AtomicInteger deleteResult = new AtomicInteger(0);
SessionUtils.doMultipleWithCommit(
() ->
- SessionUtils.doWithoutCommit(
- TableMetaMapper.class, mapper -> mapper.softDeleteTableMetasByTableId(tableId)),
- () ->
+ deleteResult.set(
+ SessionUtils.doWithCommitAndFetchResult(
+ TableMetaMapper.class,
+ mapper -> mapper.softDeleteTableMetasByTableId(tableId))),
+ () -> {
+ if (deleteResult.get() > 0) {
SessionUtils.doWithoutCommit(
OwnerMetaMapper.class,
mapper ->
mapper.softDeleteOwnerRelByMetadataObjectIdAndType(
- tableId, MetadataObject.Type.TABLE.name())));
+ tableId, MetadataObject.Type.TABLE.name()));
+ }
+ },
+ () -> {
+ if (deleteResult.get() > 0) {
+ TableColumnMetaService.getInstance().deleteColumnsByTableId(tableId);
+ }
+ });
- return true;
+ return deleteResult.get() > 0;
}
public int deleteTableMetasByLegacyTimeline(Long legacyTimeline, int limit) {
return SessionUtils.doWithCommitAndFetchResult(
TableMetaMapper.class,
- mapper -> {
- return mapper.deleteTableMetasByLegacyTimeline(legacyTimeline, limit);
- });
+ mapper -> mapper.deleteTableMetasByLegacyTimeline(legacyTimeline, limit));
}
private void fillTablePOBuilderParentEntityId(TablePO.Builder builder, Namespace namespace) {
@@ -229,4 +264,19 @@ public class TableMetaService {
}
}
}
+
+ private TablePO getTablePOBySchemaIdAndName(Long schemaId, String tableName) {
+ TablePO tablePO =
+ SessionUtils.getWithoutCommit(
+ TableMetaMapper.class,
+ mapper -> mapper.selectTableMetaBySchemaIdAndName(schemaId, tableName));
+
+ if (tablePO == null) {
+ throw new NoSuchEntityException(
+ NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+ Entity.EntityType.TABLE.name().toLowerCase(),
+ tableName);
+ }
+ return tablePO;
+ }
}
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/session/SqlSessionFactoryHelper.java b/core/src/main/java/org/apache/gravitino/storage/relational/session/SqlSessionFactoryHelper.java
index 9d92827162..4fe53dba38 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/session/SqlSessionFactoryHelper.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/session/SqlSessionFactoryHelper.java
@@ -37,6 +37,7 @@ import org.apache.gravitino.storage.relational.mapper.OwnerMetaMapper;
import org.apache.gravitino.storage.relational.mapper.RoleMetaMapper;
import org.apache.gravitino.storage.relational.mapper.SchemaMetaMapper;
import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
+import org.apache.gravitino.storage.relational.mapper.TableColumnMapper;
import org.apache.gravitino.storage.relational.mapper.TableMetaMapper;
import org.apache.gravitino.storage.relational.mapper.TagMetaMapper;
import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
@@ -110,6 +111,7 @@ public class SqlSessionFactoryHelper {
configuration.addMapper(CatalogMetaMapper.class);
configuration.addMapper(SchemaMetaMapper.class);
configuration.addMapper(TableMetaMapper.class);
+ configuration.addMapper(TableColumnMapper.class);
configuration.addMapper(FilesetMetaMapper.class);
configuration.addMapper(FilesetVersionMapper.class);
configuration.addMapper(TopicMetaMapper.class);
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/utils/POConverters.java b/core/src/main/java/org/apache/gravitino/storage/relational/utils/POConverters.java
index f09f6751cf..dabce09cb2 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/utils/POConverters.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/utils/POConverters.java
@@ -22,6 +22,7 @@ package org.apache.gravitino.storage.relational.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.Lists;
import java.time.Instant;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -34,11 +35,14 @@ import org.apache.gravitino.authorization.Privilege;
import org.apache.gravitino.authorization.Privileges;
import org.apache.gravitino.authorization.SecurableObject;
import org.apache.gravitino.authorization.SecurableObjects;
+import org.apache.gravitino.dto.rel.expressions.FunctionArg;
+import org.apache.gravitino.dto.util.DTOConverters;
import org.apache.gravitino.file.Fileset;
import org.apache.gravitino.json.JsonUtils;
import org.apache.gravitino.meta.AuditInfo;
import org.apache.gravitino.meta.BaseMetalake;
import org.apache.gravitino.meta.CatalogEntity;
+import org.apache.gravitino.meta.ColumnEntity;
import org.apache.gravitino.meta.FilesetEntity;
import org.apache.gravitino.meta.GroupEntity;
import org.apache.gravitino.meta.RoleEntity;
@@ -48,7 +52,11 @@ import org.apache.gravitino.meta.TableEntity;
import org.apache.gravitino.meta.TagEntity;
import org.apache.gravitino.meta.TopicEntity;
import org.apache.gravitino.meta.UserEntity;
+import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.expressions.Expression;
+import org.apache.gravitino.rel.types.Type;
import org.apache.gravitino.storage.relational.po.CatalogPO;
+import org.apache.gravitino.storage.relational.po.ColumnPO;
import org.apache.gravitino.storage.relational.po.ExtendedGroupPO;
import org.apache.gravitino.storage.relational.po.ExtendedUserPO;
import org.apache.gravitino.storage.relational.po.FilesetPO;
@@ -380,12 +388,21 @@ public class POConverters {
*
* @param oldTablePO the old TablePO object
* @param newTable the new TableEntity object
+ * @param needUpdateVersion whether need to update the version
* @return TablePO object with updated version
*/
- public static TablePO updateTablePOWithVersion(TablePO oldTablePO, TableEntity newTable) {
- Long lastVersion = oldTablePO.getLastVersion();
- // Will set the version to the last version + 1 when having some fields need be multiple version
- Long nextVersion = lastVersion;
+ public static TablePO updateTablePOWithVersion(
+ TablePO oldTablePO, TableEntity newTable, boolean needUpdateVersion) {
+ Long lastVersion;
+ Long currentVersion;
+ if (needUpdateVersion) {
+ lastVersion = oldTablePO.getLastVersion() + 1;
+ currentVersion = lastVersion;
+ } else {
+ lastVersion = oldTablePO.getLastVersion();
+ currentVersion = oldTablePO.getCurrentVersion();
+ }
+
try {
return TablePO.builder()
.withTableId(oldTablePO.getTableId())
@@ -394,8 +411,8 @@ public class POConverters {
.withCatalogId(oldTablePO.getCatalogId())
.withSchemaId(oldTablePO.getSchemaId())
.withAuditInfo(JsonUtils.anyFieldMapper().writeValueAsString(newTable.auditInfo()))
- .withCurrentVersion(nextVersion)
- .withLastVersion(nextVersion)
+ .withCurrentVersion(currentVersion)
+ .withLastVersion(lastVersion)
.withDeletedAt(DEFAULT_DELETED_AT)
.build();
} catch (JsonProcessingException e) {
@@ -411,11 +428,17 @@ public class POConverters {
* @return TableEntity object from TablePO object
*/
public static TableEntity fromTablePO(TablePO tablePO, Namespace namespace) {
+ return fromTableAndColumnPOs(tablePO, Collections.emptyList(), namespace);
+ }
+
+ public static TableEntity fromTableAndColumnPOs(
+ TablePO tablePO, List<ColumnPO> columnPOs, Namespace namespace) {
try {
return TableEntity.builder()
.withId(tablePO.getTableId())
.withName(tablePO.getTableName())
.withNamespace(namespace)
+ .withColumns(fromColumnPOs(columnPOs))
.withAuditInfo(
JsonUtils.anyFieldMapper().readValue(tablePO.getAuditInfo(), AuditInfo.class))
.build();
@@ -424,6 +447,73 @@ public class POConverters {
}
}
+ public static ColumnEntity fromColumnPO(ColumnPO columnPO) {
+ try {
+ return ColumnEntity.builder()
+ .withId(columnPO.getColumnId())
+ .withName(columnPO.getColumnName())
+ .withDataType(JsonUtils.anyFieldMapper().readValue(columnPO.getColumnType(), Type.class))
+ .withComment(columnPO.getColumnComment())
+ .withAutoIncrement(
+ ColumnPO.AutoIncrement.fromValue(columnPO.getAutoIncrement()).autoIncrement())
+ .withNullable(ColumnPO.Nullable.fromValue(columnPO.getNullable()).nullable())
+ .withDefaultValue(
+ columnPO.getDefaultValue() == null
+ ? Column.DEFAULT_VALUE_NOT_SET
+ : DTOConverters.fromFunctionArg(
+ (FunctionArg)
+ JsonUtils.anyFieldMapper()
+ .readValue(columnPO.getDefaultValue(), Expression.class)))
+ .withAuditInfo(
+ JsonUtils.anyFieldMapper().readValue(columnPO.getAuditInfo(), AuditInfo.class))
+ .build();
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException("Failed to deserialize json object:", e);
+ }
+ }
+
+ public static List<ColumnEntity> fromColumnPOs(List<ColumnPO> columnPOs) {
+ return columnPOs.stream().map(POConverters::fromColumnPO).collect(Collectors.toList());
+ }
+
+ public static ColumnPO initializeColumnPO(
+ TablePO tablePO, ColumnEntity columnEntity, ColumnPO.ColumnOpType opType) {
+ try {
+ return ColumnPO.builder()
+ .withColumnId(columnEntity.id())
+ .withColumnName(columnEntity.name())
+ .withMetalakeId(tablePO.getMetalakeId())
+ .withCatalogId(tablePO.getCatalogId())
+ .withSchemaId(tablePO.getSchemaId())
+ .withTableId(tablePO.getTableId())
+ .withTableVersion(tablePO.getCurrentVersion())
+ .withColumnType(JsonUtils.anyFieldMapper().writeValueAsString(columnEntity.dataType()))
+ .withColumnComment(columnEntity.comment())
+ .withNullable(ColumnPO.Nullable.fromBoolean(columnEntity.nullable()).value())
+ .withAutoIncrement(
+ ColumnPO.AutoIncrement.fromBoolean(columnEntity.autoIncrement()).value())
+ .withDefaultValue(
+ columnEntity.defaultValue() == null
+ || columnEntity.defaultValue().equals(Column.DEFAULT_VALUE_NOT_SET)
+ ? null
+ : JsonUtils.anyFieldMapper()
+ .writeValueAsString(DTOConverters.toFunctionArg(columnEntity.defaultValue())))
+ .withColumnOpType(opType.value())
+ .withAuditInfo(JsonUtils.anyFieldMapper().writeValueAsString(columnEntity.auditInfo()))
+ .withDeletedAt(DEFAULT_DELETED_AT)
+ .build();
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException("Failed to serialize json object:", e);
+ }
+ }
+
+ public static List<ColumnPO> initializeColumnPOs(
+ TablePO tablePO, List<ColumnEntity> columnEntities, ColumnPO.ColumnOpType opType) {
+ return columnEntities.stream()
+ .map(columnEntity -> initializeColumnPO(tablePO, columnEntity, opType))
+ .collect(Collectors.toList());
+ }
+
/**
* Convert list of {@link TablePO} to list of {@link TableEntity}
*
diff --git a/core/src/test/java/org/apache/gravitino/meta/TestColumnEntity.java b/core/src/test/java/org/apache/gravitino/meta/TestColumnEntity.java
index 2bae86a50b..e7ad7e7d07 100644
--- a/core/src/test/java/org/apache/gravitino/meta/TestColumnEntity.java
+++ b/core/src/test/java/org/apache/gravitino/meta/TestColumnEntity.java
@@ -19,7 +19,10 @@
package org.apache.gravitino.meta;
import java.time.Instant;
+import java.util.Arrays;
+import java.util.List;
import org.apache.gravitino.Namespace;
+import org.apache.gravitino.rel.Column;
import org.apache.gravitino.rel.expressions.literals.Literals;
import org.apache.gravitino.rel.types.Types;
import org.junit.jupiter.api.Assertions;
@@ -74,7 +77,7 @@ public class TestColumnEntity {
.withAuditInfo(
AuditInfo.builder().withCreator("test").withCreateTime(Instant.now()).build())
.build();
- Assertions.assertNull(columnEntity3.defaultValue());
+ Assertions.assertEquals(Column.DEFAULT_VALUE_NOT_SET, columnEntity3.defaultValue());
}
@Test
@@ -175,7 +178,7 @@ public class TestColumnEntity {
AuditInfo.builder().withCreator("test3").withCreateTime(Instant.now()).build())
.build();
- ColumnEntity[] columns = new ColumnEntity[] {columnEntity1, columnEntity2, columnEntity3};
+ List<ColumnEntity> columns = Arrays.asList(columnEntity1, columnEntity2, columnEntity3);
TableEntity tableEntity =
TableEntity.builder()
.withId(1L)
@@ -189,7 +192,7 @@ public class TestColumnEntity {
Assertions.assertEquals(1L, tableEntity.id());
Assertions.assertEquals("test", tableEntity.name());
Assertions.assertEquals(Namespace.of("catalog", "schema"), tableEntity.namespace());
- Assertions.assertArrayEquals(columns, tableEntity.columns());
- Assertions.assertEquals(3, tableEntity.columns().length);
+ Assertions.assertEquals(columns, tableEntity.columns());
+ Assertions.assertEquals(3, tableEntity.columns().size());
}
}
diff --git a/core/src/test/java/org/apache/gravitino/storage/TestEntityStorage.java b/core/src/test/java/org/apache/gravitino/storage/TestEntityStorage.java
index 46bb5fb933..e199382859 100644
--- a/core/src/test/java/org/apache/gravitino/storage/TestEntityStorage.java
+++ b/core/src/test/java/org/apache/gravitino/storage/TestEntityStorage.java
@@ -42,6 +42,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.time.Instant;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
@@ -69,6 +70,7 @@ import org.apache.gravitino.integration.test.util.AbstractIT;
import org.apache.gravitino.meta.AuditInfo;
import org.apache.gravitino.meta.BaseMetalake;
import org.apache.gravitino.meta.CatalogEntity;
+import org.apache.gravitino.meta.ColumnEntity;
import org.apache.gravitino.meta.FilesetEntity;
import org.apache.gravitino.meta.GroupEntity;
import org.apache.gravitino.meta.RoleEntity;
@@ -77,6 +79,8 @@ import org.apache.gravitino.meta.SchemaVersion;
import org.apache.gravitino.meta.TableEntity;
import org.apache.gravitino.meta.TopicEntity;
import org.apache.gravitino.meta.UserEntity;
+import org.apache.gravitino.rel.types.Type;
+import org.apache.gravitino.rel.types.Types;
import org.apache.gravitino.storage.relational.converters.H2ExceptionConverter;
import org.apache.gravitino.storage.relational.converters.MySQLExceptionConverter;
import org.apache.gravitino.storage.relational.converters.PostgreSQLExceptionConverter;
@@ -91,6 +95,7 @@ import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.testcontainers.shaded.org.apache.commons.lang3.tuple.Pair;
@Tag("gravitino-docker-test")
public class TestEntityStorage {
@@ -570,9 +575,19 @@ public class TestEntityStorage {
SchemaEntity schema1 =
createSchemaEntity(1L, Namespace.of("metalake", "catalog"), "schema1", auditInfo);
+ ColumnEntity column1 =
+ createColumnEntity(
+ RandomIdGenerator.INSTANCE.nextId(), "column1", Types.StringType.get(), auditInfo);
+ ColumnEntity column2 =
+ createColumnEntity(
+ RandomIdGenerator.INSTANCE.nextId(), "column2", Types.StringType.get(), auditInfo);
TableEntity table1 =
- createTableEntity(
- 1L, Namespace.of("metalake", "catalog", "schema1"), "table1", auditInfo);
+ createTableEntityWithColumns(
+ 1L,
+ Namespace.of("metalake", "catalog", "schema1"),
+ "table1",
+ auditInfo,
+ Lists.newArrayList(column1, column2));
FilesetEntity fileset1 =
createFilesetEntity(
1L, Namespace.of("metalake", "catalog", "schema1"), "fileset1", auditInfo);
@@ -582,9 +597,19 @@ public class TestEntityStorage {
SchemaEntity schema2 =
createSchemaEntity(2L, Namespace.of("metalake", "catalog"), "schema2", auditInfo);
+ ColumnEntity column3 =
+ createColumnEntity(
+ RandomIdGenerator.INSTANCE.nextId(), "column3", Types.StringType.get(), auditInfo);
+ ColumnEntity column4 =
+ createColumnEntity(
+ RandomIdGenerator.INSTANCE.nextId(), "column4", Types.StringType.get(), auditInfo);
TableEntity table1InSchema2 =
- createTableEntity(
- 2L, Namespace.of("metalake", "catalog", "schema2"), "table1", auditInfo);
+ createTableEntityWithColumns(
+ 2L,
+ Namespace.of("metalake", "catalog", "schema2"),
+ "table1",
+ auditInfo,
+ Lists.newArrayList(column3, column4));
FilesetEntity fileset1InSchema2 =
createFilesetEntity(
2L, Namespace.of("metalake", "catalog", "schema2"), "fileset1", auditInfo);
@@ -705,18 +730,20 @@ public class TestEntityStorage {
store.put(schema2New);
// table
TableEntity table1New =
- createTableEntity(
+ createTableEntityWithColumns(
RandomIdGenerator.INSTANCE.nextId(),
table1.namespace(),
table1.name(),
- table1.auditInfo());
+ table1.auditInfo(),
+ table1.columns());
store.put(table1New);
TableEntity table1InSchema2New =
- createTableEntity(
+ createTableEntityWithColumns(
RandomIdGenerator.INSTANCE.nextId(),
table1InSchema2.namespace(),
table1InSchema2.name(),
- table1InSchema2.auditInfo());
+ table1InSchema2.auditInfo(),
+ table1InSchema2.columns());
store.put(table1InSchema2New);
// fileset
FilesetEntity fileset1New =
@@ -1228,13 +1255,32 @@ public class TestEntityStorage {
.build();
}
+ public static ColumnEntity createColumnEntity(
+ Long id, String name, Type dataType, AuditInfo auditInfo) {
+ return ColumnEntity.builder()
+ .withId(id)
+ .withName(name)
+ .withComment("")
+ .withDataType(dataType)
+ .withNullable(true)
+ .withAutoIncrement(false)
+ .withAuditInfo(auditInfo)
+ .build();
+ }
+
public static TableEntity createTableEntity(
Long id, Namespace namespace, String name, AuditInfo auditInfo) {
+ return createTableEntityWithColumns(id, namespace, name, auditInfo, Collections.emptyList());
+ }
+
+ public static TableEntity createTableEntityWithColumns(
+ Long id, Namespace namespace, String name, AuditInfo auditInfo, List<ColumnEntity> columns) {
return TableEntity.builder()
.withId(id)
.withName(name)
.withNamespace(namespace)
.withAuditInfo(auditInfo)
+ .withColumns(columns)
.build();
}
@@ -1325,6 +1371,7 @@ public class TestEntityStorage {
Assertions.assertFalse(store.exists(table1.nameIdentifier(), Entity.EntityType.TABLE));
// Delete again should return false
Assertions.assertFalse(store.delete(table1.nameIdentifier(), Entity.EntityType.TABLE, true));
+ validateDeletedColumns(table1.id(), table1.type());
}
private void validateDeleteFileset(
@@ -1391,6 +1438,7 @@ public class TestEntityStorage {
Assertions.assertFalse(store.exists(userNew.nameIdentifier(), Entity.EntityType.USER));
Assertions.assertFalse(store.exists(groupNew.nameIdentifier(), EntityType.GROUP));
Assertions.assertFalse(store.exists(roleNew.nameIdentifier(), EntityType.ROLE));
+ validateDeletedColumns(metalake.id(), metalake.type());
// Delete again should return false
Assertions.assertFalse(
@@ -1407,6 +1455,7 @@ public class TestEntityStorage {
Assertions.assertThrowsExactly(
NoSuchEntityException.class,
() -> store.get(id, Entity.EntityType.CATALOG, CatalogEntity.class));
+ validateDeletedColumns(catalog.id(), catalog.type());
Assertions.assertThrowsExactly(
NoSuchEntityException.class,
@@ -1423,11 +1472,12 @@ public class TestEntityStorage {
TopicEntity topic1)
throws IOException {
TableEntity table1New =
- createTableEntity(
+ createTableEntityWithColumns(
RandomIdGenerator.INSTANCE.nextId(),
table1.namespace(),
table1.name(),
- table1.auditInfo());
+ table1.auditInfo(),
+ table1.columns());
store.put(table1New);
FilesetEntity fileset1New =
createFilesetEntity(
@@ -1464,6 +1514,9 @@ public class TestEntityStorage {
Assertions.assertTrue(e instanceof NoSuchEntityException);
Assertions.assertTrue(e.getMessage().contains("schema1"));
}
+
+ validateDeletedColumns(schema1.id(), schema1.type());
+
// Delete again should return false
Assertions.assertFalse(store.delete(schema1.nameIdentifier(), Entity.EntityType.SCHEMA, true));
@@ -1476,7 +1529,7 @@ public class TestEntityStorage {
() -> store.get(topic1.nameIdentifier(), Entity.EntityType.TOPIC, TopicEntity.class));
}
- private static void validateDeleteMetalake(
+ private void validateDeleteMetalake(
EntityStore store,
BaseMetalake metalake,
CatalogEntity catalogCopy,
@@ -1504,7 +1557,7 @@ public class TestEntityStorage {
Assertions.assertFalse(store.delete(metalake.nameIdentifier(), Entity.EntityType.METALAKE));
}
- private static void validateDeleteCatalog(
+ private void validateDeleteCatalog(
EntityStore store,
CatalogEntity catalog,
TableEntity table1,
@@ -1521,6 +1574,7 @@ public class TestEntityStorage {
NonEmptyEntityException.class,
() -> store.delete(catalog.nameIdentifier(), Entity.EntityType.CATALOG));
store.delete(table1.nameIdentifier(), Entity.EntityType.TABLE);
+ validateDeletedColumns(table1.id(), table1.type());
store.delete(fileset1.nameIdentifier(), Entity.EntityType.FILESET);
store.delete(topic1.nameIdentifier(), Entity.EntityType.TOPIC);
try {
@@ -1530,6 +1584,7 @@ public class TestEntityStorage {
}
store.delete(schema1.nameIdentifier(), Entity.EntityType.SCHEMA);
store.delete(table1InSchema2.nameIdentifier(), Entity.EntityType.TABLE);
+ validateDeletedColumns(table1InSchema2.id(), table1InSchema2.type());
Assertions.assertFalse(
store.exists(fileset1InSchema2.nameIdentifier(), Entity.EntityType.FILESET));
Assertions.assertFalse(store.exists(topic1InSchema2.nameIdentifier(), Entity.EntityType.TOPIC));
@@ -1541,7 +1596,7 @@ public class TestEntityStorage {
Assertions.assertFalse(store.delete(catalog.nameIdentifier(), Entity.EntityType.CATALOG));
}
- private static void validateDeleteSchema(
+ private void validateDeleteSchema(
EntityStore store,
SchemaEntity schema1,
TableEntity table1,
@@ -1559,11 +1614,13 @@ public class TestEntityStorage {
// has not been deleted yet;
Assertions.assertTrue(store.exists(schema1.nameIdentifier(), Entity.EntityType.SCHEMA));
Assertions.assertTrue(store.exists(table1.nameIdentifier(), Entity.EntityType.TABLE));
+ ;
Assertions.assertTrue(store.exists(fileset1.nameIdentifier(), Entity.EntityType.FILESET));
Assertions.assertTrue(store.exists(topic1.nameIdentifier(), Entity.EntityType.TOPIC));
// Delete table1,fileset1 and schema1
Assertions.assertTrue(store.delete(table1.nameIdentifier(), Entity.EntityType.TABLE));
+ validateDeletedColumns(table1.id(), table1.type());
Assertions.assertTrue(store.delete(fileset1.nameIdentifier(), Entity.EntityType.FILESET));
Assertions.assertTrue(store.delete(topic1.nameIdentifier(), Entity.EntityType.TOPIC));
Assertions.assertTrue(store.delete(schema1.nameIdentifier(), Entity.EntityType.SCHEMA));
@@ -1667,19 +1724,23 @@ public class TestEntityStorage {
// delete again should return false
Assertions.assertFalse(store.delete(table1InSchema2.nameIdentifier(), Entity.EntityType.TABLE));
+ // Make sure all columns are deleted
+ validateDeletedColumns(table1InSchema2.id(), table1InSchema2.type());
+
// Make sure table 'metalake.catalog.schema1.table1' still exist;
Assertions.assertEquals(
table1, store.get(table1.nameIdentifier(), Entity.EntityType.TABLE, TableEntity.class));
// Make sure schema 'metalake.catalog.schema2' still exist;
Assertions.assertEquals(
schema2, store.get(schema2.nameIdentifier(), Entity.EntityType.SCHEMA, SchemaEntity.class));
- // Re-insert table1Inschema2 and everything is OK
+ // Re-insert table1InSchema2 and everything is OK
TableEntity table1InSchema2New =
- createTableEntity(
+ createTableEntityWithColumns(
RandomIdGenerator.INSTANCE.nextId(),
table1InSchema2.namespace(),
table1InSchema2.name(),
- table1InSchema2.auditInfo());
+ table1InSchema2.auditInfo(),
+ table1InSchema2.columns());
store.put(table1InSchema2New);
Assertions.assertTrue(store.exists(table1InSchema2.nameIdentifier(), Entity.EntityType.TABLE));
}
@@ -2136,6 +2197,55 @@ public class TestEntityStorage {
(e) -> e));
}
+ private List<Pair<Long, Pair<Long, Long>>> listAllColumnWithEntityId(
+ Long entityId, Entity.EntityType entityType) {
+ String queryTemp =
+ "SELECT column_id, table_version, deleted_at FROM "
+ + "table_column_version_info WHERE %s = %d";
+ String query;
+ switch (entityType) {
+ case TABLE:
+ query = String.format(queryTemp, "table_id", entityId);
+ break;
+ case SCHEMA:
+ query = String.format(queryTemp, "schema_id", entityId);
+ break;
+ case CATALOG:
+ query = String.format(queryTemp, "catalog_id", entityId);
+ break;
+ case METALAKE:
+ query = String.format(queryTemp, "metalake_id", entityId);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported entity type: " + entityType);
+ }
+
+ List<Pair<Long, Pair<Long, Long>>> results = Lists.newArrayList();
+ try (SqlSession sqlSession =
+ SqlSessionFactoryHelper.getInstance().getSqlSessionFactory().openSession(true)) {
+ Connection connection = sqlSession.getConnection();
+ Statement statement = connection.createStatement();
+
+ ResultSet rs = statement.executeQuery(query);
+ while (rs.next()) {
+ results.add(
+ Pair.of(
+ rs.getLong("column_id"),
+ Pair.of(rs.getLong("table_version"), rs.getLong("deleted_at"))));
+ }
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+
+ return results;
+ }
+
+ private void validateDeletedColumns(Long entityId, Entity.EntityType entityType) {
+ List<Pair<Long, Pair<Long, Long>>> deleteResult =
+ listAllColumnWithEntityId(entityId, entityType);
+ deleteResult.forEach(p -> Assertions.assertTrue(p.getRight().getRight() > 0));
+ }
+
@ParameterizedTest
@MethodSource("storageProvider")
void testOptimizedDeleteForKv(String type) throws IOException {
diff --git a/core/src/test/java/org/apache/gravitino/storage/relational/TestJDBCBackend.java b/core/src/test/java/org/apache/gravitino/storage/relational/TestJDBCBackend.java
index c67c9697a1..bb7586cde9 100644
--- a/core/src/test/java/org/apache/gravitino/storage/relational/TestJDBCBackend.java
+++ b/core/src/test/java/org/apache/gravitino/storage/relational/TestJDBCBackend.java
@@ -150,7 +150,7 @@ public class TestJDBCBackend {
private static void prepareJdbcTable() {
// Read the ddl sql to create table
- String scriptPath = "h2/schema-0.6.0-h2.sql";
+ String scriptPath = "h2/schema-0.7.0-h2.sql";
try (SqlSession sqlSession =
SqlSessionFactoryHelper.getInstance().getSqlSessionFactory().openSession(true);
Connection connection = sqlSession.getConnection();
diff --git a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestTableColumnMetaService.java b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestTableColumnMetaService.java
new file mode 100644
index 0000000000..0b15d1e0f5
--- /dev/null
+++ b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestTableColumnMetaService.java
@@ -0,0 +1,457 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.storage.relational.service;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.meta.AuditInfo;
+import org.apache.gravitino.meta.BaseMetalake;
+import org.apache.gravitino.meta.CatalogEntity;
+import org.apache.gravitino.meta.ColumnEntity;
+import org.apache.gravitino.meta.SchemaEntity;
+import org.apache.gravitino.meta.TableEntity;
+import org.apache.gravitino.rel.expressions.literals.Literals;
+import org.apache.gravitino.rel.types.Types;
+import org.apache.gravitino.storage.RandomIdGenerator;
+import org.apache.gravitino.storage.relational.TestJDBCBackend;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.shaded.com.google.common.collect.Lists;
+
+public class TestTableColumnMetaService extends TestJDBCBackend {
+
+ private static final String METALAKE_NAME = "metalake_for_table_column_test";
+
+ private final AuditInfo auditInfo =
+ AuditInfo.builder().withCreator("creator").withCreateTime(Instant.now()).build();
+
+ @Test
+ public void testInsertAndGetTableColumns() throws IOException {
+ String catalogName = "catalog1";
+ String schemaName = "schema1";
+ createParentEntities(METALAKE_NAME, catalogName, schemaName);
+
+ // Create a table entity without columns
+ TableEntity createdTable =
+ createTableEntity(
+ RandomIdGenerator.INSTANCE.nextId(),
+ Namespace.of(METALAKE_NAME, catalogName, schemaName),
+ "table1",
+ auditInfo);
+ TableMetaService.getInstance().insertTable(createdTable, false);
+
+ TableEntity retrievedTable =
+ TableMetaService.getInstance().getTableByIdentifier(createdTable.nameIdentifier());
+ Assertions.assertEquals(createdTable.id(), retrievedTable.id());
+ Assertions.assertEquals(createdTable.name(), retrievedTable.name());
+ Assertions.assertEquals(createdTable.namespace(), retrievedTable.namespace());
+ Assertions.assertEquals(createdTable.auditInfo(), retrievedTable.auditInfo());
+ Assertions.assertTrue(retrievedTable.columns().isEmpty());
+
+ // Create a table entity with columns
+ ColumnEntity column1 =
+ ColumnEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("column1")
+ .withComment("comment1")
+ .withDataType(Types.IntegerType.get())
+ .withNullable(true)
+ .withAutoIncrement(false)
+ .withDefaultValue(Literals.integerLiteral(1))
+ .withAuditInfo(auditInfo)
+ .build();
+ ColumnEntity column2 =
+ ColumnEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("column2")
+ .withComment("comment2")
+ .withDataType(Types.StringType.get())
+ .withNullable(false)
+ .withAutoIncrement(false)
+ .withDefaultValue(Literals.stringLiteral("1"))
+ .withAuditInfo(auditInfo)
+ .build();
+ TableEntity createdTable2 =
+ TableEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("table2")
+ .withNamespace(Namespace.of(METALAKE_NAME, catalogName, schemaName))
+ .withColumns(Lists.newArrayList(column1, column2))
+ .withAuditInfo(auditInfo)
+ .build();
+ TableMetaService.getInstance().insertTable(createdTable2, false);
+
+ TableEntity retrievedTable2 =
+ TableMetaService.getInstance().getTableByIdentifier(createdTable2.nameIdentifier());
+ Assertions.assertEquals(createdTable2.id(), retrievedTable2.id());
+ Assertions.assertEquals(createdTable2.name(), retrievedTable2.name());
+ Assertions.assertEquals(createdTable2.namespace(), retrievedTable2.namespace());
+ Assertions.assertEquals(createdTable2.auditInfo(), retrievedTable2.auditInfo());
+ Assertions.assertEquals(createdTable2.columns().size(), retrievedTable2.columns().size());
+ compareTwoColumns(createdTable2.columns(), retrievedTable2.columns());
+
+ // test insert with overwrite
+ ColumnEntity column3 =
+ ColumnEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("column3")
+ .withComment("comment3")
+ .withDataType(Types.IntegerType.get())
+ .withNullable(true)
+ .withAutoIncrement(false)
+ .withDefaultValue(Literals.integerLiteral(1))
+ .withAuditInfo(auditInfo)
+ .build();
+
+ TableEntity createdTable3 =
+ TableEntity.builder()
+ .withId(createdTable2.id())
+ .withName("table3")
+ .withNamespace(Namespace.of(METALAKE_NAME, catalogName, schemaName))
+ .withColumns(Lists.newArrayList(column3))
+ .withAuditInfo(auditInfo)
+ .build();
+
+ TableMetaService.getInstance().insertTable(createdTable3, true);
+ TableEntity retrievedTable3 =
+ TableMetaService.getInstance().getTableByIdentifier(createdTable3.nameIdentifier());
+ Assertions.assertEquals(createdTable3.id(), retrievedTable3.id());
+ Assertions.assertEquals(createdTable3.name(), retrievedTable3.name());
+ Assertions.assertEquals(createdTable3.namespace(), retrievedTable3.namespace());
+ Assertions.assertEquals(createdTable3.auditInfo(), retrievedTable3.auditInfo());
+ Assertions.assertEquals(createdTable3.columns().size(), retrievedTable3.columns().size());
+ compareTwoColumns(createdTable3.columns(), retrievedTable3.columns());
+ }
+
+ @Test
+ public void testUpdateTable() throws IOException {
+ String catalogName = "catalog1";
+ String schemaName = "schema1";
+ createParentEntities(METALAKE_NAME, catalogName, schemaName);
+
+ // Create a table entity without columns
+ TableEntity createdTable =
+ createTableEntity(
+ RandomIdGenerator.INSTANCE.nextId(),
+ Namespace.of(METALAKE_NAME, catalogName, schemaName),
+ "table1",
+ auditInfo);
+ TableMetaService.getInstance().insertTable(createdTable, false);
+
+ // Test update table with new name
+ TableEntity updatedTable =
+ TableEntity.builder()
+ .withId(createdTable.id())
+ .withName("table2")
+ .withNamespace(createdTable.namespace())
+ .withColumns(createdTable.columns())
+ .withAuditInfo(auditInfo)
+ .build();
+ Function<TableEntity, TableEntity> updater = oldTable -> updatedTable;
+
+ TableMetaService.getInstance().updateTable(createdTable.nameIdentifier(), updater);
+ TableEntity retrievedTable =
+ TableMetaService.getInstance().getTableByIdentifier(updatedTable.nameIdentifier());
+
+ Assertions.assertEquals(updatedTable.id(), retrievedTable.id());
+ Assertions.assertEquals(updatedTable.name(), retrievedTable.name());
+ Assertions.assertEquals(updatedTable.namespace(), retrievedTable.namespace());
+ Assertions.assertEquals(updatedTable.auditInfo(), retrievedTable.auditInfo());
+ Assertions.assertTrue(retrievedTable.columns().isEmpty());
+
+ // Test update table with adding one new column
+ ColumnEntity column1 =
+ ColumnEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("column1")
+ .withComment("comment1")
+ .withDataType(Types.IntegerType.get())
+ .withNullable(true)
+ .withAutoIncrement(false)
+ .withDefaultValue(Literals.integerLiteral(1))
+ .withAuditInfo(auditInfo)
+ .build();
+
+ TableEntity updatedTable2 =
+ TableEntity.builder()
+ .withId(updatedTable.id())
+ .withName(updatedTable.name())
+ .withNamespace(updatedTable.namespace())
+ .withColumns(Lists.newArrayList(column1))
+ .withAuditInfo(auditInfo)
+ .build();
+
+ Function<TableEntity, TableEntity> updater2 = oldTable -> updatedTable2;
+ TableMetaService.getInstance().updateTable(updatedTable.nameIdentifier(), updater2);
+
+ TableEntity retrievedTable2 =
+ TableMetaService.getInstance().getTableByIdentifier(updatedTable2.nameIdentifier());
+
+ Assertions.assertEquals(updatedTable2.id(), retrievedTable2.id());
+ Assertions.assertEquals(updatedTable2.name(), retrievedTable2.name());
+ Assertions.assertEquals(updatedTable2.namespace(), retrievedTable2.namespace());
+ Assertions.assertEquals(updatedTable2.auditInfo(), retrievedTable2.auditInfo());
+ Assertions.assertEquals(updatedTable2.columns().size(), retrievedTable2.columns().size());
+ compareTwoColumns(updatedTable2.columns(), retrievedTable2.columns());
+
+ // Update the table with add one more column
+ ColumnEntity column2 =
+ ColumnEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("column2")
+ .withComment("comment2")
+ .withDataType(Types.StringType.get())
+ .withNullable(false)
+ .withAutoIncrement(false)
+ .withDefaultValue(Literals.stringLiteral("1"))
+ .withAuditInfo(auditInfo)
+ .build();
+
+ TableEntity updatedTable3 =
+ TableEntity.builder()
+ .withId(updatedTable2.id())
+ .withName(updatedTable2.name())
+ .withNamespace(updatedTable2.namespace())
+ .withColumns(Lists.newArrayList(column1, column2))
+ .withAuditInfo(auditInfo)
+ .build();
+
+ Function<TableEntity, TableEntity> updater3 = oldTable -> updatedTable3;
+ TableMetaService.getInstance().updateTable(updatedTable2.nameIdentifier(), updater3);
+
+ TableEntity retrievedTable3 =
+ TableMetaService.getInstance().getTableByIdentifier(updatedTable3.nameIdentifier());
+
+ Assertions.assertEquals(updatedTable3.id(), retrievedTable3.id());
+ Assertions.assertEquals(updatedTable3.name(), retrievedTable3.name());
+ Assertions.assertEquals(updatedTable3.namespace(), retrievedTable3.namespace());
+ Assertions.assertEquals(updatedTable3.auditInfo(), retrievedTable3.auditInfo());
+ Assertions.assertEquals(updatedTable3.columns().size(), retrievedTable3.columns().size());
+ compareTwoColumns(updatedTable3.columns(), retrievedTable3.columns());
+
+ // Update the table with updating one column
+ ColumnEntity updatedColumn1 =
+ ColumnEntity.builder()
+ .withId(column1.id())
+ .withName(column1.name())
+ .withComment("comment1_updated")
+ .withDataType(Types.LongType.get())
+ .withNullable(column1.nullable())
+ .withAutoIncrement(column1.autoIncrement())
+ .withDefaultValue(null)
+ .withAuditInfo(auditInfo)
+ .build();
+ TableEntity updatedTable4 =
+ TableEntity.builder()
+ .withId(updatedTable3.id())
+ .withName(updatedTable3.name())
+ .withNamespace(updatedTable3.namespace())
+ .withColumns(Lists.newArrayList(updatedColumn1, column2))
+ .withAuditInfo(auditInfo)
+ .build();
+
+ Function<TableEntity, TableEntity> updater4 = oldTable -> updatedTable4;
+ TableMetaService.getInstance().updateTable(updatedTable3.nameIdentifier(), updater4);
+
+ TableEntity retrievedTable4 =
+ TableMetaService.getInstance().getTableByIdentifier(updatedTable4.nameIdentifier());
+
+ Assertions.assertEquals(updatedTable4.id(), retrievedTable4.id());
+ Assertions.assertEquals(updatedTable4.name(), retrievedTable4.name());
+ Assertions.assertEquals(updatedTable4.namespace(), retrievedTable4.namespace());
+ Assertions.assertEquals(updatedTable4.auditInfo(), retrievedTable4.auditInfo());
+ Assertions.assertEquals(updatedTable4.columns().size(), retrievedTable4.columns().size());
+ compareTwoColumns(updatedTable4.columns(), retrievedTable4.columns());
+
+ // Update the table with removing one column
+ TableEntity updatedTable5 =
+ TableEntity.builder()
+ .withId(updatedTable4.id())
+ .withName(updatedTable4.name())
+ .withNamespace(updatedTable4.namespace())
+ .withColumns(Lists.newArrayList(column2))
+ .withAuditInfo(auditInfo)
+ .build();
+
+ Function<TableEntity, TableEntity> updater5 = oldTable -> updatedTable5;
+ TableMetaService.getInstance().updateTable(updatedTable4.nameIdentifier(), updater5);
+
+ TableEntity retrievedTable5 =
+ TableMetaService.getInstance().getTableByIdentifier(updatedTable5.nameIdentifier());
+ compareTwoColumns(updatedTable5.columns(), retrievedTable5.columns());
+
+ // update the table with removing all columns
+ TableEntity updatedTable6 =
+ TableEntity.builder()
+ .withId(updatedTable5.id())
+ .withName(updatedTable5.name())
+ .withNamespace(updatedTable5.namespace())
+ .withAuditInfo(auditInfo)
+ .build();
+
+ Function<TableEntity, TableEntity> updater6 = oldTable -> updatedTable6;
+ TableMetaService.getInstance().updateTable(updatedTable5.nameIdentifier(), updater6);
+
+ TableEntity retrievedTable6 =
+ TableMetaService.getInstance().getTableByIdentifier(updatedTable6.nameIdentifier());
+ Assertions.assertTrue(retrievedTable6.columns().isEmpty());
+ }
+
+ @Test
+ public void testCreateAndDeleteTable() throws IOException {
+ String catalogName = "catalog1";
+ String schemaName = "schema1";
+ createParentEntities(METALAKE_NAME, catalogName, schemaName);
+
+ // Create a table entity with column
+ ColumnEntity column =
+ ColumnEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("column1")
+ .withComment("comment1")
+ .withDataType(Types.IntegerType.get())
+ .withNullable(true)
+ .withAutoIncrement(false)
+ .withDefaultValue(Literals.integerLiteral(1))
+ .withAuditInfo(auditInfo)
+ .build();
+
+ TableEntity createdTable =
+ TableEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("table1")
+ .withNamespace(Namespace.of(METALAKE_NAME, catalogName, schemaName))
+ .withColumns(Lists.newArrayList(column))
+ .withAuditInfo(auditInfo)
+ .build();
+
+ TableMetaService.getInstance().insertTable(createdTable, false);
+
+ TableEntity retrievedTable =
+ TableMetaService.getInstance().getTableByIdentifier(createdTable.nameIdentifier());
+ Assertions.assertEquals(createdTable.id(), retrievedTable.id());
+ Assertions.assertEquals(createdTable.name(), retrievedTable.name());
+ Assertions.assertEquals(createdTable.namespace(), retrievedTable.namespace());
+ Assertions.assertEquals(createdTable.auditInfo(), retrievedTable.auditInfo());
+ compareTwoColumns(createdTable.columns(), retrievedTable.columns());
+
+ Assertions.assertTrue(
+ TableMetaService.getInstance().deleteTable(retrievedTable.nameIdentifier()));
+
+ Assertions.assertThrows(
+ NoSuchEntityException.class,
+ () -> TableMetaService.getInstance().getTableByIdentifier(retrievedTable.nameIdentifier()));
+ }
+
+ @Test
+ public void testDeleteMetalake() throws IOException {
+ String catalogName = "catalog1";
+ String schemaName = "schema1";
+ createParentEntities(METALAKE_NAME, catalogName, schemaName);
+
+ // Create a table entity with column
+ ColumnEntity column =
+ ColumnEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("column1")
+ .withComment("comment1")
+ .withDataType(Types.IntegerType.get())
+ .withNullable(true)
+ .withAutoIncrement(false)
+ .withDefaultValue(Literals.integerLiteral(1))
+ .withAuditInfo(auditInfo)
+ .build();
+
+ TableEntity createdTable =
+ TableEntity.builder()
+ .withId(RandomIdGenerator.INSTANCE.nextId())
+ .withName("table1")
+ .withNamespace(Namespace.of(METALAKE_NAME, catalogName, schemaName))
+ .withColumns(Lists.newArrayList(column))
+ .withAuditInfo(auditInfo)
+ .build();
+
+ TableMetaService.getInstance().insertTable(createdTable, false);
+
+ TableEntity retrievedTable =
+ TableMetaService.getInstance().getTableByIdentifier(createdTable.nameIdentifier());
+ Assertions.assertEquals(createdTable.id(), retrievedTable.id());
+ Assertions.assertEquals(createdTable.name(), retrievedTable.name());
+ Assertions.assertEquals(createdTable.namespace(), retrievedTable.namespace());
+ Assertions.assertEquals(createdTable.auditInfo(), retrievedTable.auditInfo());
+ compareTwoColumns(createdTable.columns(), retrievedTable.columns());
+
+ Assertions.assertTrue(
+ MetalakeMetaService.getInstance().deleteMetalake(NameIdentifier.of(METALAKE_NAME), true));
+
+ Assertions.assertThrows(
+ NoSuchEntityException.class,
+ () -> TableMetaService.getInstance().getTableByIdentifier(retrievedTable.nameIdentifier()));
+ }
+
+ private void compareTwoColumns(
+ List<ColumnEntity> expectedColumns, List<ColumnEntity> actualColumns) {
+ Assertions.assertEquals(expectedColumns.size(), actualColumns.size());
+ Map<String, ColumnEntity> expectedColumnsMap =
+ expectedColumns.stream().collect(Collectors.toMap(ColumnEntity::name, Function.identity()));
+ actualColumns.forEach(
+ column -> {
+ ColumnEntity expectedColumn = expectedColumnsMap.get(column.name());
+ Assertions.assertNotNull(expectedColumn);
+ Assertions.assertEquals(expectedColumn.id(), column.id());
+ Assertions.assertEquals(expectedColumn.name(), column.name());
+ Assertions.assertEquals(expectedColumn.comment(), column.comment());
+ Assertions.assertEquals(expectedColumn.dataType(), column.dataType());
+ Assertions.assertEquals(expectedColumn.nullable(), column.nullable());
+ Assertions.assertEquals(expectedColumn.autoIncrement(), column.autoIncrement());
+ Assertions.assertEquals(expectedColumn.defaultValue(), column.defaultValue());
+ Assertions.assertEquals(expectedColumn.auditInfo(), column.auditInfo());
+ });
+ }
+
+ private void createParentEntities(String metalakeName, String catalogName, String schemaName)
+ throws IOException {
+ BaseMetalake metalake =
+ createBaseMakeLake(RandomIdGenerator.INSTANCE.nextId(), metalakeName, auditInfo);
+ backend.insert(metalake, false);
+
+ CatalogEntity catalog =
+ createCatalog(
+ RandomIdGenerator.INSTANCE.nextId(),
+ Namespace.of(metalakeName),
+ catalogName,
+ auditInfo);
+ backend.insert(catalog, false);
+
+ SchemaEntity schema =
+ createSchemaEntity(
+ RandomIdGenerator.INSTANCE.nextId(),
+ Namespace.of(metalakeName, catalog.name()),
+ schemaName,
+ auditInfo);
+ backend.insert(schema, false);
+ }
+}
diff --git a/core/src/test/java/org/apache/gravitino/storage/relational/utils/TestPOConverters.java b/core/src/test/java/org/apache/gravitino/storage/relational/utils/TestPOConverters.java
index 3f92aafdfd..e97e650a14 100644
--- a/core/src/test/java/org/apache/gravitino/storage/relational/utils/TestPOConverters.java
+++ b/core/src/test/java/org/apache/gravitino/storage/relational/utils/TestPOConverters.java
@@ -24,11 +24,13 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -36,18 +38,25 @@ import org.apache.gravitino.Catalog;
import org.apache.gravitino.Entity;
import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.Namespace;
+import org.apache.gravitino.dto.util.DTOConverters;
import org.apache.gravitino.file.Fileset;
import org.apache.gravitino.json.JsonUtils;
import org.apache.gravitino.meta.AuditInfo;
import org.apache.gravitino.meta.BaseMetalake;
import org.apache.gravitino.meta.CatalogEntity;
+import org.apache.gravitino.meta.ColumnEntity;
import org.apache.gravitino.meta.FilesetEntity;
import org.apache.gravitino.meta.SchemaEntity;
import org.apache.gravitino.meta.SchemaVersion;
import org.apache.gravitino.meta.TableEntity;
import org.apache.gravitino.meta.TagEntity;
import org.apache.gravitino.meta.TopicEntity;
+import org.apache.gravitino.rel.expressions.Expression;
+import org.apache.gravitino.rel.expressions.literals.Literals;
+import org.apache.gravitino.rel.types.Type;
+import org.apache.gravitino.rel.types.Types;
import org.apache.gravitino.storage.relational.po.CatalogPO;
+import org.apache.gravitino.storage.relational.po.ColumnPO;
import org.apache.gravitino.storage.relational.po.FilesetPO;
import org.apache.gravitino.storage.relational.po.FilesetVersionPO;
import org.apache.gravitino.storage.relational.po.MetalakePO;
@@ -145,6 +154,122 @@ public class TestPOConverters {
assertEquals(expectedTable.auditInfo().creator(), convertedTable.auditInfo().creator());
}
+ @Test
+ public void testFromColumnPO() throws JsonProcessingException {
+ ColumnPO columnPO =
+ createColumnPO(
+ 1L,
+ "test",
+ 1L,
+ 1L,
+ 1L,
+ 1L,
+ Types.IntegerType.get(),
+ "test",
+ true,
+ true,
+ Literals.integerLiteral(1),
+ ColumnPO.ColumnOpType.CREATE);
+
+ ColumnEntity expectedColumn =
+ createColumn(
+ 1L, "test", Types.IntegerType.get(), "test", true, true, Literals.integerLiteral(1));
+
+ ColumnEntity convertedColumn = POConverters.fromColumnPO(columnPO);
+ assertEquals(expectedColumn.id(), convertedColumn.id());
+ assertEquals(expectedColumn.name(), convertedColumn.name());
+ assertEquals(expectedColumn.dataType(), convertedColumn.dataType());
+ assertEquals(expectedColumn.comment(), convertedColumn.comment());
+ assertEquals(expectedColumn.nullable(), convertedColumn.nullable());
+ assertEquals(expectedColumn.autoIncrement(), convertedColumn.autoIncrement());
+ assertEquals(expectedColumn.defaultValue(), convertedColumn.defaultValue());
+
+ // Test column comment is null
+ ColumnPO columnPO1 =
+ createColumnPO(
+ 1L,
+ "test",
+ 1L,
+ 1L,
+ 1L,
+ 1L,
+ Types.IntegerType.get(),
+ null,
+ true,
+ true,
+ Literals.integerLiteral(1),
+ ColumnPO.ColumnOpType.CREATE);
+
+ ColumnEntity expectedColumn1 =
+ createColumn(
+ 1L, "test", Types.IntegerType.get(), null, true, true, Literals.integerLiteral(1));
+
+ ColumnEntity convertedColumn1 = POConverters.fromColumnPO(columnPO1);
+ assertEquals(expectedColumn1.comment(), convertedColumn1.comment());
+ }
+
+ @Test
+ public void testFromTableColumnPOs() throws JsonProcessingException {
+ TablePO tablePO = createTablePO(1L, "test", 1L, 1L, 1L);
+ ColumnPO columnPO1 =
+ createColumnPO(
+ 1L,
+ "test1",
+ 1L,
+ 1L,
+ 1L,
+ 1L,
+ Types.IntegerType.get(),
+ "test1",
+ true,
+ true,
+ Literals.integerLiteral(1),
+ ColumnPO.ColumnOpType.CREATE);
+
+ ColumnPO columnPO2 =
+ createColumnPO(
+ 2L,
+ "test2",
+ 1L,
+ 1L,
+ 1L,
+ 1L,
+ Types.StringType.get(),
+ "test2",
+ true,
+ true,
+ Literals.stringLiteral("1"),
+ ColumnPO.ColumnOpType.CREATE);
+
+ ColumnEntity expectedColumn1 =
+ createColumn(
+ 1L, "test1", Types.IntegerType.get(), "test1", true, true, Literals.integerLiteral(1));
+
+ ColumnEntity expectedColumn2 =
+ createColumn(
+ 2L, "test2", Types.StringType.get(), "test2", true, true, Literals.stringLiteral("1"));
+
+ TableEntity expectedTable =
+ createTableWithColumns(
+ 1L,
+ "test",
+ NamespaceUtil.ofTable("test_metalake", "test_catalog", "test_schema"),
+ Lists.newArrayList(expectedColumn1, expectedColumn2));
+
+ TableEntity convertedTable =
+ POConverters.fromTableAndColumnPOs(
+ tablePO,
+ Lists.newArrayList(columnPO1, columnPO2),
+ NamespaceUtil.ofTable("test_metalake", "test_catalog", "test_schema"));
+
+ assertEquals(expectedTable.id(), convertedTable.id());
+ assertEquals(expectedTable.name(), convertedTable.name());
+ assertEquals(expectedTable.namespace(), convertedTable.namespace());
+ assertEquals(expectedTable.auditInfo().creator(), convertedTable.auditInfo().creator());
+ assertEquals(expectedTable.columns().size(), convertedTable.columns().size());
+ assertEquals(expectedTable.columns(), convertedTable.columns());
+ }
+
@Test
public void testFromFilesetPO() throws JsonProcessingException {
FilesetVersionPO filesetVersionPO =
@@ -527,7 +652,7 @@ public class TestPOConverters {
TablePO.Builder builder =
TablePO.builder().withMetalakeId(1L).withCatalogId(1L).withSchemaId(1L);
TablePO initPO = POConverters.initializeTablePOWithVersion(tableEntity, builder);
- TablePO updatePO = POConverters.updateTablePOWithVersion(initPO, updatedTable);
+ TablePO updatePO = POConverters.updateTablePOWithVersion(initPO, updatedTable, false);
assertEquals(1, initPO.getCurrentVersion());
assertEquals(1, initPO.getLastVersion());
assertEquals(0, initPO.getDeletedAt());
@@ -800,26 +925,18 @@ public class TestPOConverters {
}
private static TableEntity createTable(Long id, String name, Namespace namespace) {
- AuditInfo auditInfo =
- AuditInfo.builder().withCreator("creator").withCreateTime(FIX_INSTANT).build();
- return TableEntity.builder()
- .withId(id)
- .withName(name)
- .withNamespace(namespace)
- .withAuditInfo(auditInfo)
- .build();
+ return createTableWithColumns(id, name, namespace, Collections.emptyList());
}
- private static TopicEntity createTopic(
- Long id, String name, Namespace namespace, String comment, Map<String, String> properties) {
+ private static TableEntity createTableWithColumns(
+ Long id, String name, Namespace namespace, List<ColumnEntity> columns) {
AuditInfo auditInfo =
AuditInfo.builder().withCreator("creator").withCreateTime(FIX_INSTANT).build();
- return TopicEntity.builder()
+ return TableEntity.builder()
.withId(id)
.withName(name)
.withNamespace(namespace)
- .withComment(comment)
- .withProperties(properties)
+ .withColumns(columns)
.withAuditInfo(auditInfo)
.build();
}
@@ -842,6 +959,79 @@ public class TestPOConverters {
.build();
}
+ private static ColumnPO createColumnPO(
+ Long id,
+ String columnName,
+ Long metalakeId,
+ Long catalogId,
+ Long schemaId,
+ Long tableId,
+ Type columnType,
+ String columnComment,
+ boolean columnNullable,
+ boolean columnAutoIncrement,
+ Expression columnDefaultValue,
+ ColumnPO.ColumnOpType columnOpType)
+ throws JsonProcessingException {
+ AuditInfo auditInfo =
+ AuditInfo.builder().withCreator("creator").withCreateTime(FIX_INSTANT).build();
+ return ColumnPO.builder()
+ .withColumnId(id)
+ .withColumnName(columnName)
+ .withMetalakeId(metalakeId)
+ .withCatalogId(catalogId)
+ .withSchemaId(schemaId)
+ .withTableId(tableId)
+ .withTableVersion(1L)
+ .withColumnType(JsonUtils.anyFieldMapper().writeValueAsString(columnType))
+ .withColumnComment(columnComment)
+ .withNullable(ColumnPO.Nullable.fromBoolean(columnNullable).value())
+ .withAutoIncrement(ColumnPO.AutoIncrement.fromBoolean(columnAutoIncrement).value())
+ .withDefaultValue(
+ JsonUtils.anyFieldMapper()
+ .writeValueAsString(DTOConverters.toFunctionArg(columnDefaultValue)))
+ .withColumnOpType(columnOpType.value())
+ .withAuditInfo(JsonUtils.anyFieldMapper().writeValueAsString(auditInfo))
+ .withDeletedAt(0L)
+ .build();
+ }
+
+ private static ColumnEntity createColumn(
+ Long id,
+ String columnName,
+ Type columnType,
+ String columnComment,
+ boolean columnNullable,
+ boolean columnAutoIncrement,
+ Expression columnDefaultValue) {
+ AuditInfo auditInfo =
+ AuditInfo.builder().withCreator("creator").withCreateTime(FIX_INSTANT).build();
+ return ColumnEntity.builder()
+ .withId(id)
+ .withName(columnName)
+ .withDataType(columnType)
+ .withComment(columnComment)
+ .withNullable(columnNullable)
+ .withAutoIncrement(columnAutoIncrement)
+ .withDefaultValue(columnDefaultValue)
+ .withAuditInfo(auditInfo)
+ .build();
+ }
+
+ private static TopicEntity createTopic(
+ Long id, String name, Namespace namespace, String comment, Map<String, String> properties) {
+ AuditInfo auditInfo =
+ AuditInfo.builder().withCreator("creator").withCreateTime(FIX_INSTANT).build();
+ return TopicEntity.builder()
+ .withId(id)
+ .withName(name)
+ .withNamespace(namespace)
+ .withComment(comment)
+ .withProperties(properties)
+ .withAuditInfo(auditInfo)
+ .build();
+ }
+
private static TopicPO createTopicPO(
Long id,
String name,
diff --git a/integration-test-common/src/test/java/org/apache/gravitino/integration/test/util/AbstractIT.java b/integration-test-common/src/test/java/org/apache/gravitino/integration/test/util/AbstractIT.java
index 0ef754d5ef..ede6b7be28 100644
--- a/integration-test-common/src/test/java/org/apache/gravitino/integration/test/util/AbstractIT.java
+++ b/integration-test-common/src/test/java/org/apache/gravitino/integration/test/util/AbstractIT.java
@@ -228,7 +228,7 @@ public class AbstractIT {
new File(
gravitinoHome
+ String.format(
- "/scripts/mysql/schema-%s-mysql.sql", ConfigConstants.VERSION_0_6_0)),
+ "/scripts/mysql/schema-%s-mysql.sql", ConfigConstants.VERSION_0_7_0)),
"UTF-8");
String[] initMySQLBackendSqls =
diff --git a/scripts/h2/schema-0.7.0-h2.sql b/scripts/h2/schema-0.7.0-h2.sql
new file mode 100644
index 0000000000..8a76f1e6a1
--- /dev/null
+++ b/scripts/h2/schema-0.7.0-h2.sql
@@ -0,0 +1,290 @@
+--
+-- 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.
+--
+
+CREATE TABLE IF NOT EXISTS `metalake_meta` (
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `metalake_name` VARCHAR(128) NOT NULL COMMENT 'metalake name',
+ `metalake_comment` VARCHAR(256) DEFAULT '' COMMENT 'metalake comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'metalake properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'metalake audit info',
+ `schema_version` MEDIUMTEXT NOT NULL COMMENT 'metalake schema version info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'metalake current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'metalake last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'metalake deleted at',
+ PRIMARY KEY (metalake_id),
+ CONSTRAINT uk_mn_del UNIQUE (metalake_name, deleted_at)
+) ENGINE = InnoDB;
+
+
+CREATE TABLE IF NOT EXISTS `catalog_meta` (
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `catalog_name` VARCHAR(128) NOT NULL COMMENT 'catalog name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `type` VARCHAR(64) NOT NULL COMMENT 'catalog type',
+ `provider` VARCHAR(64) NOT NULL COMMENT 'catalog provider',
+ `catalog_comment` VARCHAR(256) DEFAULT '' COMMENT 'catalog comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'catalog properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'catalog audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'catalog current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'catalog last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'catalog deleted at',
+ PRIMARY KEY (catalog_id),
+ CONSTRAINT uk_mid_cn_del UNIQUE (metalake_id, catalog_name, deleted_at)
+) ENGINE=InnoDB;
+
+
+CREATE TABLE IF NOT EXISTS `schema_meta` (
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `schema_name` VARCHAR(128) NOT NULL COMMENT 'schema name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_comment` VARCHAR(256) DEFAULT '' COMMENT 'schema comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'schema properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'schema audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'schema current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'schema last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'schema deleted at',
+ PRIMARY KEY (schema_id),
+ CONSTRAINT uk_cid_sn_del UNIQUE (catalog_id, schema_name, deleted_at),
+ -- Aliases are used here, and indexes with the same name in H2 can only be created once.
+ KEY idx_smid (metalake_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `table_meta` (
+ `table_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'table id',
+ `table_name` VARCHAR(128) NOT NULL COMMENT 'table name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'table audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'table current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'table last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'table deleted at',
+ PRIMARY KEY (table_id),
+ CONSTRAINT uk_sid_tn_del UNIQUE (schema_id, table_name, deleted_at),
+ -- Aliases are used here, and indexes with the same name in H2 can only be created once.
+ KEY idx_tmid (metalake_id),
+ KEY idx_tcid (catalog_id)
+) ENGINE=InnoDB;
+
+
+CREATE TABLE IF NOT EXISTS `table_column_version_info` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `table_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'table id',
+ `table_version` INT UNSIGNED NOT NULL COMMENT 'table version',
+ `column_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'column id',
+ `column_name` VARCHAR(128) NOT NULL COMMENT 'column name',
+ `column_type` VARCHAR(128) NOT NULL COMMENT 'column type',
+ `column_comment` VARCHAR(256) DEFAULT '' COMMENT 'column comment',
+ `column_nullable` TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'column nullable, 0 is not nullable, 1 is nullable',
+ `column_auto_increment` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'column auto increment, 0 is not auto increment, 1 is auto increment',
+ `column_default_value` VARCHAR(256) DEFAULT NULL COMMENT 'column default value',
+ `column_op_type` TINYINT(1) NOT NULL COMMENT 'column operation type, 1 is create, 2 is update, 3 is delete',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'column deleted at',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'column audit info',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_tid_ver_cid_del` (`table_id`, `table_version`, `column_id`, `deleted_at`),
+ KEY `idx_tcmid` (`metalake_id`),
+ KEY `idx_tccid` (`catalog_id`),
+ KEY `idx_tcsid` (`schema_id`)
+) ENGINE=InnoDB;
+
+
+CREATE TABLE IF NOT EXISTS `fileset_meta` (
+ `fileset_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'fileset id',
+ `fileset_name` VARCHAR(128) NOT NULL COMMENT 'fileset name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `type` VARCHAR(64) NOT NULL COMMENT 'fileset type',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'fileset audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'fileset current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'fileset last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'fileset deleted at',
+ PRIMARY KEY (fileset_id),
+ CONSTRAINT uk_sid_fn_del UNIQUE (schema_id, fileset_name, deleted_at),
+ -- Aliases are used here, and indexes with the same name in H2 can only be created once.
+ KEY idx_fmid (metalake_id),
+ KEY idx_fcid (catalog_id)
+) ENGINE=InnoDB;
+
+
+CREATE TABLE IF NOT EXISTS `fileset_version_info` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `fileset_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'fileset id',
+ `version` INT UNSIGNED NOT NULL COMMENT 'fileset info version',
+ `fileset_comment` VARCHAR(256) DEFAULT '' COMMENT 'fileset comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'fileset properties',
+ `storage_location` MEDIUMTEXT DEFAULT NULL COMMENT 'fileset storage location',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'fileset deleted at',
+ PRIMARY KEY (id),
+ CONSTRAINT uk_fid_ver_del UNIQUE (fileset_id, version, deleted_at),
+ -- Aliases are used here, and indexes with the same name in H2 can only be created once.
+ KEY idx_fvmid (metalake_id),
+ KEY idx_fvcid (catalog_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `topic_meta` (
+ `topic_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'topic id',
+ `topic_name` VARCHAR(128) NOT NULL COMMENT 'topic name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `comment` VARCHAR(256) DEFAULT '' COMMENT 'topic comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'topic properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'topic audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'topic current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'topic last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'topic deleted at',
+ PRIMARY KEY (topic_id),
+ CONSTRAINT uk_cid_tn_del UNIQUE (schema_id, topic_name, deleted_at),
+ -- Aliases are used here, and indexes with the same name in H2 can only be created once.
+ KEY idx_tvmid (metalake_id),
+ KEY idx_tvcid (catalog_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `user_meta` (
+ `user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'user id',
+ `user_name` VARCHAR(128) NOT NULL COMMENT 'username',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'user audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'user current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'user last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'user deleted at',
+ PRIMARY KEY (`user_id`),
+ CONSTRAINT `uk_mid_us_del` UNIQUE (`metalake_id`, `user_name`, `deleted_at`)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `role_meta` (
+ `role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
+ `role_name` VARCHAR(128) NOT NULL COMMENT 'role name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'schema properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'role audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'role current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'role last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'role deleted at',
+ PRIMARY KEY (`role_id`),
+ CONSTRAINT `uk_mid_rn_del` UNIQUE (`metalake_id`, `role_name`, `deleted_at`)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `role_meta_securable_object` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
+ `metadata_object_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'securable object entity id',
+ `type` VARCHAR(128) NOT NULL COMMENT 'securable object type',
+ `privilege_names` VARCHAR(256) NOT NULL COMMENT 'securable object privilege names',
+ `privilege_conditions` VARCHAR(256) NOT NULL COMMENT 'securable object privilege conditions',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'securable objectcurrent version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'securable object last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'securable object deleted at',
+ PRIMARY KEY (`id`),
+ KEY `idx_obj_rid` (`role_id`),
+ KEY `idx_obj_eid` (`metadata_object_id`)
+ ) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `user_role_rel` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'user id',
+ `role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'relation audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'relation current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'relation last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'relation deleted at',
+ PRIMARY KEY (`id`),
+ CONSTRAINT `uk_ui_ri_del` UNIQUE (`user_id`, `role_id`, `deleted_at`),
+ KEY `idx_rid` (`role_id`)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `group_meta` (
+ `group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'group id',
+ `group_name` VARCHAR(128) NOT NULL COMMENT 'group name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'group audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'group current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'group last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'group deleted at',
+ PRIMARY KEY (`group_id`),
+ CONSTRAINT `uk_mid_gr_del` UNIQUE (`metalake_id`, `group_name`, `deleted_at`)
+ ) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `group_role_rel` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'group id',
+ `role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'relation audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'relation current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'relation last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'relation deleted at',
+ PRIMARY KEY (`id`),
+ CONSTRAINT `uk_gi_ri_del` UNIQUE (`group_id`, `role_id`, `deleted_at`),
+ KEY `idx_gid` (`group_id`)
+ ) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `tag_meta` (
+ `tag_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'tag id',
+ `tag_name` VARCHAR(128) NOT NULL COMMENT 'tag name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `tag_comment` VARCHAR(256) DEFAULT '' COMMENT 'tag comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'tag properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'tag audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'tag current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'tag last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'tag deleted at',
+ PRIMARY KEY (`tag_id`),
+ UNIQUE KEY `uk_mn_tn_del` (`metalake_id`, `tag_name`, `deleted_at`)
+ ) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `tag_relation_meta` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `tag_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'tag id',
+ `metadata_object_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metadata object id',
+ `metadata_object_type` VARCHAR(64) NOT NULL COMMENT 'metadata object type',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'tag relation audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'tag relation current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'tag relation last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'tag relation deleted at',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_ti_mi_del` (`tag_id`, `metadata_object_id`, `deleted_at`),
+ KEY `idx_tid` (`tag_id`),
+ KEY `idx_mid` (`metadata_object_id`)
+ ) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `owner_meta` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `owner_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'owner id',
+ `owner_type` VARCHAR(64) NOT NULL COMMENT 'owner type',
+ `metadata_object_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metadata object id',
+ `metadata_object_type` VARCHAR(64) NOT NULL COMMENT 'metadata object type',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'owner relation audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'owner relation current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'owner relation last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'owner relation deleted at',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_ow_me_del` (`owner_id`, `metadata_object_id`, `metadata_object_type`, `deleted_at`),
+ KEY `idx_oid` (`owner_id`),
+ KEY `idx_meid` (`metadata_object_id`)
+ ) ENGINE=InnoDB;
diff --git a/scripts/h2/upgrade-0.6.0-to-0.7.0-h2.sql b/scripts/h2/upgrade-0.6.0-to-0.7.0-h2.sql
new file mode 100644
index 0000000000..fba1075f56
--- /dev/null
+++ b/scripts/h2/upgrade-0.6.0-to-0.7.0-h2.sql
@@ -0,0 +1,41 @@
+--
+-- 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.
+--
+CREATE TABLE IF NOT EXISTS `table_column_version_info` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `table_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'table id',
+ `table_version` INT UNSIGNED NOT NULL COMMENT 'table version',
+ `column_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'column id',
+ `column_name` VARCHAR(128) NOT NULL COMMENT 'column name',
+ `column_type` VARCHAR(128) NOT NULL COMMENT 'column type',
+ `column_comment` VARCHAR(256) DEFAULT '' COMMENT 'column comment',
+ `column_nullable` TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'column nullable, 0 is not nullable, 1 is nullable',
+ `column_auto_increment` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'column auto increment, 0 is not auto increment, 1 is auto increment',
+ `column_default_value` VARCHAR(256) DEFAULT NULL COMMENT 'column default value',
+ `column_op_type` TINYINT(1) NOT NULL COMMENT 'column operation type, 1 is create, 2 is update, 3 is delete',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'column deleted at',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'column audit info',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_tid_ver_cid_del` (`table_id`, `table_version`, `column_id`, `deleted_at`),
+ KEY `idx_tcmid` (`metalake_id`),
+ KEY `idx_tccid` (`catalog_id`),
+ KEY `idx_tcsid` (`schema_id`)
+) ENGINE=InnoDB;
diff --git a/scripts/mysql/schema-0.7.0-mysql.sql b/scripts/mysql/schema-0.7.0-mysql.sql
new file mode 100644
index 0000000000..858d47d497
--- /dev/null
+++ b/scripts/mysql/schema-0.7.0-mysql.sql
@@ -0,0 +1,281 @@
+--
+-- 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.
+--
+
+CREATE TABLE IF NOT EXISTS `metalake_meta` (
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `metalake_name` VARCHAR(128) NOT NULL COMMENT 'metalake name',
+ `metalake_comment` VARCHAR(256) DEFAULT '' COMMENT 'metalake comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'metalake properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'metalake audit info',
+ `schema_version` MEDIUMTEXT NOT NULL COMMENT 'metalake schema version info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'metalake current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'metalake last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'metalake deleted at',
+ PRIMARY KEY (`metalake_id`),
+ UNIQUE KEY `uk_mn_del` (`metalake_name`, `deleted_at`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'metalake metadata';
+
+CREATE TABLE IF NOT EXISTS `catalog_meta` (
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `catalog_name` VARCHAR(128) NOT NULL COMMENT 'catalog name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `type` VARCHAR(64) NOT NULL COMMENT 'catalog type',
+ `provider` VARCHAR(64) NOT NULL COMMENT 'catalog provider',
+ `catalog_comment` VARCHAR(256) DEFAULT '' COMMENT 'catalog comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'catalog properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'catalog audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'catalog current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'catalog last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'catalog deleted at',
+ PRIMARY KEY (`catalog_id`),
+ UNIQUE KEY `uk_mid_cn_del` (`metalake_id`, `catalog_name`, `deleted_at`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'catalog metadata';
+
+CREATE TABLE IF NOT EXISTS `schema_meta` (
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `schema_name` VARCHAR(128) NOT NULL COMMENT 'schema name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_comment` VARCHAR(256) DEFAULT '' COMMENT 'schema comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'schema properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'schema audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'schema current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'schema last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'schema deleted at',
+ PRIMARY KEY (`schema_id`),
+ UNIQUE KEY `uk_cid_sn_del` (`catalog_id`, `schema_name`, `deleted_at`),
+ KEY `idx_mid` (`metalake_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'schema metadata';
+
+CREATE TABLE IF NOT EXISTS `table_meta` (
+ `table_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'table id',
+ `table_name` VARCHAR(128) NOT NULL COMMENT 'table name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'table audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'table current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'table last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'table deleted at',
+ PRIMARY KEY (`table_id`),
+ UNIQUE KEY `uk_sid_tn_del` (`schema_id`, `table_name`, `deleted_at`),
+ KEY `idx_mid` (`metalake_id`),
+ KEY `idx_cid` (`catalog_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'table metadata';
+
+CREATE TABLE IF NOT EXISTS `table_column_version_info` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `table_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'table id',
+ `table_version` INT UNSIGNED NOT NULL COMMENT 'table version',
+ `column_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'column id',
+ `column_name` VARCHAR(128) NOT NULL COMMENT 'column name',
+ `column_type` VARCHAR(128) NOT NULL COMMENT 'column type',
+ `column_comment` VARCHAR(256) DEFAULT '' COMMENT 'column comment',
+ `column_nullable` TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'column nullable, 0 is not nullable, 1 is nullable',
+ `column_auto_increment` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'column auto increment, 0 is not auto increment, 1 is auto increment',
+ `column_default_value` VARCHAR(256) DEFAULT NULL COMMENT 'column default value',
+ `column_op_type` TINYINT(1) NOT NULL COMMENT 'column operation type, 1 is create, 2 is update, 3 is delete',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'column deleted at',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'column audit info',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_tid_ver_cid_del` (`table_id`, `table_version`, `column_id`, `deleted_at`),
+ KEY `idx_mid` (`metalake_id`),
+ KEY `idx_cid` (`catalog_id`),
+ KEY `idx_sid` (`schema_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'table column version info';
+
+CREATE TABLE IF NOT EXISTS `fileset_meta` (
+ `fileset_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'fileset id',
+ `fileset_name` VARCHAR(128) NOT NULL COMMENT 'fileset name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `type` VARCHAR(64) NOT NULL COMMENT 'fileset type',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'fileset audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'fileset current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'fileset last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'fileset deleted at',
+ PRIMARY KEY (`fileset_id`),
+ UNIQUE KEY `uk_sid_fn_del` (`schema_id`, `fileset_name`, `deleted_at`),
+ KEY `idx_mid` (`metalake_id`),
+ KEY `idx_cid` (`catalog_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'fileset metadata';
+
+CREATE TABLE IF NOT EXISTS `fileset_version_info` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `fileset_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'fileset id',
+ `version` INT UNSIGNED NOT NULL COMMENT 'fileset info version',
+ `fileset_comment` VARCHAR(256) DEFAULT '' COMMENT 'fileset comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'fileset properties',
+ `storage_location` MEDIUMTEXT NOT NULL COMMENT 'fileset storage location',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'fileset deleted at',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_fid_ver_del` (`fileset_id`, `version`, `deleted_at`),
+ KEY `idx_mid` (`metalake_id`),
+ KEY `idx_cid` (`catalog_id`),
+ KEY `idx_sid` (`schema_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'fileset version info';
+
+CREATE TABLE IF NOT EXISTS `topic_meta` (
+ `topic_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'topic id',
+ `topic_name` VARCHAR(128) NOT NULL COMMENT 'topic name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `comment` VARCHAR(256) DEFAULT '' COMMENT 'topic comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'topic properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'topic audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'topic current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'topic last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'topic deleted at',
+ PRIMARY KEY (`topic_id`),
+ UNIQUE KEY `uk_sid_tn_del` (`schema_id`, `topic_name`, `deleted_at`),
+ KEY `idx_mid` (`metalake_id`),
+ KEY `idx_cid` (`catalog_id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'topic metadata';
+
+CREATE TABLE IF NOT EXISTS `user_meta` (
+ `user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'user id',
+ `user_name` VARCHAR(128) NOT NULL COMMENT 'username',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'user audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'user current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'user last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'user deleted at',
+ PRIMARY KEY (`user_id`),
+ UNIQUE KEY `uk_mid_us_del` (`metalake_id`, `user_name`, `deleted_at`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'user metadata';
+
+CREATE TABLE IF NOT EXISTS `role_meta` (
+ `role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
+ `role_name` VARCHAR(128) NOT NULL COMMENT 'role name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'schema properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'role audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'role current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'role last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'role deleted at',
+ PRIMARY KEY (`role_id`),
+ UNIQUE KEY `uk_mid_rn_del` (`metalake_id`, `role_name`, `deleted_at`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'role metadata';
+
+CREATE TABLE IF NOT EXISTS `role_meta_securable_object` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
+ `metadata_object_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'The entity id of securable object',
+ `type` VARCHAR(128) NOT NULL COMMENT 'securable object type',
+ `privilege_names` VARCHAR(256) NOT NULL COMMENT 'securable object privilege names',
+ `privilege_conditions` VARCHAR(256) NOT NULL COMMENT 'securable object privilege conditions',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'securable objectcurrent version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'securable object last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'securable object deleted at',
+ PRIMARY KEY (`id`),
+ KEY `idx_obj_rid` (`role_id`),
+ KEY `idx_obj_eid` (`metadata_object_id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'securable object meta';
+
+CREATE TABLE IF NOT EXISTS `user_role_rel` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'user id',
+ `role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'relation audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'relation current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'relation last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'relation deleted at',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_ui_ri_del` (`user_id`, `role_id`, `deleted_at`),
+ KEY `idx_rid` (`role_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'user role relation';
+
+CREATE TABLE IF NOT EXISTS `group_meta` (
+ `group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'group id',
+ `group_name` VARCHAR(128) NOT NULL COMMENT 'group name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'group audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'group current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'group last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'group deleted at',
+ PRIMARY KEY (`group_id`),
+ UNIQUE KEY `uk_mid_gr_del` (`metalake_id`, `group_name`, `deleted_at`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'group metadata';
+
+CREATE TABLE IF NOT EXISTS `group_role_rel` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'group id',
+ `role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'relation audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'relation current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'relation last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'relation deleted at',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_gi_ri_del` (`group_id`, `role_id`, `deleted_at`),
+ KEY `idx_rid` (`group_id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'group role relation';
+
+CREATE TABLE IF NOT EXISTS `tag_meta` (
+ `tag_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'tag id',
+ `tag_name` VARCHAR(128) NOT NULL COMMENT 'tag name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `tag_comment` VARCHAR(256) DEFAULT '' COMMENT 'tag comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'tag properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'tag audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'tag current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'tag last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'tag deleted at',
+ PRIMARY KEY (`tag_id`),
+ UNIQUE KEY `uk_mi_tn_del` (`metalake_id`, `tag_name`, `deleted_at`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'tag metadata';
+
+CREATE TABLE IF NOT EXISTS `tag_relation_meta` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `tag_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'tag id',
+ `metadata_object_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metadata object id',
+ `metadata_object_type` VARCHAR(64) NOT NULL COMMENT 'metadata object type',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'tag relation audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'tag relation current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'tag relation last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'tag relation deleted at',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_ti_mi_mo_del` (`tag_id`, `metadata_object_id`, `metadata_object_type`, `deleted_at`),
+ KEY `idx_tid` (`tag_id`),
+ KEY `idx_mid` (`metadata_object_id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'tag metadata object relation';
+
+CREATE TABLE IF NOT EXISTS `owner_meta` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `owner_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'owner id',
+ `owner_type` VARCHAR(64) NOT NULL COMMENT 'owner type',
+ `metadata_object_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metadata object id',
+ `metadata_object_type` VARCHAR(64) NOT NULL COMMENT 'metadata object type',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'owner relation audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'owner relation current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'owner relation last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'owner relation deleted at',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_ow_me_del` (`owner_id`, `metadata_object_id`, `metadata_object_type`,`deleted_at`),
+ KEY `idx_oid` (`owner_id`),
+ KEY `idx_meid` (`metadata_object_id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'owner relation';
diff --git a/scripts/mysql/upgrade-0.6.0-to-0.7.0-mysql.sql b/scripts/mysql/upgrade-0.6.0-to-0.7.0-mysql.sql
new file mode 100644
index 0000000000..007fc0a8d3
--- /dev/null
+++ b/scripts/mysql/upgrade-0.6.0-to-0.7.0-mysql.sql
@@ -0,0 +1,41 @@
+--
+-- 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.
+--
+CREATE TABLE IF NOT EXISTS `table_column_version_info` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `table_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'table id',
+ `table_version` INT UNSIGNED NOT NULL COMMENT 'table version',
+ `column_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'column id',
+ `column_name` VARCHAR(128) NOT NULL COMMENT 'column name',
+ `column_type` VARCHAR(128) NOT NULL COMMENT 'column type',
+ `column_comment` VARCHAR(256) DEFAULT '' COMMENT 'column comment',
+ `column_nullable` TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'column nullable, 0 is not nullable, 1 is nullable',
+ `column_auto_increment` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'column auto increment, 0 is not auto increment, 1 is auto increment',
+ `column_default_value` VARCHAR(256) DEFAULT NULL COMMENT 'column default value',
+ `column_op_type` TINYINT(1) NOT NULL COMMENT 'column operation type, 1 is create, 2 is update, 3 is delete',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'column deleted at',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'column audit info',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_tid_ver_cid_del` (`table_id`, `table_version`, `column_id`, `deleted_at`),
+ KEY `idx_mid` (`metalake_id`),
+ KEY `idx_cid` (`catalog_id`),
+ KEY `idx_sid` (`schema_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'table column version info';
diff --git a/scripts/postgresql/schema-0.7.0-postgresql.sql b/scripts/postgresql/schema-0.7.0-postgresql.sql
index 0ce7a96853..e2ad46cf50 100644
--- a/scripts/postgresql/schema-0.7.0-postgresql.sql
+++ b/scripts/postgresql/schema-0.7.0-postgresql.sql
@@ -140,6 +140,48 @@ COMMENT ON COLUMN table_meta.current_version IS 'table current version';
COMMENT ON COLUMN table_meta.last_version IS 'table last version';
COMMENT ON COLUMN table_meta.deleted_at IS 'table deleted at';
+CREATE TABLE IF NOT EXISTS table_column_version_info (
+ id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+ metalake_id BIGINT NOT NULL,
+ catalog_id BIGINT NOT NULL,
+ schema_id BIGINT NOT NULL,
+ table_id BIGINT NOT NULL,
+ table_version INT NOT NULL,
+ column_id BIGINT NOT NULL,
+ column_name VARCHAR(128) NOT NULL,
+ column_type VARCHAR(128) NOT NULL,
+ column_comment VARCHAR(256) DEFAULT '',
+ column_nullable SMALLINT NOT NULL DEFAULT 1,
+ column_auto_increment SMALLINT NOT NULL DEFAULT 0,
+ column_default_value VARCHAR(256) DEFAULT NULL,
+ column_op_type SMALLINT NOT NULL,
+ deleted_at BIGINT NOT NULL DEFAULT 0,
+ audit_info TEXT NOT NULL,
+ PRIMARY KEY (id),
+ UNIQUE (table_id, table_version, column_id, deleted_at)
+);
+CREATE INDEX idx_mid ON table_column_version_info (metalake_id);
+CREATE INDEX idx_cid ON table_column_version_info (catalog_id);
+CREATE INDEX idx_sid ON table_column_version_info (schema_id);
+COMMENT ON TABLE table_column_version_info IS 'table column version information';
+
+COMMENT ON COLUMN table_column_version_info.id IS 'auto increment id';
+COMMENT ON COLUMN table_column_version_info.metalake_id IS 'metalake id';
+COMMENT ON COLUMN table_column_version_info.catalog_id IS 'catalog id';
+COMMENT ON COLUMN table_column_version_info.schema_id IS 'schema id';
+COMMENT ON COLUMN table_column_version_info.table_id IS 'table id';
+COMMENT ON COLUMN table_column_version_info.table_version IS 'table version';
+COMMENT ON COLUMN table_column_version_info.column_id IS 'column id';
+COMMENT ON COLUMN table_column_version_info.column_name IS 'column name';
+COMMENT ON COLUMN table_column_version_info.column_type IS 'column type';
+COMMENT ON COLUMN table_column_version_info.column_comment IS 'column comment';
+COMMENT ON COLUMN table_column_version_info.column_nullable IS 'column nullable, 0 is not nullable, 1 is nullable';
+COMMENT ON COLUMN table_column_version_info.column_auto_increment IS 'column auto increment, 0 is not auto increment, 1 is auto increment';
+COMMENT ON COLUMN table_column_version_info.column_default_value IS 'column default value';
+COMMENT ON COLUMN table_column_version_info.column_op_type IS 'column operation type, 1 is create, 2 is update, 3 is delete';
+COMMENT ON COLUMN table_column_version_info.deleted_at IS 'column deleted at';
+COMMENT ON COLUMN table_column_version_info.audit_info IS 'column audit info';
+
CREATE TABLE IF NOT EXISTS fileset_meta (
fileset_id BIGINT NOT NULL,