Skip to content

Commit

Permalink
update fe code
Browse files Browse the repository at this point in the history
  • Loading branch information
amorynan committed Jan 9, 2025
1 parent b69c345 commit 6295442
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
26 changes: 17 additions & 9 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 @@ -523,38 +523,46 @@ public boolean isDecimalV3OrContainsDecimalV3() {
return false;
}

// This method defines the char type or complex type nested char type
// This method defines the char type
// to support the schema-change behavior of length growth.
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()) {
throw new TypeException("Cannot shorten string length for type "
+ this.toSql() + " to " + other.toSql());
throw new TypeException("Cannot shorten string length");
} else {
return true;
}
} else if (this.isStructType() && other.isStructType()) {
}
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 boolean isSupportSchemaChangeForComplexType(Type other) throws TypeException {
if (this.isStructType() && other.isStructType()) {
StructType thisStructType = (StructType) this;
StructType otherStructType = (StructType) other;
if (thisStructType.getFields().size() != otherStructType.getFields().size()) {
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(
if (!thisStructType.getFields().get(i).getType().isSupportSchemaChangeForComplexType(
otherStructType.getFields().get(i).getType())) {
throw new TypeException("Cannot change struct type with different field type");
}
}
} else if (this.isArrayType() && other.isArrayType()) {
return ((ArrayType) this).getItemType().isSupportSchemaChangeForCharType(((ArrayType) other).getItemType());
return ((ArrayType) this).getItemType().isSupportSchemaChangeForComplexType(
((ArrayType) other).getItemType());
} else if (this.isMapType() && other.isMapType()) {
return ((MapType) this).getKeyType().isSupportSchemaChangeForCharType(((MapType) other).getKeyType())
return ((MapType) this).getKeyType().isSupportSchemaChangeForComplexType(((MapType) other).getKeyType())
&&
((MapType) this).getValueType().isSupportSchemaChangeForCharType(((MapType) other).getValueType());
((MapType) this).getValueType().isSupportSchemaChangeForComplexType(
((MapType) other).getValueType());
}
return false;
return isSupportSchemaChangeForCharType(other);
}

public boolean isDecimalV3() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.catalog.Tablet;
import org.apache.doris.catalog.TabletMeta;
import org.apache.doris.catalog.TypeException;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.DdlException;
Expand Down Expand Up @@ -627,11 +628,25 @@ private boolean processModifyColumn(ModifyColumnClause alterClause, OlapTable ol
if (!col.equals(modColumn)) {
typeChanged = true;
// TODO:the case where columnPos is not empty has not been considered
if (columnPos == null && ((col.getDataType() == PrimitiveType.VARCHAR
&& modColumn.getDataType() == PrimitiveType.VARCHAR)
|| col.getDataType().isComplexType())) {
col.checkSchemaChangeAllowed(modColumn);
lightSchemaChange = olapTable.getEnableLightSchemaChange();
if (columnPos == null && col.getDataType() == PrimitiveType.VARCHAR
&& modColumn.getDataType() == PrimitiveType.VARCHAR) {
try {
if (col.getType().isSupportSchemaChangeForCharType(modColumn.getType())) {
lightSchemaChange = olapTable.getEnableLightSchemaChange();
}
} catch (TypeException e) {
throw new DdlException(e.getMessage());
}
}
if (columnPos == null && col.getDataType().isComplexType()
&& modColumn.getDataType().isComplexType()) {
try {
if (col.getType().isSupportSchemaChangeForComplexType(modColumn.getType())) {
lightSchemaChange = olapTable.getEnableLightSchemaChange();
}
} catch (TypeException e) {
throw new DdlException(e.getMessage());
}
}
if (col.isClusterKey()) {
throw new DdlException("Can not modify cluster key column: " + col.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,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
try {
if (!type.isSupportSchemaChangeForCharType(other.type)) {
if (!type.isSupportSchemaChangeForComplexType(other.type)) {
throw new DdlException("Can not change " + type.toSql() + " to " + other.type.toSql());
}
} catch (TypeException e) {
Expand Down

0 comments on commit 6295442

Please sign in to comment.