From 79ae7af2b85c1d31cb4048ea05d99712dc91c2e4 Mon Sep 17 00:00:00 2001 From: wyxxxcat Date: Sun, 19 Jan 2025 21:07:53 +0800 Subject: [PATCH] 1 --- .../apache/doris/analysis/AlterTableStmt.java | 7 +++++-- .../doris/analysis/AlterTableStmtTest.java | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStmt.java index cb3925cc444391..7e48c33b5b2e67 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStmt.java @@ -33,6 +33,7 @@ import org.apache.doris.qe.ConnectContext; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,10 +41,12 @@ public class AlterTableStmt extends DdlStmt implements NotFallbackInParser { private TableName tbl; private List ops; + private List originOps; public AlterTableStmt(TableName tbl, List ops) { this.tbl = tbl; this.ops = ops; + this.originOps = ops; } public void setTableName(String newTableName) { @@ -104,7 +107,7 @@ public void rewriteAlterClause(OlapTable table) throws UserException { // analyse sequence column Type sequenceColType = null; if (alterFeature == EnableFeatureClause.Features.SEQUENCE_LOAD) { - Map propertyMap = alterClause.getProperties(); + Map propertyMap = new HashMap<>(alterClause.getProperties()); try { sequenceColType = PropertyAnalyzer.analyzeSequenceType(propertyMap, table.getKeysType()); if (sequenceColType == null) { @@ -181,7 +184,7 @@ public String toSql() { StringBuilder sb = new StringBuilder(); sb.append("ALTER TABLE ").append(tbl.toSql()).append(" "); int idx = 0; - for (AlterClause op : ops) { + for (AlterClause op : originOps) { if (idx != 0) { sb.append(", \n"); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/AlterTableStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/AlterTableStmtTest.java index c968f21d670200..61192f202d9224 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/AlterTableStmtTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/AlterTableStmtTest.java @@ -32,6 +32,7 @@ import org.junit.Before; import org.junit.Test; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -178,4 +179,24 @@ public void testDropIndexStmt() throws UserException { Assert.assertEquals("DROP INDEX `index1` ON `db`.`table`", dropIndexClause.toSql()); Assert.assertEquals("ALTER TABLE `testDb`.`testTbl` DROP INDEX `index1`", stmt.toSql()); } + + @Test + public void testEnableFeatureClause() { + List ops = Lists.newArrayList(); + ops.add(new EnableFeatureClause("BATCH_DELETE")); + AlterTableStmt alterTableStmt = new AlterTableStmt(new TableName(internalCtl, "db", "test"), ops); + Assert.assertEquals(alterTableStmt.toSql(), "ALTER TABLE `db`.`test` ENABLE FEATURE \"BATCH_DELETE\""); + ops.clear(); + ops.add(new EnableFeatureClause("UPDATE_FLEXIBLE_COLUMNS")); + alterTableStmt = new AlterTableStmt(new TableName(internalCtl, "db", "test"), ops); + Assert.assertEquals(alterTableStmt.toSql(), + "ALTER TABLE `db`.`test` ENABLE FEATURE \"UPDATE_FLEXIBLE_COLUMNS\""); + ops.clear(); + Map properties = new HashMap<>(); + properties.put("function_column.sequence_type", "int"); + ops.add(new EnableFeatureClause("SEQUENCE_LOAD", properties)); + alterTableStmt = new AlterTableStmt(new TableName(internalCtl, "db", "test"), ops); + Assert.assertEquals(alterTableStmt.toSql(), + "ALTER TABLE `db`.`test` ENABLE FEATURE \"SEQUENCE_LOAD\" WITH PROPERTIES (\"function_column.sequence_type\" = \"int\")"); + } }