This is an automated email from the ASF dual-hosted git repository. morrysnow pushed a commit to branch branch-3.1 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.1 by this push: new b207016ae82 branch-3.1: [feature](view)Support modify view comment #46910 (#52018) b207016ae82 is described below commit b207016ae8293398a91f7899ab6a6ebbadef53af Author: James <lijib...@selectdb.com> AuthorDate: Fri Jun 20 17:04:37 2025 +0800 branch-3.1: [feature](view)Support modify view comment #46910 (#52018) backport: #46910 --- .../antlr4/org/apache/doris/nereids/DorisParser.g4 | 4 ++-- .../main/java/org/apache/doris/alter/Alter.java | 24 +++++++++++++++------ .../org/apache/doris/analysis/AlterViewStmt.java | 15 +++++++++++++ .../main/java/org/apache/doris/catalog/Env.java | 4 +++- .../doris/nereids/parser/LogicalPlanBuilder.java | 12 ++++++++--- .../trees/plans/commands/AlterViewCommand.java | 5 ++++- .../trees/plans/commands/info/AlterViewInfo.java | 20 +++++++++++++++++ .../org/apache/doris/persist/AlterViewInfo.java | 12 +++++++++-- .../apache/doris/persist/AlterViewInfoTest.java | 2 +- regression-test/data/view_p0/view_p0.out | Bin 1144 -> 3474 bytes regression-test/suites/view_p0/view_p0.groovy | 22 ++++++++++++++++++- 11 files changed, 102 insertions(+), 18 deletions(-) diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index 1184f2b310d..5c11e19633f 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -181,8 +181,8 @@ supportedCreateStatement ; supportedAlterStatement - : ALTER VIEW name=multipartIdentifier (LEFT_PAREN cols=simpleColumnDefs RIGHT_PAREN)? - AS query #alterView + : ALTER VIEW name=multipartIdentifier + ((MODIFY commentSpec) | ((LEFT_PAREN cols=simpleColumnDefs RIGHT_PAREN)? AS query)) #alterView | ALTER STORAGE VAULT name=multipartIdentifier properties=propertyClause #alterStorageVault | ALTER SYSTEM RENAME COMPUTE GROUP name=identifier newName=identifier #alterSystemRenameComputeGroup ; diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java index 37b1f177d45..ac5cbcb6528 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java @@ -700,23 +700,28 @@ public class Alter { String tableName = dbTableName.getTbl(); View view = (View) db.getTableOrMetaException(tableName, TableType.VIEW); - modifyViewDef(db, view, stmt.getInlineViewDef(), ctx.getSessionVariable().getSqlMode(), stmt.getColumns()); + modifyViewDef(db, view, stmt.getInlineViewDef(), ctx.getSessionVariable().getSqlMode(), stmt.getColumns(), + stmt.getComment()); } private void modifyViewDef(Database db, View view, String inlineViewDef, long sqlMode, - List<Column> newFullSchema) throws DdlException { + List<Column> newFullSchema, String comment) throws DdlException { db.writeLockOrDdlException(); try { view.writeLockOrDdlException(); try { - view.setInlineViewDefWithSqlMode(inlineViewDef, sqlMode); - view.setNewFullSchema(newFullSchema); + if (comment != null) { + view.setComment(comment); + } else { + view.setInlineViewDefWithSqlMode(inlineViewDef, sqlMode); + view.setNewFullSchema(newFullSchema); + } String viewName = view.getName(); db.unregisterTable(viewName); db.registerTable(view); AlterViewInfo alterViewInfo = new AlterViewInfo(db.getId(), view.getId(), - inlineViewDef, newFullSchema, sqlMode); + inlineViewDef, newFullSchema, sqlMode, comment); Env.getCurrentEnv().getEditLog().logModifyViewDef(alterViewInfo); LOG.info("modify view[{}] definition to {}", viewName, inlineViewDef); } finally { @@ -732,6 +737,7 @@ public class Alter { long tableId = alterViewInfo.getTableId(); String inlineViewDef = alterViewInfo.getInlineViewDef(); List<Column> newFullSchema = alterViewInfo.getNewFullSchema(); + String comment = alterViewInfo.getComment(); Database db = Env.getCurrentInternalCatalog().getDbOrMetaException(dbId); View view = (View) db.getTableOrMetaException(tableId, TableType.VIEW); @@ -740,8 +746,12 @@ public class Alter { view.writeLock(); try { String viewName = view.getName(); - view.setInlineViewDefWithSqlMode(inlineViewDef, alterViewInfo.getSqlMode()); - view.setNewFullSchema(newFullSchema); + if (comment != null) { + view.setComment(comment); + } else { + view.setInlineViewDefWithSqlMode(inlineViewDef, alterViewInfo.getSqlMode()); + view.setNewFullSchema(newFullSchema); + } // We do not need to init view here. // During the `init` phase, some `Alter-View` statements will access the remote file system, diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterViewStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterViewStmt.java index 5a2d184e20d..24efbd90905 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterViewStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterViewStmt.java @@ -36,14 +36,29 @@ import java.util.List; @Deprecated public class AlterViewStmt extends BaseViewStmt implements NotFallbackInParser { + private final String comment; + + public AlterViewStmt(TableName tbl, String comment) { + this(tbl, null, null, comment); + } + public AlterViewStmt(TableName tbl, List<ColWithComment> cols, QueryStmt queryStmt) { + this(tbl, cols, queryStmt, null); + } + + public AlterViewStmt(TableName tbl, List<ColWithComment> cols, QueryStmt queryStmt, String comment) { super(tbl, cols, queryStmt); + this.comment = comment; } public TableName getTbl() { return tableName; } + public String getComment() { + return comment; + } + @Override public void analyze(Analyzer analyzer) throws UserException { super.analyze(analyzer); diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java index 86b5a4678b9..51f4cd120a0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java @@ -5716,8 +5716,10 @@ public class Env { } if (replace) { + String comment = stmt.getComment(); + comment = comment == null || comment.isEmpty() ? null : comment; AlterViewStmt alterViewStmt = new AlterViewStmt(stmt.getTableName(), stmt.getColWithComments(), - stmt.getViewDefStmt()); + stmt.getViewDefStmt(), comment); alterViewStmt.setInlineViewDef(stmt.getInlineViewDef()); alterViewStmt.setFinalColumns(stmt.getColumns()); try { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index 08dd757b5aa..0cfd39e6670 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -938,9 +938,15 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { @Override public LogicalPlan visitAlterView(AlterViewContext ctx) { List<String> nameParts = visitMultipartIdentifier(ctx.name); - String querySql = getOriginSql(ctx.query()); - AlterViewInfo info = new AlterViewInfo(new TableNameInfo(nameParts), querySql, - ctx.cols == null ? Lists.newArrayList() : visitSimpleColumnDefs(ctx.cols)); + String comment = ctx.commentSpec() == null ? null : visitCommentSpec(ctx.commentSpec()); + AlterViewInfo info; + if (comment != null) { + info = new AlterViewInfo(new TableNameInfo(nameParts), comment); + } else { + String querySql = getOriginSql(ctx.query()); + info = new AlterViewInfo(new TableNameInfo(nameParts), querySql, + ctx.cols == null ? Lists.newArrayList() : visitSimpleColumnDefs(ctx.cols)); + } return new AlterViewCommand(info); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterViewCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterViewCommand.java index 900986874b8..80e6b4c8640 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterViewCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterViewCommand.java @@ -39,7 +39,10 @@ public class AlterViewCommand extends Command implements ForwardWithSync { public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { executor.checkBlockRules(); alterViewInfo.init(ctx); - alterViewInfo.validate(ctx); + // For modify comment command, doesn't need to do validation. + if (alterViewInfo.getComment() == null) { + alterViewInfo.validate(ctx); + } AlterViewStmt alterViewStmt = alterViewInfo.translateToLegacyStmt(ctx); Env.getCurrentEnv().alterView(alterViewStmt); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterViewInfo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterViewInfo.java index eb8af115ac0..483c37a8388 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterViewInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AlterViewInfo.java @@ -40,10 +40,19 @@ import java.util.List; /** AlterViewInfo */ public class AlterViewInfo extends BaseViewInfo { + + private final String comment; + /** constructor*/ public AlterViewInfo(TableNameInfo viewName, String querySql, List<SimpleColumnDefinition> simpleColumnDefinitions) { super(viewName, querySql, simpleColumnDefinitions); + this.comment = null; + } + + public AlterViewInfo(TableNameInfo viewName, String comment) { + super(viewName, null, null); + this.comment = comment; } /** init */ @@ -69,6 +78,10 @@ public class AlterViewInfo extends BaseViewInfo { ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLE_ACCESS_DENIED_ERROR, PrivPredicate.ALTER.getPrivs().toString(), viewName.getTbl()); } + if (comment != null) { + // Modify comment only. + return; + } analyzeAndFillRewriteSqlMap(querySql, ctx); PlanUtils.OutermostPlanFinderContext outermostPlanFinderContext = new PlanUtils.OutermostPlanFinderContext(); analyzedPlan.accept(PlanUtils.OutermostPlanFinder.INSTANCE, outermostPlanFinderContext); @@ -78,6 +91,9 @@ public class AlterViewInfo extends BaseViewInfo { /**translateToLegacyStmt*/ public AlterViewStmt translateToLegacyStmt(ConnectContext ctx) { + if (comment != null) { + return new AlterViewStmt(viewName.transferToTableName(), comment); + } // expand star(*) in project list and replace table name with qualifier String rewrittenSql = rewriteSql(ctx.getStatementContext().getIndexInSqlToString(), querySql); // rewrite project alias @@ -92,4 +108,8 @@ public class AlterViewInfo extends BaseViewInfo { alterViewStmt.setFinalColumns(finalCols); return alterViewStmt; } + + public String getComment() { + return comment; + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/persist/AlterViewInfo.java b/fe/fe-core/src/main/java/org/apache/doris/persist/AlterViewInfo.java index c54dfcf7c31..141a35d6834 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/persist/AlterViewInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/persist/AlterViewInfo.java @@ -42,18 +42,22 @@ public class AlterViewInfo implements Writable { private long sqlMode; @SerializedName(value = "newFullSchema") private List<Column> newFullSchema; + @SerializedName(value = "comment") + private String comment; public AlterViewInfo() { // for persist newFullSchema = Lists.newArrayList(); } - public AlterViewInfo(long dbId, long tableId, String inlineViewDef, List<Column> newFullSchema, long sqlMode) { + public AlterViewInfo(long dbId, long tableId, String inlineViewDef, List<Column> newFullSchema, long sqlMode, + String comment) { this.dbId = dbId; this.tableId = tableId; this.inlineViewDef = inlineViewDef; this.newFullSchema = newFullSchema; this.sqlMode = sqlMode; + this.comment = comment; } public long getDbId() { @@ -76,6 +80,10 @@ public class AlterViewInfo implements Writable { return sqlMode; } + public String getComment() { + return comment; + } + @Override public int hashCode() { return Objects.hash(dbId, tableId, inlineViewDef, sqlMode, newFullSchema); @@ -92,7 +100,7 @@ public class AlterViewInfo implements Writable { AlterViewInfo otherInfo = (AlterViewInfo) other; return dbId == otherInfo.getDbId() && tableId == otherInfo.getTableId() && inlineViewDef.equalsIgnoreCase(otherInfo.getInlineViewDef()) && sqlMode == otherInfo.getSqlMode() - && newFullSchema.equals(otherInfo.getNewFullSchema()); + && newFullSchema.equals(otherInfo.getNewFullSchema()) && Objects.equals(comment, otherInfo.comment); } @Override diff --git a/fe/fe-core/src/test/java/org/apache/doris/persist/AlterViewInfoTest.java b/fe/fe-core/src/test/java/org/apache/doris/persist/AlterViewInfoTest.java index 8b179c2889e..b8e8044d22e 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/persist/AlterViewInfoTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/persist/AlterViewInfoTest.java @@ -57,7 +57,7 @@ public class AlterViewInfoTest { Column column1 = new Column("col1", PrimitiveType.BIGINT); Column column2 = new Column("col2", PrimitiveType.DOUBLE); - AlterViewInfo alterViewInfo = new AlterViewInfo(dbId, tableId, inlineViewDef, Lists.newArrayList(column1, column2), sqlMode); + AlterViewInfo alterViewInfo = new AlterViewInfo(dbId, tableId, inlineViewDef, Lists.newArrayList(column1, column2), sqlMode, null); alterViewInfo.write(out); out.flush(); out.close(); diff --git a/regression-test/data/view_p0/view_p0.out b/regression-test/data/view_p0/view_p0.out index 0e59bbd6233..a792969b19e 100644 Binary files a/regression-test/data/view_p0/view_p0.out and b/regression-test/data/view_p0/view_p0.out differ diff --git a/regression-test/suites/view_p0/view_p0.groovy b/regression-test/suites/view_p0/view_p0.groovy index e6c6a12f882..570111707f4 100644 --- a/regression-test/suites/view_p0/view_p0.groovy +++ b/regression-test/suites/view_p0/view_p0.groovy @@ -191,7 +191,27 @@ suite("view_p0") { """ qt_desc_view_3 "DESC test_view_table2_view" + qt_comment0 """show create table test_view_table2_view""" + sql """ALTER VIEW `test_view_table2_view` MODIFY COMMENT "comment1";""" + qt_comment1 """show create table test_view_table2_view""" + + sql """Alter VIEW `test_view_table2_view` + AS + SELECT + date_format(c_date,'%Y-%m-%d') AS `CREATE_DATE` + FROM + test_view_table2 + GROUP BY + date_format(c_date, '%Y-%m-%d'); + """ + qt_comment2 """show create table test_view_table2_view""" + + sql """Alter VIEW `test_view_table2_view` MODIFY COMMENT "comment4";""" + qt_comment4 """show create table test_view_table2_view""" + + sql """Alter VIEW `test_view_table2_view` MODIFY COMMENT "";""" + qt_comment_empty """show create table test_view_table2_view""" + sql """ drop view if exists test_view_table2_view;""" sql """DROP TABLE IF EXISTS test_view_table2""" } - --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org