Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@
import org.apache.doris.qe.ConnectContext;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

// Alter table statement.
public class AlterTableStmt extends DdlStmt implements NotFallbackInParser {
private TableName tbl;
private List<AlterClause> ops;
private List<AlterClause> originOps;

public AlterTableStmt(TableName tbl, List<AlterClause> ops) {
this.tbl = tbl;
this.ops = ops;
this.originOps = ops;
}

public void setTableName(String newTableName) {
Expand Down Expand Up @@ -104,7 +107,7 @@ public void rewriteAlterClause(OlapTable table) throws UserException {
// analyse sequence column
Type sequenceColType = null;
if (alterFeature == EnableFeatureClause.Features.SEQUENCE_LOAD) {
Map<String, String> propertyMap = alterClause.getProperties();
Map<String, String> propertyMap = new HashMap<>(alterClause.getProperties());
try {
sequenceColType = PropertyAnalyzer.analyzeSequenceType(propertyMap, table.getKeysType());
if (sequenceColType == null) {
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.junit.Before;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -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<AlterClause> 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<String, String> 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\")");
}
}
Loading