diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropIndexClause.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropIndexClause.java index f72136ee2b3f41..783bed775be0f6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropIndexClause.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropIndexClause.java @@ -81,7 +81,7 @@ public boolean needChangeMTMVState() { @Override public String toSql() { StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("DROP INDEX ").append(indexName); + stringBuilder.append("DROP INDEX ").append("`" + indexName + "`"); if (!alter) { stringBuilder.append(" ON ").append(tableName.toSql()); } 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 9f32556ce9c201..9476df59cd1419 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 @@ -123,4 +123,27 @@ public void testEnableFeature() throws UserException { stmt.toSql()); Assert.assertEquals("testDb", stmt.getTbl().getDb()); } + + @Test + public void testCreateIndex() throws UserException { + List ops = Lists.newArrayList(); + ops.add(new CreateIndexClause( + new TableName(InternalCatalog.INTERNAL_CATALOG_NAME, "db", "table"), + new IndexDef("index1", false, Lists.newArrayList("col1"), IndexDef.IndexType.INVERTED, null, "balabala"), + true)); + AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, "testDb", "testTbl"), ops); + stmt.analyze(analyzer); + Assert.assertEquals("ALTER TABLE `testDb`.`testTbl` ADD INDEX `index1` (`col1`) USING INVERTED COMMENT 'balabala'", + stmt.toSql()); + } + + @Test + public void testDropIndex() throws UserException { + List ops = Lists.newArrayList(); + ops.add(new DropIndexClause("index1", false, + new TableName(InternalCatalog.INTERNAL_CATALOG_NAME, "db", "table"), true)); + AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, "testDb", "testTbl"), ops); + stmt.analyze(analyzer); + Assert.assertEquals("ALTER TABLE `testDb`.`testTbl` DROP INDEX `index1`", stmt.toSql()); + } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateIndexClauseTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateIndexClauseTest.java index 9aa0641b1b94b8..86e633d2dfebe6 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateIndexClauseTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateIndexClauseTest.java @@ -52,8 +52,7 @@ public void testAlter() throws AnalysisException { new IndexDef("index1", false, Lists.newArrayList("col1"), IndexDef.IndexType.INVERTED, null, "balabala"), true); clause.analyze(analyzer); - Assert.assertEquals("ALTER TABLE `db`.`table` ADD INDEX `index1` (`col1`) USING INVERTED COMMENT 'balabala'", - clause.toSql()); + Assert.assertEquals("ADD INDEX `index1` (`col1`) USING INVERTED COMMENT 'balabala'", clause.toSql()); } @Test(expected = AnalysisException.class) diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/DropIndexClauseTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/DropIndexClauseTest.java index 6a4459e8773db5..e1659cd03cfcfa 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/DropIndexClauseTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/DropIndexClauseTest.java @@ -47,7 +47,7 @@ public void testAlter() throws UserException { DropIndexClause clause = new DropIndexClause("index1", false, new TableName(InternalCatalog.INTERNAL_CATALOG_NAME, "db", "table"), true); clause.analyze(analyzer); - Assert.assertEquals("ALTER TABLE `db`.`table` DROP INDEX `index1`", clause.toSql()); + Assert.assertEquals("DROP INDEX `index1`", clause.toSql()); } @Test(expected = AnalysisException.class)