This is an automated email from the ASF dual-hosted git repository. kxiao pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
commit a3cecb31c3d9fd367d440657456f97489f3864e9 Author: Luwei <[email protected]> AuthorDate: Thu Sep 21 20:35:45 2023 +0800 [enhancement](schema) Add schema consistency check when add partition (#24707) --- .../apache/doris/datasource/InternalCatalog.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index 0720e52207..979bdf6692 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -1592,9 +1592,30 @@ public class InternalCatalog implements CatalogIf<Database> { metaChanged = true; break; } + + List<Column> oldSchema = indexIdToMeta.get(indexId).getSchema(); + List<Column> newSchema = entry.getValue().getSchema(); + oldSchema.sort((Column a, Column b) -> a.getUniqueId() - b.getUniqueId()); + newSchema.sort((Column a, Column b) -> a.getUniqueId() - b.getUniqueId()); + if (oldSchema.size() != newSchema.size()) { + LOG.warn("schema column size diff, old schema {}, new schema {}", oldSchema, newSchema); + metaChanged = true; + break; + } else { + for (int i = 0; i < oldSchema.size(); ++i) { + if (!oldSchema.get(i).equals(newSchema.get(i))) { + LOG.warn("schema diff, old schema {}, new schema {}", + oldSchema.get(i), newSchema.get(i)); + metaChanged = true; + break; + } + } + } } } + + if (metaChanged) { throw new DdlException("Table[" + tableName + "]'s meta has been changed. try again."); } @@ -2945,6 +2966,23 @@ public class InternalCatalog implements CatalogIf<Database> { break; } } + + List<Column> oldSchema = copiedTbl.getFullSchema(); + List<Column> newSchema = olapTable.getFullSchema(); + oldSchema.sort((Column a, Column b) -> a.getUniqueId() - b.getUniqueId()); + newSchema.sort((Column a, Column b) -> a.getUniqueId() - b.getUniqueId()); + if (oldSchema.size() != newSchema.size()) { + LOG.warn("schema column size diff, old schema {}, new schema {}", oldSchema, newSchema); + metaChanged = true; + } else { + for (int i = 0; i < oldSchema.size(); ++i) { + if (!oldSchema.get(i).equals(newSchema.get(i))) { + LOG.warn("schema diff, old schema {}, new schema {}", oldSchema.get(i), newSchema.get(i)); + metaChanged = true; + break; + } + } + } } if (metaChanged) { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
