Skip to content

Commit

Permalink
[Enhancement] (nereids)implement showBrokerCommand in nereids (#44424)
Browse files Browse the repository at this point in the history
Issue Number: close #42761
  • Loading branch information
Vallishp authored Nov 22, 2024
1 parent f958509 commit c1c9337
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ supportedDropStatement
;

supportedShowStatement

: SHOW (GLOBAL | SESSION | LOCAL)? VARIABLES wildWhere? #showVariables
| SHOW AUTHORS #showAuthors
| SHOW BROKER #showBroker
| SHOW DYNAMIC PARTITION TABLES ((FROM | IN) database=multipartIdentifier)? #showDynamicPartition
| SHOW LAST INSERT #showLastInsert
| SHOW DELETE ((FROM | IN) database=multipartIdentifier)? #showDelete
Expand Down Expand Up @@ -310,7 +310,6 @@ unsupportedShowStatement
| SHOW ALL PROPERTIES wildWhere? #showAllProperties
| SHOW BACKUP ((FROM | IN) database=multipartIdentifier)? wildWhere? #showBackup
| SHOW BRIEF? RESTORE ((FROM | IN) database=multipartIdentifier)? wildWhere? #showRestore
| SHOW BROKER #showBroker
| SHOW RESOURCES wildWhere? sortClause? limitClause? #showResources
| SHOW WORKLOAD GROUPS wildWhere? #showWorkloadGroups
| SHOW TRASH (ON backend=STRING_LITERAL)? #showTrash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
import org.apache.doris.nereids.DorisParser.SetVariableWithTypeContext;
import org.apache.doris.nereids.DorisParser.ShowAuthorsContext;
import org.apache.doris.nereids.DorisParser.ShowBackendsContext;
import org.apache.doris.nereids.DorisParser.ShowBrokerContext;
import org.apache.doris.nereids.DorisParser.ShowConfigContext;
import org.apache.doris.nereids.DorisParser.ShowConstraintContext;
import org.apache.doris.nereids.DorisParser.ShowCreateCatalogContext;
Expand Down Expand Up @@ -467,6 +468,7 @@
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.ShowBackendsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowBrokerCommand;
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.ShowCreateCatalogCommand;
Expand Down Expand Up @@ -4334,6 +4336,12 @@ public RecoverPartitionCommand visitRecoverPartition(RecoverPartitionContext ctx
partitionName, partitionId, newPartitionName);
}

@Override
public LogicalPlan visitShowBroker(ShowBrokerContext ctx) {
return new ShowBrokerCommand();
}

@Override
public LogicalPlan visitDropRole(DropRoleContext ctx) {
return new DropRoleCommand(ctx.name.getText(), ctx.EXISTS() != null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public enum PlanType {
DROP_SQL_BLOCK_RULE_COMMAND,
SHOW_BACKENDS_COMMAND,
SHOW_BLOCK_RULE_COMMAND,
SHOW_BROKER_COMMAND,
SHOW_CONFIG_COMMAND,
SHOW_CREATE_CATALOG_COMMAND,
SHOW_CREATE_MATERIALIZED_VIEW_COMMAND,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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.analysis.RedirectStatus;
import org.apache.doris.catalog.BrokerMgr;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.mysql.privilege.PrivPredicate;
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 java.util.List;

/**
* show broker command
*/
public class ShowBrokerCommand extends ShowCommand {

/**
* constructor
*/
public ShowBrokerCommand() {
super(PlanType.SHOW_BROKER_COMMAND);
}

public ShowResultSetMetaData getMetaData() {
ShowResultSetMetaData.Builder builder = ShowResultSetMetaData.builder();
for (String title : BrokerMgr.BROKER_PROC_NODE_TITLE_NAMES) {
builder.addColumn(new Column(title, ScalarType.createVarchar(30)));
}
return builder.build();
}

@Override
public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception {
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)
&& !Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(),
PrivPredicate.OPERATOR)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN/OPERATOR");
}
List<List<String>> brokersInfo = Env.getCurrentEnv().getBrokerMgr().getBrokersInfo();
// Only success
return new ShowResultSet(getMetaData(), brokersInfo);
}

@Override
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
return visitor.visitShowBrokerCommand(this, context);
}

@Override
public RedirectStatus toRedirectStatus() {
if (ConnectContext.get().getSessionVariable().getForwardToMaster()) {
return RedirectStatus.FORWARD_NO_SYNC;
} else {
return RedirectStatus.NO_FORWARD;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
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.ShowBackendsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowBrokerCommand;
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.ShowCreateCatalogCommand;
Expand Down Expand Up @@ -396,6 +397,10 @@ default R visitRecoverPartitionCommand(RecoverPartitionCommand recoverPartitionC
return visitCommand(recoverPartitionCommand, context);
}

default R visitShowBrokerCommand(ShowBrokerCommand showBrokerCommand, C context) {
return visitCommand(showBrokerCommand, context);
}

default R visitDropRoleCommand(DropRoleCommand dropRoleCommand, C context) {
return visitCommand(dropRoleCommand, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ suite('test_manager_interface_2',"p0") {
}

sql """ALTER SYSTEM ADD BROKER test_manager_broker "${address}:${notExistPort}";"""
checkNereidsExecute("show broker")
result = sql """ show broker """
x = 0
logger.info("result = ${result}" )
Expand Down

0 comments on commit c1c9337

Please sign in to comment.