Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions docs/en/docs/sql-manual/sql-reference/Data-Types/STRUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -123,4 +121,4 @@ mysql> select * from struct_test;

### keywords

STRUCT
STRUCT
6 changes: 2 additions & 4 deletions docs/zh-CN/docs/sql-manual/sql-reference/Data-Types/STRUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ DATEV2, DATETIME, DATETIMEV2, CHAR, VARCHAR, STRING
在将来的版本我们还将完善:

```
TODO:
1、支持 COMMENT
2、支持嵌套 STRUCT 或其他的复杂类型
TODO:支持嵌套 STRUCT 或其他的复杂类型
```

### example
Expand Down Expand Up @@ -123,4 +121,4 @@ mysql> select * from struct_test;

### keywords

STRUCT
STRUCT
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -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 ::=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ suite("test_complex_type_unique_key", "p0") {
id INT,
a ARRAY<SMALLINT> NOT NULL COMMENT "",
m MAP<STRING, INT(11)> NOT NULL COMMENT "",
s STRUCT<f1:SMALLINT, f2:INT(11)> NOT NULL COMMENT "",
s STRUCT<f1:SMALLINT COMMENT 'sf1', f2:INT(11) COMMENT 'sf2'> NOT NULL COMMENT "",
an ARRAY<DATE>,
mn MAP<STRING, INT(11)>,
sn STRUCT<f1:SMALLINT, f2:INT(11)>
Expand Down