From 5aa049829eea446a082707f7736ea34c01af0fd6 Mon Sep 17 00:00:00 2001 From: GentleCold Date: Mon, 11 Nov 2024 00:26:44 +0800 Subject: [PATCH] [Feat](Nereids) support show authors command --- .../org/apache/doris/nereids/DorisParser.g4 | 2 +- .../nereids/parser/LogicalPlanBuilder.java | 7 +++ .../doris/nereids/trees/plans/PlanType.java | 1 + .../plans/commands/ShowAuthorsCommand.java | 59 +++++++++++++++++++ .../trees/plans/visitor/CommandVisitor.java | 5 ++ .../ddl/show_authors/show_authors.out | 3 + .../ddl/show_authors/show_authors.groovy | 21 +++++++ 7 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowAuthorsCommand.java create mode 100644 regression-test/data/nereids_p0/ddl/show_authors/show_authors.out create mode 100644 regression-test/suites/nereids_p0/ddl/show_authors/show_authors.groovy 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 b7fa04c2ef796fb..dbee9e292849f70 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 @@ -195,6 +195,7 @@ supportedShowStatement | SHOW VIEW (FROM |IN) tableName=multipartIdentifier ((FROM | IN) database=identifier)? #showView + | SHOW AUTHORS #showAuthors ; unsupportedOtherStatement @@ -243,7 +244,6 @@ unsupportedShowStatement | SHOW EVENTS ((FROM | IN) database=multipartIdentifier)? wildWhere? #showEvents | SHOW PLUGINS #showPlugins | SHOW STORAGE? ENGINES #showStorageEngines - | SHOW AUTHORS #showAuthors | SHOW BRIEF? CREATE TABLE name=multipartIdentifier #showCreateTable | SHOW CREATE VIEW name=multipartIdentifier #showCreateView | SHOW CREATE MATERIALIZED VIEW name=multipartIdentifier #showMaterializedView 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 8362d002d2b8135..9788f60592843c8 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 @@ -198,6 +198,7 @@ import org.apache.doris.nereids.DorisParser.ShowProcedureStatusContext; import org.apache.doris.nereids.DorisParser.ShowVariablesContext; import org.apache.doris.nereids.DorisParser.ShowViewContext; +import org.apache.doris.nereids.DorisParser.ShowAuthorsContext; import org.apache.doris.nereids.DorisParser.SimpleColumnDefContext; import org.apache.doris.nereids.DorisParser.SimpleColumnDefsContext; import org.apache.doris.nereids.DorisParser.SingleStatementContext; @@ -422,6 +423,7 @@ import org.apache.doris.nereids.trees.plans.commands.SetOptionsCommand; import org.apache.doris.nereids.trees.plans.commands.SetTransactionCommand; import org.apache.doris.nereids.trees.plans.commands.SetUserPropertiesCommand; +import org.apache.doris.nereids.trees.plans.commands.ShowAuthorsCommand; import org.apache.doris.nereids.trees.plans.commands.ShowConfigCommand; import org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand; import org.apache.doris.nereids.trees.plans.commands.ShowCreateMTMVCommand; @@ -4046,4 +4048,9 @@ public ShowViewCommand visitShowView(ShowViewContext ctx) { } return new ShowViewCommand(databaseName, new TableNameInfo(tableNameParts)); } + + @Override + public LogicalPlan visitShowAuthors(ShowAuthorsContext ctx) { + return new ShowAuthorsCommand(); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java index b9fb9e96f879272..b6752735353cebf 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java @@ -178,5 +178,6 @@ public enum PlanType { SHOW_CONFIG_COMMAND, SHOW_VARIABLES_COMMAND, SHOW_VIEW_COMMAND, + SHOW_AUTHORS_COMMAND, REPLAY_COMMAND } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowAuthorsCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowAuthorsCommand.java new file mode 100644 index 000000000000000..098535302b2b3e8 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowAuthorsCommand.java @@ -0,0 +1,59 @@ +// 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.nereids.trees.plans.commands; + +import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.ScalarType; +import org.apache.doris.nereids.trees.plans.PlanType; +import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; +import org.apache.doris.qe.ConnectContext; +import org.apache.doris.qe.ShowResultSet; +import org.apache.doris.qe.ShowResultSetMetaData; +import org.apache.doris.qe.StmtExecutor; + +import com.google.common.collect.Lists; + +import java.util.ArrayList; +import java.util.List; + +/** + * ShowAuthorsCommand + */ +public class ShowAuthorsCommand extends ShowCommand { + private static final ShowResultSetMetaData META_DATA = + ShowResultSetMetaData.builder() + .addColumn(new Column("Name", ScalarType.createVarchar(30))) + .addColumn(new Column("Location", ScalarType.createVarchar(30))) + .addColumn(new Column("Comment", ScalarType.createVarchar(30))) + .build(); + + public ShowAuthorsCommand() { + super(PlanType.SHOW_AUTHORS_COMMAND); + } + + @Override + public R accept(PlanVisitor visitor, C context) { + return visitor.visitShowAuthorsCommand(this, context); + } + + @Override + public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { + List> rowSet = Lists.newArrayList(); + return new ShowResultSet(META_DATA, rowSet); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java index e89c9a3a5c5f1c6..c8a4b73c46c8b15 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java @@ -54,6 +54,7 @@ import org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand; import org.apache.doris.nereids.trees.plans.commands.ShowVariablesCommand; import org.apache.doris.nereids.trees.plans.commands.ShowViewCommand; +import org.apache.doris.nereids.trees.plans.commands.ShowAuthorsCommand; import org.apache.doris.nereids.trees.plans.commands.UnsetDefaultStorageVaultCommand; import org.apache.doris.nereids.trees.plans.commands.UnsetVariableCommand; import org.apache.doris.nereids.trees.plans.commands.UnsupportedCommand; @@ -242,4 +243,8 @@ default R visitShowVariablesCommand(ShowVariablesCommand showVariablesCommand, C default R visitShowViewCommand(ShowViewCommand showViewCommand, C context) { return visitCommand(showViewCommand, context); } + + default R visitShowAuthorsCommand(ShowAuthorsCommand showAuthorsCommand, C context) { + return visitCommand(showAuthorsCommand, context); + } } diff --git a/regression-test/data/nereids_p0/ddl/show_authors/show_authors.out b/regression-test/data/nereids_p0/ddl/show_authors/show_authors.out new file mode 100644 index 000000000000000..5629a2aa80f679f --- /dev/null +++ b/regression-test/data/nereids_p0/ddl/show_authors/show_authors.out @@ -0,0 +1,3 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !cmd -- + diff --git a/regression-test/suites/nereids_p0/ddl/show_authors/show_authors.groovy b/regression-test/suites/nereids_p0/ddl/show_authors/show_authors.groovy new file mode 100644 index 000000000000000..8d00205a5cb93af --- /dev/null +++ b/regression-test/suites/nereids_p0/ddl/show_authors/show_authors.groovy @@ -0,0 +1,21 @@ +// 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. + +suite("show_authors_command") { + checkNereidsExecute("""show authors;""") + qt_cmd("""show authors;""") +}