Skip to content

Commit

Permalink
add return value for function
Browse files Browse the repository at this point in the history
  • Loading branch information
amorynan committed Jan 13, 2025
1 parent 8d480bf commit 6be4564
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ private boolean processModifyColumn(ModifyColumnClause alterClause, OlapTable ol
}
if (columnPos == null && col.getDataType().isComplexType()
&& modColumn.getDataType().isComplexType()) {
ColumnType.checkSupportSchemaChangeForComplexType(col.getType(), modColumn.getType());
ColumnType.checkSupportSchemaChangeForComplexType(col.getType(), modColumn.getType(), true);
lightSchemaChange = olapTable.getEnableLightSchemaChange();
}
if (col.isClusterKey()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ 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
ColumnType.checkSupportSchemaChangeForComplexType(type, other.type);
ColumnType.checkSupportSchemaChangeForComplexType(type, other.type, false);

// now we support convert decimal to varchar type
if ((getDataType() == PrimitiveType.DECIMALV2 || getDataType().isDecimalV3Type())
Expand Down
34 changes: 19 additions & 15 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnType.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ static boolean isSchemaChangeAllowed(Type lhs, Type rhs) {

// This method defines the char type
// to support the schema-change behavior of length growth.
public static void checkSupportSchemaChangeForCharType(Type checkType, Type other) throws DdlException {
// return true if the checkType and other are both char-type otherwise return false,
// which used in checkSupportSchemaChangeForComplexType
public static boolean checkSupportSchemaChangeForCharType(Type checkType, Type other) throws DdlException {
if ((checkType.getPrimitiveType() == PrimitiveType.VARCHAR && other.getPrimitiveType() == PrimitiveType.VARCHAR)
|| (checkType.getPrimitiveType() == PrimitiveType.CHAR
&& other.getPrimitiveType() == PrimitiveType.VARCHAR)
Expand All @@ -180,41 +182,43 @@ public static void checkSupportSchemaChangeForCharType(Type checkType, Type othe
if (checkType.getLength() > other.getLength()) {
throw new DdlException("Cannot shorten string length");
}
return true;
} else {
return false;
}
}

// This method defines the complex type which is struct, array, map if nested char-type
// to support the schema-change behavior of length growth.
public static void checkSupportSchemaChangeForComplexType(Type checkType, Type other) throws DdlException {
if (checkType.isStructType()) {
if (!other.isStructType()) {
throw new DdlException("Cannot change " + checkType.toSql() + " to " + other.toSql());
}
public static void checkSupportSchemaChangeForComplexType(Type checkType, Type other, boolean nested)
throws DdlException {
if (checkType.isStructType() && other.isStructType()) {
StructType thisStructType = (StructType) checkType;
StructType otherStructType = (StructType) other;
if (thisStructType.getFields().size() != otherStructType.getFields().size()) {
throw new DdlException("Cannot change struct type with different field size");
}
for (int i = 0; i < thisStructType.getFields().size(); i++) {
checkSupportSchemaChangeForComplexType(thisStructType.getFields().get(i).getType(),
otherStructType.getFields().get(i).getType());
otherStructType.getFields().get(i).getType(), true);
}
} else if (checkType.isArrayType()) {
if (!other.isArrayType()) {
throw new DdlException("Cannot change " + checkType.toSql() + " to " + other.toSql());
}
checkSupportSchemaChangeForComplexType(((ArrayType) checkType).getItemType(),
((ArrayType) other).getItemType());
} else if (checkType.isMapType()) {
if (!other.isMapType()) {
throw new DdlException("Cannot change " + checkType.toSql() + " to " + other.toSql());
}
((ArrayType) other).getItemType(), true);
} else if (checkType.isMapType() && other.isMapType()) {
checkSupportSchemaChangeForComplexType(((MapType) checkType).getKeyType(),
((MapType) other).getKeyType());
((MapType) other).getKeyType(), true);
checkSupportSchemaChangeForComplexType(((MapType) checkType).getValueType(),
((MapType) other).getValueType());
((MapType) other).getValueType(), true);
} else {
checkSupportSchemaChangeForCharType(checkType, other);
// only support char-type schema change behavior for nested complex type
// if nested is false, we do not check return value.
if (nested && !checkSupportSchemaChangeForCharType(checkType, other)) {
throw new DdlException("Cannot change " + checkType.toSql() + " to " + other.toSql());
}
}
}

Expand Down

0 comments on commit 6be4564

Please sign in to comment.