Skip to content

Commit

Permalink
[minor](planner) remove len on integral type toSql
Browse files Browse the repository at this point in the history
  • Loading branch information
morrySnow committed Oct 31, 2023
1 parent 462db3d commit e83e634
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public boolean getResultIsNullable() {
@Override
public String toSql(int depth) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("agg_state(");
stringBuilder.append("AGG_STATE(");
for (int i = 0; i < subTypes.size(); i++) {
if (i > 0) {
stringBuilder.append(", ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ public static ArrayType create(Type type, boolean containsNull) {
@Override
public String toSql(int depth) {
if (!containsNull) {
return "array<not_null(" + itemType.toSql(depth + 1) + ")>";
return "ARRAY<" + itemType.toSql(depth + 1) + " NOT NULL>";
} else {
return "array<" + itemType.toSql(depth + 1) + ">";
return "ARRAY<" + itemType.toSql(depth + 1) + ">";
}
}

Expand Down Expand Up @@ -203,7 +203,7 @@ public boolean supportSubType(Type subType) {

@Override
public String toString() {
return String.format("ARRAY<%s>", itemType.toString()).toUpperCase();
return String.format("ARRAY<%s>", itemType.toString());
}

@Override
Expand Down
54 changes: 27 additions & 27 deletions fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java
Original file line number Diff line number Diff line change
Expand Up @@ -583,38 +583,38 @@ public String toSql(int depth) {
switch (type) {
case CHAR:
if (isWildcardVarchar()) {
stringBuilder.append("character");
stringBuilder.append("CHARACTER");
} else if (Strings.isNullOrEmpty(lenStr)) {
stringBuilder.append("char").append("(").append(len).append(")");
stringBuilder.append("CHAR").append("(").append(len).append(")");
} else {
stringBuilder.append("char").append("(`").append(lenStr).append("`)");
stringBuilder.append("CHAR").append("(`").append(lenStr).append("`)");
}
break;
case VARCHAR:
if (isWildcardVarchar()) {
stringBuilder.append("varchar(*)");
stringBuilder.append("VARCHAR(*)");
} else if (Strings.isNullOrEmpty(lenStr)) {
stringBuilder.append("varchar").append("(").append(len).append(")");
stringBuilder.append("VARCHAR").append("(").append(len).append(")");
} else {
stringBuilder.append("varchar").append("(`").append(lenStr).append("`)");
stringBuilder.append("VARCHAR").append("(`").append(lenStr).append("`)");
}
break;
case DECIMALV2:
if (Strings.isNullOrEmpty(precisionStr)) {
stringBuilder.append("decimal").append("(").append(precision)
stringBuilder.append("DECIMAL").append("(").append(precision)
.append(", ").append(scale).append(")");
} else if (!Strings.isNullOrEmpty(precisionStr) && !Strings.isNullOrEmpty(scaleStr)) {
stringBuilder.append("decimal").append("(`").append(precisionStr)
stringBuilder.append("DECIMAL").append("(`").append(precisionStr)
.append("`, `").append(scaleStr).append("`)");
} else {
stringBuilder.append("decimal").append("(`").append(precisionStr).append("`)");
stringBuilder.append("DECIMAL").append("(`").append(precisionStr).append("`)");
}
break;
case DECIMAL32:
case DECIMAL64:
case DECIMAL128:
case DECIMAL256:
String typeName = "decimalv3";
String typeName = "DECIMALV3";
if (Strings.isNullOrEmpty(precisionStr)) {
stringBuilder.append(typeName).append("(").append(precision)
.append(", ").append(scale).append(")");
Expand All @@ -626,30 +626,30 @@ public String toSql(int depth) {
}
break;
case DATETIMEV2:
stringBuilder.append("datetimev2").append("(").append(scale).append(")");
stringBuilder.append("DATETIMEV2").append("(").append(scale).append(")");
break;
case TIME:
stringBuilder.append("time");
stringBuilder.append("TIME");
break;
case TIMEV2:
stringBuilder.append("time").append("(").append(scale).append(")");
stringBuilder.append("TIME").append("(").append(scale).append(")");
break;
case BOOLEAN:
return "boolean";
return "BOOLEAN";
case TINYINT:
return "tinyint(4)";
return "TINYINT";
case SMALLINT:
return "smallint(6)";
return "SMALLINT";
case INT:
return "int(11)";
case IPV4:
return "ipv4";
return "INT";
case BIGINT:
return "bigint(20)";
return "BIGINT";
case LARGEINT:
return "largeint(40)";
return "LARGEINT";
case IPV4:
return "IPV4";
case IPV6:
return "ipv6";
return "IPV6";
case FLOAT:
case DOUBLE:
case DATE:
Expand All @@ -662,19 +662,19 @@ public String toSql(int depth) {
case LAMBDA_FUNCTION:
case ARRAY:
case NULL_TYPE:
stringBuilder.append(type.toString().toLowerCase());
stringBuilder.append(type);
break;
case STRING:
stringBuilder.append("text");
stringBuilder.append("TEXT");
break;
case JSONB:
stringBuilder.append("json");
stringBuilder.append("JSON");
break;
case AGG_STATE:
stringBuilder.append("agg_state(unknown)");
stringBuilder.append("AGG_STATE(UNKNOWN)");
break;
default:
stringBuilder.append("unknown type: " + type.toString());
stringBuilder.append("unknown type: ").append(type);
break;
}
return stringBuilder.toString();
Expand Down
2 changes: 1 addition & 1 deletion regression-test/suites/nereids_syntax_p0/explain.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ suite("nereids_explain") {
when 1>1 then cast(1 as float)
else 0.0 end;
"""
contains "SlotDescriptor{id=0, col=null, colUniqueId=null, type=double, nullable=false, isAutoIncrement=false}"
contains "SlotDescriptor{id=0, col=null, colUniqueId=null, type=DOUBLE, nullable=false, isAutoIncrement=false}"
}

def explainStr = sql("select sum(if(lo_tax=1,lo_tax,0)) from lineorder where false").toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ suite("test_multi_partition_key", "p0") {
test {
sql "ALTER TABLE test_multi_col_test_partition_add ADD PARTITION partition_add VALUES LESS THAN ('30', '1000') " +
"DISTRIBUTED BY hash(k1) BUCKETS 5"
exception "Cannot assign hash distribution with different distribution cols. new is: [`k1` tinyint(4) NOT NULL] default is: [`k1` tinyint(4) NOT NULL]"
exception "Cannot assign hash distribution with different distribution cols. new is: [`k1` TINYINT NOT NULL] default is: [`k1` TINYINT NOT NULL]"
}

sql "ALTER TABLE test_multi_col_test_partition_add ADD PARTITION partition_add VALUES LESS THAN ('30', '1000') "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,45 +142,45 @@ suite("test_nested_complex_switch", "query") {
// map
test {
sql sql_m_s
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported data type: MAP<text,STRUCT<f1:tinyint(4)>>"
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported data type: MAP<TEXT,STRUCT<f1:TINYINT>>"
}

test {
sql sql_m_a
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported data type: MAP<array<int(11)>,text>"
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported data type: MAP<ARRAY<INT>,TEXT>"
}

test {
sql sql_m_m
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported data type: MAP<text,MAP<text,int(11)>>"
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported data type: MAP<TEXT,MAP<TEXT,INT>>"
}

// array
test {
sql sql_a_s
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported data type: ARRAY<STRUCT<f1:tinyint(4)>>"
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported data type: ARRAY<STRUCT<f1:TINYINT>>"
}


test {
sql sql_a_m
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported data type: ARRAY<MAP<text,int(11)>>"
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported data type: ARRAY<MAP<TEXT,INT>>"
}

// struct
test {
sql sql_s_s
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported field type: STRUCT<f11:boolean> for STRUCT"
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported field type: STRUCT<f11:BOOLEAN> for STRUCT"
}

test {
sql sql_s_a
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported field type: array<int(11)> for STRUCT"
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported field type: ARRAY<INT> for STRUCT"
}

test {
sql sql_s_m
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported field type: MAP<boolean,tinyint(4)> for STRUCT"
exception "java.sql.SQLException: errCode = 2, detailMessage = Unsupported field type: MAP<BOOLEAN,TINYINT> for STRUCT"
}

} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ suite("test_materialized_view_array", "rollup") {
create_test_table.call(tableName)
test {
sql "CREATE MATERIALIZED VIEW idx AS select k2,k1, k3, k4, k5 from ${tableName}"
exception "errCode = 2, detailMessage = The ARRAY column[`mv_k2` array<smallint(6)> NULL] not support to create materialized view"
exception "errCode = 2, detailMessage = The ARRAY column[`mv_k2` ARRAY<SMALLINT> NULL] not support to create materialized view"
}
} finally {
try_sql("DROP TABLE IF EXISTS ${tableName}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ suite("test_materialized_view_struct", "rollup") {
create_test_table.call(tableName)
test {
sql "CREATE MATERIALIZED VIEW idx AS select k2,k1, k3, k4, k5 from ${tableName}"
exception "errCode = 2, detailMessage = The STRUCT column[`mv_k2` STRUCT<f1:smallint(6)> NULL] not support to create materialized view"
exception "errCode = 2, detailMessage = The STRUCT column[`mv_k2` STRUCT<f1:SMALLINT> NULL] not support to create materialized view"
}
} finally {
try_sql("DROP TABLE IF EXISTS ${tableName}")
Expand Down

0 comments on commit e83e634

Please sign in to comment.