This is an automated email from the ASF dual-hosted git repository. lipeidian pushed a commit to branch issue-5443 in repository https://gitbox.apache.org/repos/asf/gravitino.git
commit 38630316b4922f5f73b8bcb2826f344df5bc6cd2 Author: lipeidian <[email protected]> AuthorDate: Tue Nov 5 14:47:23 2024 +0800 update --- .../main/java/org/apache/gravitino/rel/Column.java | 64 +++++++++++++++++++--- .../org/apache/gravitino/dto/rel/ColumnDTO.java | 31 ++++++++++- .../org/apache/gravitino/connector/BaseColumn.java | 27 +++++++++ 3 files changed, 113 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/org/apache/gravitino/rel/Column.java b/api/src/main/java/org/apache/gravitino/rel/Column.java index 650f5748f..a0feda1e5 100644 --- a/api/src/main/java/org/apache/gravitino/rel/Column.java +++ b/api/src/main/java/org/apache/gravitino/rel/Column.java @@ -20,8 +20,11 @@ package org.apache.gravitino.rel; import com.google.common.base.Preconditions; import com.google.common.base.Strings; + import java.util.Map; import java.util.Objects; + +import com.google.common.collect.ImmutableMap; import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.rel.expressions.Expression; @@ -71,6 +74,11 @@ public interface Column { */ Expression defaultValue(); + /** + * @return The properties of this column. + */ + Map<String, String> properties(); + /** * Create a {@link Column} instance. * @@ -82,7 +90,7 @@ public interface Column { * @return A {@link Column} instance. */ static ColumnImpl of(String name, Type dataType, String comment, Expression defaultValue) { - return of(name, dataType, comment, true, false, defaultValue); + return of(name, dataType, comment, true, false, defaultValue, ImmutableMap.of()); } /** @@ -94,7 +102,7 @@ public interface Column { * @return A {@link Column} instance. */ static ColumnImpl of(String name, Type dataType, String comment) { - return of(name, dataType, comment, true, false, DEFAULT_VALUE_NOT_SET); + return of(name, dataType, comment, true, false, DEFAULT_VALUE_NOT_SET, ImmutableMap.of()); } /** @@ -105,7 +113,7 @@ public interface Column { * @return A {@link Column} instance. */ static ColumnImpl of(String name, Type dataType) { - return of(name, dataType, null, true, false, DEFAULT_VALUE_NOT_SET); + return of(name, dataType, null, true, false, DEFAULT_VALUE_NOT_SET, ImmutableMap.of()); } /** @@ -133,7 +141,39 @@ public interface Column { comment, nullable, autoIncrement, - defaultValue == null ? DEFAULT_VALUE_NOT_SET : defaultValue); + defaultValue == null ? DEFAULT_VALUE_NOT_SET : defaultValue, + ImmutableMap.of()); + } + + /** + * Create a {@link Column} instance. + * + * @param name The name of the column. + * @param dataType The data type of the column. + * @param comment The comment of the column. + * @param nullable True if the column may produce null values. + * @param autoIncrement True if the column is an auto-increment column. + * @param defaultValue The default value of the column. {@link Column#DEFAULT_VALUE_NOT_SET} if + * null. + * @param properties The properties of the column. + * @return A {@link Column} instance. + */ + static ColumnImpl of( + String name, + Type dataType, + String comment, + boolean nullable, + boolean autoIncrement, + Expression defaultValue, + Map<String, String> properties) { + return new ColumnImpl( + name, + dataType, + comment, + nullable, + autoIncrement, + defaultValue == null ? DEFAULT_VALUE_NOT_SET : defaultValue, + properties); } /** The implementation of {@link Column} for users to use API. */ @@ -144,6 +184,7 @@ public interface Column { private boolean nullable; private boolean autoIncrement; private Expression defaultValue; + private Map<String, String> properties; private ColumnImpl( String name, @@ -151,15 +192,18 @@ public interface Column { String comment, boolean nullable, boolean autoIncrement, - Expression defaultValue) { + Expression defaultValue, + Map<String, String> properties) { Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "Column name cannot be null"); Preconditions.checkArgument(dataType != null, "Column data type cannot be null"); + Preconditions.checkArgument(properties != null, "Column properties cannot be null"); this.name = name; this.dataType = dataType; this.comment = comment; this.nullable = nullable; this.autoIncrement = autoIncrement; this.defaultValue = defaultValue; + this.properties = properties; } @Override @@ -192,6 +236,11 @@ public interface Column { return defaultValue; } + @Override + public Map<String, String> properties() { + return properties; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -206,12 +255,13 @@ public interface Column { && Objects.equals(name, column.name) && Objects.equals(dataType, column.dataType) && Objects.equals(comment, column.comment) - && Objects.equals(defaultValue, column.defaultValue); + && Objects.equals(defaultValue, column.defaultValue) + && Objects.equals(properties, column.properties); } @Override public int hashCode() { - return Objects.hash(name, dataType, comment, nullable, autoIncrement, defaultValue); + return Objects.hash(name, dataType, comment, nullable, autoIncrement, defaultValue, properties); } } } diff --git a/common/src/main/java/org/apache/gravitino/dto/rel/ColumnDTO.java b/common/src/main/java/org/apache/gravitino/dto/rel/ColumnDTO.java index 4684cb6ce..fa52931e3 100644 --- a/common/src/main/java/org/apache/gravitino/dto/rel/ColumnDTO.java +++ b/common/src/main/java/org/apache/gravitino/dto/rel/ColumnDTO.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; import lombok.EqualsAndHashCode; import lombok.ToString; import org.apache.gravitino.dto.rel.expressions.LiteralDTO; @@ -32,6 +33,8 @@ import org.apache.gravitino.rel.expressions.Expression; import org.apache.gravitino.rel.types.Type; import org.apache.gravitino.rel.types.Types; +import java.util.Map; + /** Represents a Column DTO (Data Transfer Object). */ @EqualsAndHashCode @ToString @@ -62,6 +65,9 @@ public class ColumnDTO implements Column { @JsonDeserialize(using = JsonUtils.ColumnDefaultValueDeserializer.class) private Expression defaultValue = Column.DEFAULT_VALUE_NOT_SET; + @JsonProperty("properties") + private Map<String, String> properties = Maps.newHashMap(); + private ColumnDTO() {} /** @@ -80,13 +86,15 @@ public class ColumnDTO implements Column { String comment, boolean nullable, boolean autoIncrement, - Expression defaultValue) { + Expression defaultValue, + Map<String, String> properties) { this.name = name; this.dataType = dataType; this.comment = comment; this.nullable = nullable; this.autoIncrement = autoIncrement; this.defaultValue = defaultValue == null ? Column.DEFAULT_VALUE_NOT_SET : defaultValue; + this.properties = properties; } @Override @@ -119,6 +127,11 @@ public class ColumnDTO implements Column { return defaultValue; } + @Override + public Map<String, String> properties() { + return properties; + } + /** * Creates a new Builder to build a Column DTO. * @@ -153,6 +166,9 @@ public class ColumnDTO implements Column { /** The default value of the column. */ protected Expression defaultValue; + /** The properties of the column. */ + protected Map<String, String> properties; + /** Constructs a new Builder. */ public Builder() {} @@ -222,6 +238,17 @@ public class ColumnDTO implements Column { return (S) this; } + /** + * Sets the comment for the column. + * + * @param properties The properties of the column. + * @return The Builder instance. + */ + public S withProperties(Map<String, String> properties) { + this.properties = properties; + return (S) this; + } + /** * Builds a Column DTO based on the provided builder parameters. * @@ -231,7 +258,7 @@ public class ColumnDTO implements Column { public ColumnDTO build() { Preconditions.checkNotNull(name, "Column name cannot be null"); Preconditions.checkNotNull(dataType, "Column data type cannot be null"); - return new ColumnDTO(name, dataType, comment, nullable, autoIncrement, defaultValue); + return new ColumnDTO(name, dataType, comment, nullable, autoIncrement, defaultValue, properties); } } diff --git a/core/src/main/java/org/apache/gravitino/connector/BaseColumn.java b/core/src/main/java/org/apache/gravitino/connector/BaseColumn.java index 2c9520f78..4a170df64 100644 --- a/core/src/main/java/org/apache/gravitino/connector/BaseColumn.java +++ b/core/src/main/java/org/apache/gravitino/connector/BaseColumn.java @@ -27,6 +27,8 @@ import org.apache.gravitino.rel.Column; import org.apache.gravitino.rel.expressions.Expression; import org.apache.gravitino.rel.types.Type; +import java.util.Map; + /** An abstract class representing a base column in a relational database. */ @Evolving @ToString @@ -45,6 +47,8 @@ public abstract class BaseColumn implements Column { protected Expression defaultValue; + protected Map<String, String> properties; + /** * Returns the name of the column. * @@ -96,6 +100,14 @@ public abstract class BaseColumn implements Column { return defaultValue; } + /** + * @return The properties of this column. + */ + @Override + public Map<String, String> properties() { + return properties; + } + /** * Builder interface for creating instances of {@link BaseColumn}. * @@ -116,6 +128,8 @@ public abstract class BaseColumn implements Column { SELF withDefaultValue(Expression defaultValue); + SELF withProperties(Map<String, String> properties); + T build(); } @@ -134,6 +148,7 @@ public abstract class BaseColumn implements Column { protected boolean nullable = true; protected boolean autoIncrement = false; protected Expression defaultValue; + protected Map<String, String> properties; /** * Sets the name of the column. @@ -207,6 +222,18 @@ public abstract class BaseColumn implements Column { return self(); } + /** + * Sets the properties of the column. + * + * @param properties The properties of the column. + * @return The builder instance. + */ + @Override + public SELF withProperties(Map<String, String> properties) { + this.properties = properties; + return self(); + } + /** * Builds the instance of the column with the provided attributes. *
