eldenmoon commented on code in PR #47096: URL: https://github.com/apache/doris/pull/47096#discussion_r1994656203
########## fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnType.java: ########## @@ -208,12 +210,48 @@ public static void checkSupportSchemaChangeForComplexType(Type checkType, Type o 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"); + // now we only support add new field for struct type + if (thisStructType.getFields().size() > otherStructType.getFields().size()) { + throw new DdlException("Cannot reduce struct fields from " + checkType.toSql() + " to " + + other.toSql()); } - for (int i = 0; i < thisStructType.getFields().size(); i++) { + int i = 0; + HashSet<String> thisStructNames = new HashSet<>(); + for (; i < thisStructType.getFields().size(); i++) { + // do not support struct same position field name/type change + StructField thisField = thisStructType.getFields().get(i); + StructField otherField = otherStructType.getFields().get(i); + if (!thisField.equals(otherField)) { + // name and type are changed will throw exception + if (!thisField.getName().equals(otherField.getName())) { + throw new DdlException("Cannot change name in struct" + thisField.getName() + " to " + + otherField.getName()); + } + if (!thisField.getType().equals(otherField.getType())) { + if (thisField.getType().isStringType() && otherField.getType().isStringType()) { + // check string type + // check length growth later in checkSupportSchemaChangeForCharType + checkSupportSchemaChangeForCharType(thisStructType.getFields().get(i).getType(), + otherStructType.getFields().get(i).getType()); + } else if (thisField.getType().isComplexType() && otherField.getType().isComplexType()) { + // check complex type recursively + checkSupportSchemaChangeForComplexType(thisStructType.getFields().get(i).getType(), Review Comment: what if struct<array<int>> vs struct<struct<a:int>> will line 256 has problem? ########## fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnType.java: ########## @@ -208,12 +210,48 @@ public static void checkSupportSchemaChangeForComplexType(Type checkType, Type o 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"); + // now we only support add new field for struct type + if (thisStructType.getFields().size() > otherStructType.getFields().size()) { + throw new DdlException("Cannot reduce struct fields from " + checkType.toSql() + " to " + + other.toSql()); } - for (int i = 0; i < thisStructType.getFields().size(); i++) { + int i = 0; + HashSet<String> thisStructNames = new HashSet<>(); + for (; i < thisStructType.getFields().size(); i++) { + // do not support struct same position field name/type change + StructField thisField = thisStructType.getFields().get(i); + StructField otherField = otherStructType.getFields().get(i); + if (!thisField.equals(otherField)) { + // name and type are changed will throw exception + if (!thisField.getName().equals(otherField.getName())) { + throw new DdlException("Cannot change name in struct" + thisField.getName() + " to " + + otherField.getName()); + } + if (!thisField.getType().equals(otherField.getType())) { + if (thisField.getType().isStringType() && otherField.getType().isStringType()) { + // check string type + // check length growth later in checkSupportSchemaChangeForCharType + checkSupportSchemaChangeForCharType(thisStructType.getFields().get(i).getType(), + otherStructType.getFields().get(i).getType()); + } else if (thisField.getType().isComplexType() && otherField.getType().isComplexType()) { + // check complex type recursively + checkSupportSchemaChangeForComplexType(thisStructType.getFields().get(i).getType(), Review Comment: what if struct<array<int>> vs struct<struct<a:int>> will line 256 has problem? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org