This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 80c75b6da4f [fix](schema change) fix bug of query failure after rename column (#26300) 80c75b6da4f is described below commit 80c75b6da4fd31f06cca0f1cd483908226d9193c Author: Luwei <814383...@qq.com> AuthorDate: Mon Nov 20 16:54:40 2023 +0800 [fix](schema change) fix bug of query failure after rename column (#26300) --- .../main/java/org/apache/doris/catalog/Env.java | 18 ++++++-- .../doris/persist/TableRenameColumnInfo.java | 14 ++++++- .../test_alter_table_column_rename.groovy | 49 ++++++++++++++++++++++ 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java index d558f88692a..09e5b1ef0dd 100755 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java @@ -4360,7 +4360,8 @@ public class Env { } private void renameColumn(Database db, OlapTable table, String colName, - String newColName, boolean isReplay) throws DdlException { + String newColName, Map<Long, Integer> indexIdToSchemaVersion, + boolean isReplay) throws DdlException { table.checkNormalStateForAlter(); if (colName.equalsIgnoreCase(newColName)) { throw new DdlException("Same column name"); @@ -4406,6 +4407,12 @@ public class Env { Env.getCurrentEnv().getQueryStats() .rename(Env.getCurrentEnv().getCurrentCatalog().getId(), db.getId(), table.getId(), entry.getKey(), colName, newColName); + if (!isReplay) { + indexIdToSchemaVersion.put(entry.getKey(), entry.getValue().getSchemaVersion() + 1); + } + if (indexIdToSchemaVersion != null) { + entry.getValue().setSchemaVersion(indexIdToSchemaVersion.get(entry.getKey())); + } } } if (!hasColumn) { @@ -4466,7 +4473,8 @@ public class Env { if (!isReplay) { // log - TableRenameColumnInfo info = new TableRenameColumnInfo(db.getId(), table.getId(), colName, newColName); + TableRenameColumnInfo info = new TableRenameColumnInfo(db.getId(), table.getId(), colName, newColName, + indexIdToSchemaVersion); editLog.logColumnRename(info); LOG.info("rename coloumn[{}] to {}", colName, newColName); } @@ -4477,7 +4485,8 @@ public class Env { try { String colName = renameClause.getColName(); String newColName = renameClause.getNewColName(); - renameColumn(db, table, colName, newColName, false); + Map<Long, Integer> indexIdToSchemaVersion = new HashMap<Long, Integer>(); + renameColumn(db, table, colName, newColName, indexIdToSchemaVersion, false); } finally { table.writeUnlock(); } @@ -4489,12 +4498,13 @@ public class Env { long tableId = info.getTableId(); String colName = info.getColName(); String newColName = info.getNewColName(); + Map<Long, Integer> indexIdToSchemaVersion = info.getIndexIdToSchemaVersion(); Database db = getCurrentEnv().getInternalCatalog().getDbOrMetaException(dbId); OlapTable table = (OlapTable) db.getTableOrMetaException(tableId, TableType.OLAP); table.writeLock(); try { - renameColumn(db, table, colName, newColName, true); + renameColumn(db, table, colName, newColName, indexIdToSchemaVersion, true); } catch (DdlException e) { // should not happen LOG.warn("failed to replay rename column", e); diff --git a/fe/fe-core/src/main/java/org/apache/doris/persist/TableRenameColumnInfo.java b/fe/fe-core/src/main/java/org/apache/doris/persist/TableRenameColumnInfo.java index aec3a56a4fc..eafdb943e11 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/persist/TableRenameColumnInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/persist/TableRenameColumnInfo.java @@ -26,6 +26,7 @@ import com.google.gson.annotations.SerializedName; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; +import java.util.Map; /** * PersistInfo for Table rename column info @@ -39,13 +40,16 @@ public class TableRenameColumnInfo implements Writable { private String colName; @SerializedName(value = "newColName") private String newColName; + @SerializedName(value = "indexIdToSchemaVersion") + private Map<Long, Integer> indexIdToSchemaVersion; public TableRenameColumnInfo(long dbId, long tableId, - String colName, String newColName) { + String colName, String newColName, Map<Long, Integer> indexIdToSchemaVersion) { this.dbId = dbId; this.tableId = tableId; this.colName = colName; this.newColName = newColName; + this.indexIdToSchemaVersion = indexIdToSchemaVersion; } public long getDbId() { @@ -64,6 +68,10 @@ public class TableRenameColumnInfo implements Writable { return newColName; } + public Map<Long, Integer> getIndexIdToSchemaVersion() { + return indexIdToSchemaVersion; + } + @Override public void write(DataOutput out) throws IOException { Text.writeString(out, GsonUtils.GSON.toJson(this)); @@ -86,7 +94,8 @@ public class TableRenameColumnInfo implements Writable { TableRenameColumnInfo info = (TableRenameColumnInfo) obj; return (dbId == info.dbId && tableId == info.tableId - && colName.equals(info.colName) && newColName.equals(info.newColName)); + && colName.equals(info.colName) && newColName.equals(info.newColName) + && indexIdToSchemaVersion.equals(info.indexIdToSchemaVersion)); } @Override @@ -96,6 +105,7 @@ public class TableRenameColumnInfo implements Writable { sb.append(" tableId: ").append(tableId); sb.append(" colName: ").append(colName); sb.append(" newColName: ").append(newColName); + sb.append(" indexIdToSchemaVersion: ").append(indexIdToSchemaVersion.toString()); return sb.toString(); } } diff --git a/regression-test/suites/schema_change_p0/test_alter_table_column_rename.groovy b/regression-test/suites/schema_change_p0/test_alter_table_column_rename.groovy new file mode 100644 index 00000000000..3650b93ccbb --- /dev/null +++ b/regression-test/suites/schema_change_p0/test_alter_table_column_rename.groovy @@ -0,0 +1,49 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_alter_table_column_rename") { + def tbName = "alter_table_column_rename" + + sql "DROP TABLE IF EXISTS ${tbName}" + sql """ + CREATE TABLE IF NOT EXISTS ${tbName} ( + k1 INT NOT NULL, + value1 varchar(16) NOT NULL, + value2 int NOT NULL + ) + DUPLICATE KEY (k1) + DISTRIBUTED BY HASH(k1) BUCKETS 1 properties("replication_num" = "1"); + """ + + sql """ insert into ${tbName} values (1, 'a', 2) """ + sql """ select * from ${tbName} """ + + // rename column name + sql """ ALTER TABLE ${tbName} RENAME COLUMN value2 new_col """ + + List<List<Object>> result = sql """ show frontends """ + for (row : result) { + //println row + String jdbcUrl = "jdbc:mysql://" + row[1] + ":" + row[4] + def result1 = connect(user = 'root', password = '', jdbcUrl) { + sql """ SYNC """ + sql """ use regression_test_schema_change_p0 """ + sql """ select * from ${tbName} where new_col = 2 """ + } + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org