diff --git a/docs/en/docs/sql-manual/sql-reference/Data-Types/STRUCT.md b/docs/en/docs/sql-manual/sql-reference/Data-Types/STRUCT.md index e0a3a506f45349..bf3b2d1d4c6794 100644 --- a/docs/en/docs/sql-manual/sql-reference/Data-Types/STRUCT.md +++ b/docs/en/docs/sql-manual/sql-reference/Data-Types/STRUCT.md @@ -58,9 +58,7 @@ DATEV2, DATETIME, DATETIMEV2, CHAR, VARCHAR, STRING We have a todo list for future version: ``` -TODO: - 1、支持 COMMENT - 2、支持嵌套 STRUCT 或其他的复杂类型 +TODO:支持嵌套 STRUCT 或其他的复杂类型 ``` ### example @@ -123,4 +121,4 @@ mysql> select * from struct_test; ### keywords - STRUCT \ No newline at end of file + STRUCT diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Types/STRUCT.md b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Types/STRUCT.md index db3a3997bce0bc..39ec42b21251a5 100644 --- a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Types/STRUCT.md +++ b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Types/STRUCT.md @@ -56,9 +56,7 @@ DATEV2, DATETIME, DATETIMEV2, CHAR, VARCHAR, STRING 在将来的版本我们还将完善: ``` -TODO: - 1、支持 COMMENT - 2、支持嵌套 STRUCT 或其他的复杂类型 +TODO:支持嵌套 STRUCT 或其他的复杂类型 ``` ### example @@ -123,4 +121,4 @@ mysql> select * from struct_test; ### keywords - STRUCT \ No newline at end of file + STRUCT diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/StructField.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/StructField.java index 20ef2cb1358e51..488e477a07eb95 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/StructField.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/StructField.java @@ -23,11 +23,8 @@ import com.google.common.base.Strings; import com.google.gson.annotations.SerializedName; +import org.apache.commons.lang3.StringUtils; -/** - * TODO: Support comments for struct fields. The Metastore does not properly store - * comments of struct fields. We set comment to null to avoid compatibility issues. - */ public class StructField { @SerializedName(value = "name") protected final String name; @@ -57,6 +54,10 @@ public StructField(String name, Type type) { this(name, type, null, true); } + public StructField(String name, Type type, String comment) { + this(name, type, comment, true); + } + public StructField(Type type) { this(DEFAULT_FIELD_NAME, type, null, true); } @@ -96,7 +97,7 @@ public String toSql(int depth) { if (type != null) { sb.append(":").append(typeSql); } - if (comment != null) { + if (StringUtils.isNotBlank(comment)) { sb.append(String.format(" COMMENT '%s'", comment)); } return sb.toString(); @@ -116,7 +117,7 @@ public String prettyPrint(int lpad) { typeStr = typeStr.substring(lpad); sb.append(":").append(typeStr); } - if (comment != null) { + if (StringUtils.isNotBlank(comment)) { sb.append(String.format(" COMMENT '%s'", comment)); } return sb.toString(); @@ -143,9 +144,6 @@ public boolean matchesField(StructField f) { public void toThrift(TTypeDesc container, TTypeNode node) { TStructField field = new TStructField(); field.setName(name); - if (comment != null) { - field.setComment(comment); - } field.setContainsNull(containsNull); node.struct_fields.add(field); type.toThrift(container); diff --git a/fe/fe-core/src/main/cup/sql_parser.cup b/fe/fe-core/src/main/cup/sql_parser.cup index 305e0334272929..5967991ec403d5 100644 --- a/fe/fe-core/src/main/cup/sql_parser.cup +++ b/fe/fe-core/src/main/cup/sql_parser.cup @@ -6328,8 +6328,8 @@ map_expr ::= ; struct_field ::= - ident:name COLON type:type - {: RESULT = new StructField(name, type); :} + ident:name COLON type:type opt_comment:comment + {: RESULT = new StructField(name, type, comment); :} ; struct_field_list ::= diff --git a/regression-test/suites/query_p0/show/test_complex_type_unique_key.groovy b/regression-test/suites/query_p0/show/test_complex_type_unique_key.groovy index 6978813bbae07a..8417fc4865a2c2 100644 --- a/regression-test/suites/query_p0/show/test_complex_type_unique_key.groovy +++ b/regression-test/suites/query_p0/show/test_complex_type_unique_key.groovy @@ -30,7 +30,7 @@ suite("test_complex_type_unique_key", "p0") { id INT, a ARRAY NOT NULL COMMENT "", m MAP NOT NULL COMMENT "", - s STRUCT NOT NULL COMMENT "", + s STRUCT NOT NULL COMMENT "", an ARRAY, mn MAP, sn STRUCT