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 @@ -200,6 +200,14 @@ under the License.
note:
1)Only support non colocate table with RANGE partition and HASH distribution

10. Modify table comment
grammer:
MODIFY COMMENT "new table comment"

11. Modify column comment
grammer:
MODIFY COLUMN col1 COMMENT "new column comment"


Rename supports modification of the following names:
1. Modify the table name
Expand Down Expand Up @@ -379,6 +387,14 @@ under the License.
18. Modify the default buckets number of example_db.my_table to 50

ALTER TABLE example_db.my_table MODIFY DISTRIBUTION DISTRIBUTED BY HASH(k1) BUCKETS 50;

19. Modify table comment

ALTER TABLE example_db.my_table MODIFY COMMENT "new comment";

20. Modify column comment

ALTER TABLE example_db.my_table MODIFY COLUMN k1 COMMENT "k1", MODIFY COLUMN k2 COMMENT "k2";

[rename]
1. Modify the table named table1 to table2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ under the License.
注意:
1)只能用在分区类型为RANGE,采用哈希分桶的非colocate表

10. 修改表注释
语法:
MODIFY COMMENT "new table comment"

11. 修改列注释
语法:
MODIFY COLUMN col1 COMMENT "new column comment"

rename 支持对以下名称进行修改:
1. 修改表名
Expand All @@ -211,13 +218,15 @@ under the License.
3. 修改 partition 名称
语法:
RENAME PARTITION old_partition_name new_partition_name;

bitmap index 支持如下几种修改方式
1. 创建bitmap 索引
语法:
ADD INDEX index_name (column [, ...],) [USING BITMAP] [COMMENT 'balabala'];
注意:
1. 目前仅支持bitmap 索引
1. BITMAP 索引仅在单列上创建

2. 删除索引
语法:
DROP INDEX index_name;
Expand Down Expand Up @@ -373,6 +382,14 @@ under the License.
18. 将表的默认分桶数改为50

ALTER TABLE example_db.my_table MODIFY DISTRIBUTION DISTRIBUTED BY HASH(k1) BUCKETS 50;

19. 修改表注释

ALTER TABLE example_db.my_table MODIFY COMMENT "new comment";

20. 修改列注释

ALTER TABLE example_db.my_table MODIFY COLUMN k1 COMMENT "k1", MODIFY COLUMN k2 COMMENT "k2";

[rename]
1. 将名为 table1 的表修改为 table2
Expand Down
8 changes: 8 additions & 0 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,14 @@ alter_table_clause ::=
{:
RESULT = new ModifyDistributionClause(distribution);
:}
| KW_MODIFY KW_COMMENT STRING_LITERAL:comment
{:
RESULT = new ModifyTableCommentClause(comment);
:}
| KW_MODIFY KW_COLUMN ident:colName KW_COMMENT STRING_LITERAL:comment
{:
RESULT = new ModifyColumnCommentClause(colName, comment);
:}
;

opt_enable_feature_properties ::=
Expand Down
94 changes: 91 additions & 3 deletions fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import org.apache.doris.analysis.CreateMaterializedViewStmt;
import org.apache.doris.analysis.DropMaterializedViewStmt;
import org.apache.doris.analysis.DropPartitionClause;
import org.apache.doris.analysis.ModifyColumnCommentClause;
import org.apache.doris.analysis.ModifyDistributionClause;
import org.apache.doris.analysis.ModifyPartitionClause;
import org.apache.doris.analysis.ModifyTableCommentClause;
import org.apache.doris.analysis.ModifyTablePropertiesClause;
import org.apache.doris.analysis.PartitionRenameClause;
import org.apache.doris.analysis.ReplacePartitionClause;
Expand Down Expand Up @@ -56,17 +58,19 @@
import org.apache.doris.common.util.PropertyAnalyzer;
import org.apache.doris.persist.AlterViewInfo;
import org.apache.doris.persist.BatchModifyPartitionsInfo;
import org.apache.doris.persist.ModifyCommentOperationLog;
import org.apache.doris.persist.ModifyPartitionInfo;
import org.apache.doris.persist.ReplaceTableOperationLog;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.thrift.TTabletType;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -196,13 +200,97 @@ private boolean processAlterOlapTable(AlterTableStmt stmt, OlapTable olapTable,
Preconditions.checkState(alterClauses.size() == 1);
AlterClause alterClause = alterClauses.get(0);
Catalog.getCurrentCatalog().modifyDefaultDistributionBucketNum(db, olapTable, (ModifyDistributionClause) alterClause);
} else if (currentAlterOps.contains(AlterOpType.MODIFY_COLUMN_COMMENT)) {
processModifyColumnComment(db, olapTable, alterClauses);
} else if (currentAlterOps.contains(AlterOpType.MODIFY_TABLE_COMMENT)) {
Preconditions.checkState(alterClauses.size() == 1);
AlterClause alterClause = alterClauses.get(0);
processModifyTableComment(db, olapTable, alterClause);
} else {
throw new DdlException("Invalid alter operations: " + currentAlterOps);
}

return needProcessOutsideTableLock;
}

private void processModifyTableComment(Database db, OlapTable tbl, AlterClause alterClause)
throws DdlException {
tbl.writeLock();
try {
ModifyTableCommentClause clause = (ModifyTableCommentClause) alterClause;
tbl.setComment(clause.getComment());
// log
ModifyCommentOperationLog op = ModifyCommentOperationLog.forTable(db.getId(), tbl.getId(), clause.getComment());
Catalog.getCurrentCatalog().getEditLog().logModifyComment(op);
} finally {
tbl.writeUnlock();
}
}

private void processModifyColumnComment(Database db, OlapTable tbl, List<AlterClause> alterClauses)
throws DdlException {
tbl.writeLock();
try {
// check first
Map<String, String> colToComment = Maps.newHashMap();
for (AlterClause alterClause : alterClauses) {
Preconditions.checkState(alterClause instanceof ModifyColumnCommentClause);
ModifyColumnCommentClause clause = (ModifyColumnCommentClause) alterClause;
String colName = clause.getColName();
if (tbl.getColumn(colName) == null) {
throw new DdlException("Unknown column: " + colName);
}
if (colToComment.containsKey(colName)) {
throw new DdlException("Duplicate column: " + colName);
}
colToComment.put(colName, clause.getComment());
}

// modify comment
for (Map.Entry<String, String> entry : colToComment.entrySet()) {
Column col = tbl.getColumn(entry.getKey());
col.setComment(entry.getValue());
}

// log
ModifyCommentOperationLog op = ModifyCommentOperationLog.forColumn(db.getId(), tbl.getId(), colToComment);
Catalog.getCurrentCatalog().getEditLog().logModifyComment(op);
} finally {
tbl.writeUnlock();
}
}

public void replayModifyComment(ModifyCommentOperationLog operation) {
long dbId = operation.getDbId();
long tblId = operation.getTblId();
Database db = Catalog.getCurrentCatalog().getDb(dbId);
if (db == null) {
return;
}
Table tbl = db.getTable(tblId);
if (tbl == null) {
return;
}
tbl.writeLock();
try {
ModifyCommentOperationLog.Type type = operation.getType();
switch (type) {
case TABLE:
tbl.setComment(operation.getTblComment());
break;
case COLUMN:
for (Map.Entry<String, String> entry : operation.getColToComment().entrySet()) {
tbl.getColumn(entry.getKey()).setComment(entry.getValue());
}
break;
default:
break;
}
} finally {
tbl.writeUnlock();
}
}

private void processAlterExternalTable(AlterTableStmt stmt, Table externalTable, Database db) throws UserException {
stmt.rewriteAlterClause(externalTable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public enum AlterOpType {
ENABLE_FEATURE,
REPLACE_TABLE,
MODIFY_DISTRIBUTION,
MODIFY_TABLE_COMMENT,
MODIFY_COLUMN_COMMENT,
INVALID_OP; // INVALID_OP must be the last one

// true means 2 operations have no conflict.
Expand All @@ -55,6 +57,8 @@ public enum AlterOpType {
COMPATIBILITY_MATRIX[DROP_ROLLUP.ordinal()][DROP_ROLLUP.ordinal()] = true;
// schema change, such as add/modify/drop columns can be processed in batch
COMPATIBILITY_MATRIX[SCHEMA_CHANGE.ordinal()][SCHEMA_CHANGE.ordinal()] = true;
// can modify multi column comments at same time
COMPATIBILITY_MATRIX[MODIFY_COLUMN_COMMENT.ordinal()][MODIFY_COLUMN_COMMENT.ordinal()] = true;
}

public boolean needCheckCapacity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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.

package org.apache.doris.analysis;

import org.apache.doris.alter.AlterOpType;
import org.apache.doris.common.AnalysisException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;

import java.util.Map;

// MODIFY COLUMN k1 COMMENT "new comment";
public class ModifyColumnCommentClause extends AlterTableClause {
private static final Logger LOG = LogManager.getLogger(ModifyColumnCommentClause.class);
private String colName;
private String comment;

public ModifyColumnCommentClause(String colName, String comment) {
super(AlterOpType.MODIFY_COLUMN_COMMENT);
this.colName = colName;
this.comment = Strings.nullToEmpty(comment);
}

public String getColName() {
return colName;
}

public String getComment() {
return comment;
}

@Override
public Map<String, String> getProperties() {
return Maps.newHashMap();
}

@Override
public void analyze(Analyzer analyzer) throws AnalysisException {
if (Strings.isNullOrEmpty(colName)) {
throw new AnalysisException("Empty column name");
}
}

@Override
public String toSql() {
StringBuilder sb = new StringBuilder();
sb.append("MODIFY COLUMN COMMENT ").append(colName);
sb.append(" '").append(comment).append("'");
return sb.toString();
}

@Override
public String toString() {
return toSql();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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.

package org.apache.doris.analysis;

import org.apache.doris.alter.AlterOpType;
import org.apache.doris.common.AnalysisException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;

import java.util.Map;

// MODIFY COMMENT "new tbl comment";
public class ModifyTableCommentClause extends AlterTableClause {
private static final Logger LOG = LogManager.getLogger(ModifyTableCommentClause.class);
private String comment;

public ModifyTableCommentClause(String comment) {
super(AlterOpType.MODIFY_TABLE_COMMENT);
this.comment = Strings.nullToEmpty(comment);
}

public String getComment() {
return comment;
}

@Override
public void analyze(Analyzer analyzer) throws AnalysisException {
}

@Override
public Map<String, String> getProperties() {
return Maps.newHashMap();
}

@Override
public String toSql() {
StringBuilder sb = new StringBuilder();
sb.append("MODIFY COMMENT ");
sb.append("'").append(comment).append("'");
return sb.toString();
}

@Override
public String toString() {
return toSql();
}
}
Loading