[fix](schema) Table column order is changed if add a column and do truncate (#24981)

This commit is contained in:
meiyi
2023-09-27 20:59:11 +08:00
committed by GitHub
parent 63b283a848
commit 391a4e29eb

View File

@ -1615,17 +1615,19 @@ public class InternalCatalog implements CatalogIf<Database> {
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));
List<Column> oldSchemaCopy = Lists.newArrayList(oldSchema);
List<Column> 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 class InternalCatalog implements CatalogIf<Database> {
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));
List<Column> oldSchemaCopy = Lists.newArrayList(oldSchema);
List<Column> 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;
}