Skip to content

Commit

Permalink
fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
amorynan committed Jan 9, 2025
1 parent e011431 commit ac1d2f0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
13 changes: 6 additions & 7 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 @@ -513,29 +513,28 @@ public boolean isDecimalV3OrContainsDecimalV3() {

// This method defines the char type or complex type nested char type
// to support the schema-change behavior of length growth.
public boolean isSupportSchemaChangeForCharType(Type other) {
public boolean isSupportSchemaChangeForCharType(Type other) throws TypeException {
if ((this.getPrimitiveType() == PrimitiveType.VARCHAR && other.getPrimitiveType() == PrimitiveType.VARCHAR) || (
this.getPrimitiveType() == PrimitiveType.CHAR && other.getPrimitiveType() == PrimitiveType.VARCHAR) || (
this.getPrimitiveType() == PrimitiveType.CHAR && other.getPrimitiveType() == PrimitiveType.CHAR)) {
if (this.getLength() > other.getLength()) {
return false;
throw new TypeException("Cannot shorten string length for type "
+ this.toSql() + " to " + other.toSql());
} else {
return true;
}
}
if (this.isStructType() && other.isStructType()) {
} else if (this.isStructType() && other.isStructType()) {
StructType thisStructType = (StructType) this;
StructType otherStructType = (StructType) other;
if (thisStructType.getFields().size() != otherStructType.getFields().size()) {
return false;
throw new TypeException("Cannot change struct type with different field size");
}
for (int i = 0; i < thisStructType.getFields().size(); i++) {
if (!thisStructType.getFields().get(i).getType().isSupportSchemaChangeForCharType(
otherStructType.getFields().get(i).getType())) {
return false;
throw new TypeException("Cannot change struct type with different field type");
}
}
return true;
} else if (this.isArrayType() && other.isArrayType()) {
return ((ArrayType) this).getItemType().isSupportSchemaChangeForCharType(((ArrayType) other).getItemType());
} else if (this.isMapType() && other.isMapType()) {
Expand Down
8 changes: 6 additions & 2 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,12 @@ public void checkSchemaChangeAllowed(Column other) throws DdlException {

// Nested types only support changing the order and increasing the length of the nested char type
// Char-type only support length growing
if (!type.isSupportSchemaChangeForCharType(other.type)) {
throw new DdlException("Cannot shorten string length for type " + type.toSql() + " to " + other.toSql());
try {
if (!type.isSupportSchemaChangeForCharType(other.type)) {
throw new DdlException("Can not change " + type.toSql() + " to " + other.type.toSql());
}
} catch (TypeException e) {
throw new DdlException(e.getMessage());
}

// now we support convert decimal to varchar type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,44 @@ suite ("test_varchar_sc_in_complex") {
exception "Cannot shorten string length"
}

// add case alter modify array/map/struct to other type
// test array to struct
test {
sql """ alter table ${tableName} modify column c_a struct<col:varchar(3)>
"""
exception "Cannot chang"
}
// test array to map
test {
sql """ alter table ${tableName} modify column c_a map<varchar(3),varchar(3)>
"""
exception "Cannot chang"
}
// test map to array
test {
sql """ alter table ${tableName} modify column c_m array<varchar(3)>
"""
exception "Cannot chang"
}
// test map to struct
test {
sql """ alter table ${tableName} modify column c_m struct<col:varchar(3)>
"""
exception "Cannot chang"
}
// test struct to array
test {
sql """ alter table ${tableName} modify column c_s array<varchar(3)>
"""
exception "Cannot chang"
}
// test struct to map
test {
sql """ alter table ${tableName} modify column c_s map<varchar(3),varchar(3)>
"""
exception "Cannot chang"
}


sql """ alter table ${tableName} modify column c_a array<varchar(20)> """
int max_try_secs = 300
Expand Down

0 comments on commit ac1d2f0

Please sign in to comment.