[improvement](type) modify the inner type display of the Array/Map/Struct type (#24459)

In the old code, when using desc command to view the table schema
It will display as follows
```
ARRAY<TINYINT(4)>
ARRAY<SMALLINT(6)>
ARRAY<INT(11)>
ARRAY<BIGINT(20)>
ARRAY<LARGEINT(40)>
```
However, for normal integer type displays, the width is not displayed
So, I changed it to the following
```
ARRAY<TINYINT>
ARRAY<SMALLINT>
ARRAY<INT>
ARRAY<BIGINT>
ARRAY<LARGEINT>
```
This commit is contained in:
zy-kkk
2023-09-20 17:03:03 +08:00
committed by GitHub
parent 1405b7ca82
commit 5eb8fe3d6e
5 changed files with 23 additions and 6 deletions

View File

@ -203,7 +203,7 @@ public class ArrayType extends Type {
@Override
public String toString() {
return toSql(0).toUpperCase();
return String.format("ARRAY<%s>", itemType.toString()).toUpperCase();
}
@Override

View File

@ -174,7 +174,8 @@ public class MapType extends Type {
@Override
public String toString() {
return toSql(0).toUpperCase();
return String.format("MAP<%s,%s>",
keyType.toString(), valueType.toString());
}
@Override

View File

@ -158,4 +158,16 @@ public class StructField {
return otherStructField.name.equals(name) && otherStructField.type.equals(type)
&& otherStructField.containsNull == containsNull;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(name);
if (type != null) {
sb.append(":").append(type);
}
if (StringUtils.isNotBlank(comment)) {
sb.append(String.format(" COMMENT '%s'", comment));
}
return sb.toString();
}
}

View File

@ -303,7 +303,11 @@ public class StructType extends Type {
@Override
public String toString() {
return toSql(0);
ArrayList<String> fieldsSql = Lists.newArrayList();
for (StructField f : fields) {
fieldsSql.add(f.toString());
}
return String.format("STRUCT<%s>", Joiner.on(",").join(fieldsSql));
}
@Override

View File

@ -21,9 +21,9 @@ value2 INT Yes false \N SUM
-- !sql --
k1 INT Yes true \N
value1 INT Yes false \N NONE
value2 ARRAY<INT(11)> Yes false [] NONE
value3 ARRAY<INT(11)> Yes false \N NONE
value4 ARRAY<INT(11)> No false [] NONE
value2 ARRAY<INT> Yes false [] NONE
value3 ARRAY<INT> Yes false \N NONE
value4 ARRAY<INT> No false [] NONE
-- !sql --
1 2 [] \N []