From 9679ebe1ccaf7fa753646f6a8328e26895caf28f Mon Sep 17 00:00:00 2001 From: meiyi Date: Wed, 27 Sep 2023 18:46:53 +0800 Subject: [PATCH] [fix](schema) Table column order is changed if add a column and do truncate --- .../doris/datasource/InternalCatalog.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) 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 c0db722e17bcc3..8c710adc800b8a 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 @@ -1615,17 +1615,19 @@ public void addPartition(Database db, String tableName, AddPartitionClause addPa List oldSchema = indexIdToMeta.get(indexId).getSchema(); List 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)); + List oldSchemaCopy = Lists.newArrayList(oldSchema); + List newSchemaCopy = Lists.newArrayList(newSchema); + oldSchemaCopy.sort((Column a, Column b) -> a.getUniqueId() - b.getUniqueId()); + newSchemaCopy.sort((Column a, Column b) -> a.getUniqueId() - b.getUniqueId()); + for (int i = 0; i < oldSchemaCopy.size(); ++i) { + if (!oldSchemaCopy.get(i).equals(newSchemaCopy.get(i))) { + LOG.warn("schema diff, old schema {}, new schema {}", oldSchemaCopy.get(i), + newSchemaCopy.get(i)); metaChanged = true; break; } @@ -3014,15 +3016,18 @@ public void truncateTable(TruncateTableStmt truncateTableStmt) throws DdlExcepti List oldSchema = copiedTbl.getFullSchema(); List 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)); + List oldSchemaCopy = Lists.newArrayList(oldSchema); + List newSchemaCopy = Lists.newArrayList(newSchema); + oldSchemaCopy.sort((Column a, Column b) -> a.getUniqueId() - b.getUniqueId()); + newSchemaCopy.sort((Column a, Column b) -> a.getUniqueId() - b.getUniqueId()); + for (int i = 0; i < oldSchemaCopy.size(); ++i) { + if (!oldSchemaCopy.get(i).equals(newSchemaCopy.get(i))) { + LOG.warn("schema diff, old schema {}, new schema {}", oldSchemaCopy.get(i), + newSchemaCopy.get(i)); metaChanged = true; break; }