imay commented on a change in pull request #2573: implements create drop show 
index syntax for bitmap index [#2487]
URL: https://github.com/apache/incubator-doris/pull/2573#discussion_r362504816
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/alter/Alter.java
 ##########
 @@ -169,9 +175,49 @@ public void processAlterTable(AlterTableStmt stmt) throws 
UserException {
                     || alterClause instanceof AddColumnsClause
                     || alterClause instanceof DropColumnClause
                     || alterClause instanceof ModifyColumnClause
-                    || alterClause instanceof ReorderColumnsClause)
+                    || alterClause instanceof ReorderColumnsClause
+                    || alterClause instanceof CreateIndexClause
+                    || alterClause instanceof DropIndexClause)
                     && !hasAddMaterializedView && !hasDropRollup && 
!hasPartition && !hasRename) {
                 hasSchemaChange = true;
+                if (alterClause instanceof CreateIndexClause) {
+                    Table table = db.getTable(dbTableName.getTbl());
+                    if (!(table instanceof OlapTable)) {
+                        throw new AnalysisException("create index only support 
in olap table at current version.");
+                    }
+                    List<Index> indexes = ((OlapTable) table).getIndexes();
+                    IndexDef indexDef = ((CreateIndexClause) 
alterClause).getIndexDef();
+                    Set<String> newColset = new 
TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+                    newColset.addAll(indexDef.getColumns());
+                    for (Index idx : indexes) {
+                        if 
(idx.getIndexName().equalsIgnoreCase(indexDef.getIndexName())) {
+                            throw new AnalysisException("index `" + 
indexDef.getIndexName() + "` already exist.");
+                        }
+                        Set<String> idxSet = new 
TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+                        idxSet.addAll(idx.getColumns());
+                            if (newColset.equals(idxSet)) {
+                                throw new AnalysisException("index for columns 
(" + String
+                                        .join(",", indexDef.getColumns()) + " 
) already exist.");
+                            }
+                        }
+
+                } else if (alterClause instanceof DropIndexClause) {
+                    Table table = db.getTable(dbTableName.getTbl());
+                    if (table instanceof OlapTable) {
 
 Review comment:
   If table is not OlapTable, throw exception?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to