Skip to content

Commit

Permalink
[fix](compability) type toSql should return lowercase string
Browse files Browse the repository at this point in the history
revert #25951
  • Loading branch information
morrySnow committed Jul 17, 2024
1 parent 29b99ad commit e79abe6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 53 deletions.
77 changes: 37 additions & 40 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 @@ -579,36 +579,34 @@ public static ScalarType createHllType() {
public String toString() {
if (type == PrimitiveType.CHAR) {
if (isWildcardChar()) {
return "CHARACTER(" + MAX_CHAR_LENGTH + ")";
return "character(" + MAX_CHAR_LENGTH + ")";
}
return "CHAR(" + len + ")";
return "char(" + len + ")";
} else if (type == PrimitiveType.DECIMALV2) {
if (isWildcardDecimal()) {
return "DECIMAL(*, *)";
return "decimal(*, *)";
}
return "DECIMAL(" + precision + ", " + scale + ")";
return "decimal(" + precision + ", " + scale + ")";
} else if (type.isDecimalV3Type()) {
if (isWildcardDecimal()) {
return "DECIMALV3(*, *)";
return "decimalv3(*, *)";
}
return "DECIMALV3(" + precision + ", " + scale + ")";
return "decimalv3(" + precision + ", " + scale + ")";
} else if (type == PrimitiveType.DATETIMEV2) {
return "DATETIMEV2(" + scale + ")";
return "datetimev2(" + scale + ")";
} else if (type == PrimitiveType.TIMEV2) {
return "TIMEV2(" + scale + ")";
return "timev2(" + scale + ")";
} else if (type == PrimitiveType.VARCHAR) {
if (isWildcardVarchar()) {
return "VARCHAR(" + MAX_VARCHAR_LENGTH + ")";
return "varchar(" + MAX_VARCHAR_LENGTH + ")";
}
return "VARCHAR(" + len + ")";
return "varchar(" + len + ")";
} else if (type == PrimitiveType.STRING) {
return "TEXT";
return "text";
} else if (type == PrimitiveType.JSONB) {
return "JSON";
} else if (type == PrimitiveType.VARIANT) {
return "VARIANT";
return "json";
}
return type.toString();
return type.toString().toLowerCase();
}

@Override
Expand All @@ -617,38 +615,38 @@ public String toSql(int depth) {
switch (type) {
case CHAR:
if (isWildcardChar()) {
stringBuilder.append("CHARACTER").append("(").append(MAX_CHAR_LENGTH).append(")");
stringBuilder.append("character").append("(").append(MAX_CHAR_LENGTH).append(")");
} 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()) {
return "VARCHAR(" + MAX_VARCHAR_LENGTH + ")";
return "varchar(" + MAX_VARCHAR_LENGTH + ")";
} 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("DECIMALV2").append("(").append(precision)
stringBuilder.append("decimalv2").append("(").append(precision)
.append(", ").append(scale).append(")");
} else if (!Strings.isNullOrEmpty(precisionStr) && !Strings.isNullOrEmpty(scaleStr)) {
stringBuilder.append("DECIMALV2").append("(`").append(precisionStr)
stringBuilder.append("decimalv2").append("(`").append(precisionStr)
.append("`, `").append(scaleStr).append("`)");
} else {
stringBuilder.append("DECIMALV2").append("(`").append(precisionStr).append("`)");
stringBuilder.append("decimalv2").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 @@ -660,30 +658,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("timev2").append("(").append(scale).append(")");
break;
case BOOLEAN:
return "BOOLEAN";
return "boolean";
case TINYINT:
return "TINYINT";
return "tinyint";
case SMALLINT:
return "SMALLINT";
return "smallint";
case INT:
return "INT";
return "int";
case BIGINT:
return "BIGINT";
return "bigint";
case LARGEINT:
return "LARGEINT";
return "largeint";
case IPV4:
return "IPV4";
return "ipv4";
case IPV6:
return "IPV6";
return "ipv6";
case FLOAT:
case DOUBLE:
case DATE:
Expand All @@ -694,15 +692,14 @@ public String toSql(int depth) {
case VARIANT:
case QUANTILE_STATE:
case LAMBDA_FUNCTION:
case ARRAY:
case NULL_TYPE:
stringBuilder.append(type);
stringBuilder.append(type.toString().toLowerCase());
break;
case STRING:
stringBuilder.append("TEXT");
stringBuilder.append("text");
break;
case JSONB:
stringBuilder.append("JSON");
stringBuilder.append("json");
break;
default:
stringBuilder.append("unknown type: ").append(type);
Expand Down
28 changes: 15 additions & 13 deletions fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,40 +452,42 @@ public boolean typeContainsPrecision() {
}

public String hideVersionForVersionColumn(Boolean isToSql) {
if (isDatetimeV2()) {
StringBuilder typeStr = new StringBuilder("DATETIME");
if (isDatetime() || isDatetimeV2()) {
StringBuilder typeStr = new StringBuilder("datetime");
if (((ScalarType) this).getScalarScale() > 0) {
typeStr.append("(").append(((ScalarType) this).getScalarScale()).append(")");
}
return typeStr.toString();
} else if (isDateV2()) {
return "DATE";
} else if (isDecimalV3()) {
StringBuilder typeStr = new StringBuilder("DECIMAL");
} else if (isDate() || isDateV2()) {
return "date";
} else if (isDecimalV2() || isDecimalV3()) {
StringBuilder typeStr = new StringBuilder("decimal");
ScalarType sType = (ScalarType) this;
int scale = sType.getScalarScale();
int precision = sType.getScalarPrecision();
// not default
if (!sType.isDefaultDecimal()) {
typeStr.append("(").append(precision).append(", ").append(scale)
.append(")");
typeStr.append("(").append(precision).append(", ").append(scale).append(")");
return typeStr.toString();
} else if (isTime() || isTimeV2()) {
StringBuilder typeStr = new StringBuilder("time");
if (((ScalarType) this).getScalarScale() > 0) {
typeStr.append("(").append(((ScalarType) this).getScalarScale()).append(")");
}
return typeStr.toString();
} else if (isArrayType()) {
String nestedDesc = ((ArrayType) this).getItemType().hideVersionForVersionColumn(isToSql);
return "ARRAY<" + nestedDesc + ">";
return "array<" + nestedDesc + ">";
} else if (isMapType()) {
String keyDesc = ((MapType) this).getKeyType().hideVersionForVersionColumn(isToSql);
String valueDesc = ((MapType) this).getValueType().hideVersionForVersionColumn(isToSql);
return "MAP<" + keyDesc + "," + valueDesc + ">";
return "map<" + keyDesc + "," + valueDesc + ">";
} else if (isStructType()) {
List<String> fieldDesc = new ArrayList<>();
StructType structType = (StructType) this;
for (int i = 0; i < structType.getFields().size(); i++) {
StructField field = structType.getFields().get(i);
fieldDesc.add(field.getName() + ":" + field.getType().hideVersionForVersionColumn(isToSql));
}
return "STRUCT<" + StringUtils.join(fieldDesc, ",") + ">";
return "struct<" + StringUtils.join(fieldDesc, ",") + ">";
} else if (isToSql) {
return this.toSql();
}
Expand Down

0 comments on commit e79abe6

Please sign in to comment.