Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions fe/fe-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,17 @@ under the License.
<artifactId>sdk-core</artifactId>
<version>${awssdk.version}</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<!-- for hive-catalog-shade -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ statementBase
| constraintStatement #constraintStatementAlias
| supportedDropStatement #supportedDropStatementAlias
| supportedShowStatement #supportedShowStatementAlias
| supportedKillStatement #supportedKillStatementAlias
| unsupportedStatement #unsupported
;



unsupportedStatement
: unsupportedSetStatement
| unsupoortedUnsetStatement
| unsupportedUseStatement
| unsupportedDmlStatement
| unsupportedKillStatement
| unsupportedDescribeStatement
| unsupportedCreateStatement
| unsupportedDropStatement
Expand Down Expand Up @@ -190,7 +192,8 @@ supportedAlterStatement
;

supportedDropStatement
: DROP CATALOG RECYCLE BIN WHERE idType=STRING_LITERAL EQ id=INTEGER_VALUE #dropCatalogRecycleBin
: DROP CATALOG RECYCLE BIN WHERE idType=STRING_LITERAL EQ id=INTEGER_VALUE #dropCatalogRecycleBin
| DROP ROLE (IF EXISTS)? name=identifier #dropRole
;

supportedShowStatement
Expand All @@ -199,6 +202,11 @@ supportedShowStatement
((FROM | IN) database=identifier)? #showView
;

supportedKillStatement
: KILL (CONNECTION)? INTEGER_VALUE #killConnection
| KILL QUERY (INTEGER_VALUE | STRING_LITERAL) #killQuery
;

unsupportedOtherStatement
: HELP mark=identifierOrText #help
| INSTALL PLUGIN FROM source=identifierOrText properties=propertyClause? #installPlugin
Expand Down Expand Up @@ -643,7 +651,6 @@ unsupportedDropStatement
| DROP USER (IF EXISTS)? userIdentify #dropUser
| DROP VIEW (IF EXISTS)? name=multipartIdentifier #dropView
| DROP REPOSITORY name=identifier #dropRepository
| DROP ROLE (IF EXISTS)? name=identifier #dropRole
| DROP FILE name=STRING_LITERAL
((FROM | IN) database=identifier)? properties=propertyClause #dropFile
| DROP INDEX (IF EXISTS)? name=identifier ON tableName=multipartIdentifier #dropIndex
Expand Down Expand Up @@ -673,7 +680,7 @@ unsupportedStatsStatement
columns=identifierList? partitionSpec? #dropStats
| DROP CACHED STATS tableName=multipartIdentifier #dropCachedStats
| DROP EXPIRED STATS #dropExpiredStats
| DROP ANALYZE JOB INTEGER_VALUE #dropAanalyzeJob
| DROP ANALYZE JOB INTEGER_VALUE #dropAnalyzeJob
| KILL ANALYZE jobId=INTEGER_VALUE #killAnalyzeJob
| SHOW TABLE STATS tableName=multipartIdentifier
partitionSpec? columnList=identifierList? #showTableStats
Expand Down Expand Up @@ -854,11 +861,6 @@ stageAndPattern
(LEFT_PAREN pattern=STRING_LITERAL RIGHT_PAREN)?
;

unsupportedKillStatement
: KILL (CONNECTION)? INTEGER_VALUE #killConnection
| KILL QUERY (INTEGER_VALUE | STRING_LITERAL) #killQuery
;

unsupportedDescribeStatement
: explainCommand FUNCTION tvfName=identifier LEFT_PAREN
(properties=propertyItemList)? RIGHT_PAREN tableAlias #describeTableValuedFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public enum ErrorCode {
ERR_DUP_FIELDNAME(1060, new byte[]{'4', '2', 'S', '2', '1'}, "Duplicate column name '%s'"),
ERR_NONUNIQ_TABLE(1066, new byte[]{'4', '2', '0', '0', '0'}, "Not unique table/alias: '%s'"),
ERR_NO_SUCH_THREAD(1094, new byte[]{'H', 'Y', '0', '0', '0'}, "Unknown thread id: %d"),
ERR_KILL_DENIED_ERROR(1095, new byte[]{'H', 'Y', '0', '0', '0'}, "You are not owner of thread %d"),
ERR_KILL_DENIED_ERROR(1095, new byte[] {'H', 'Y', '0', '0', '0'}, "You are not owner of thread or query: %d"),
ERR_NO_TABLES_USED(1096, new byte[]{'H', 'Y', '0', '0', '0'}, "No tables used"),
ERR_NO_SUCH_QUERY(1097, new byte[]{'H', 'Y', '0', '0', '0'}, "Unknown query id: %s"),
ERR_WRONG_DB_NAME(1102, new byte[]{'4', '2', '0', '0', '0'}, "Incorrect database name '%s'"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,10 @@ public void dropRole(DropRoleStmt stmt) throws DdlException {
dropRoleInternal(stmt.getRole(), stmt.isSetIfExists(), false);
}

public void dropRole(String role, boolean ignoreIfNonExists) throws DdlException {
dropRoleInternal(role, ignoreIfNonExists, false);
}

public void replayDropRole(PrivInfo info) {
try {
dropRoleInternal(info.getRole(), false, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import org.apache.doris.nereids.DorisParser.DropConstraintContext;
import org.apache.doris.nereids.DorisParser.DropMTMVContext;
import org.apache.doris.nereids.DorisParser.DropProcedureContext;
import org.apache.doris.nereids.DorisParser.DropRoleContext;
import org.apache.doris.nereids.DorisParser.ElementAtContext;
import org.apache.doris.nereids.DorisParser.ExistContext;
import org.apache.doris.nereids.DorisParser.ExplainContext;
Expand All @@ -122,6 +123,7 @@
import org.apache.doris.nereids.DorisParser.IsnullContext;
import org.apache.doris.nereids.DorisParser.JoinCriteriaContext;
import org.apache.doris.nereids.DorisParser.JoinRelationContext;
import org.apache.doris.nereids.DorisParser.KillQueryContext;
import org.apache.doris.nereids.DorisParser.LambdaExpressionContext;
import org.apache.doris.nereids.DorisParser.LateralViewContext;
import org.apache.doris.nereids.DorisParser.LessThanPartitionDefContext;
Expand Down Expand Up @@ -387,14 +389,19 @@
import org.apache.doris.nereids.trees.plans.commands.CreateViewCommand;
import org.apache.doris.nereids.trees.plans.commands.DeleteFromCommand;
import org.apache.doris.nereids.trees.plans.commands.DeleteFromUsingCommand;
import org.apache.doris.nereids.trees.plans.commands.DropAnalyzeJobCommand;
import org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand;
import org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand.IdType;
import org.apache.doris.nereids.trees.plans.commands.DropConstraintCommand;
import org.apache.doris.nereids.trees.plans.commands.DropMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.DropProcedureCommand;
import org.apache.doris.nereids.trees.plans.commands.DropRoleCommand;
import org.apache.doris.nereids.trees.plans.commands.ExplainCommand;
import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
import org.apache.doris.nereids.trees.plans.commands.ExportCommand;
import org.apache.doris.nereids.trees.plans.commands.KillAnalyzeJobCommand;
import org.apache.doris.nereids.trees.plans.commands.KillConnectionCommand;
import org.apache.doris.nereids.trees.plans.commands.KillQueryCommand;
import org.apache.doris.nereids.trees.plans.commands.LoadCommand;
import org.apache.doris.nereids.trees.plans.commands.PauseMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.RefreshMTMVCommand;
Expand Down Expand Up @@ -3903,4 +3910,40 @@ public ShowViewCommand visitShowView(ShowViewContext ctx) {
}
return new ShowViewCommand(databaseName, new TableNameInfo(tableNameParts));
}

@Override
public LogicalPlan visitKillQuery(KillQueryContext ctx) {
String queryId = null;
int connectionId = -1;
TerminalNode integerValue = ctx.INTEGER_VALUE();
if (integerValue != null) {
connectionId = Integer.valueOf(integerValue.getText());
} else {
queryId = stripQuotes(ctx.STRING_LITERAL().getText());
}
return new KillQueryCommand(queryId, connectionId);
}

@Override
public LogicalPlan visitKillConnection(DorisParser.KillConnectionContext ctx) {
int connectionId = Integer.parseInt(ctx.INTEGER_VALUE().getText());
return new KillConnectionCommand(connectionId);
}

@Override
public LogicalPlan visitDropAnalyzeJob(DorisParser.DropAnalyzeJobContext ctx) {
long jobId = Long.parseLong(ctx.INTEGER_VALUE().getText());
return new DropAnalyzeJobCommand(jobId);
}

@Override
public LogicalPlan visitKillAnalyzeJob(DorisParser.KillAnalyzeJobContext ctx) {
long jobId = Long.parseLong(ctx.jobId.getText());
return new KillAnalyzeJobCommand(jobId);
}

public LogicalPlan visitDropRole(DropRoleContext ctx) {
return new DropRoleCommand(ctx.name.getText(), ctx.EXISTS() != null);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public enum PlanType {
CALL_COMMAND,
CREATE_PROCEDURE_COMMAND,
DROP_PROCEDURE_COMMAND,
DROP_ROLE_COMMAND,
SHOW_PROCEDURE_COMMAND,
SHOW_CREATE_PROCEDURE_COMMAND,
SHOW_VIEW_COMMAND,
Expand All @@ -174,5 +175,9 @@ public enum PlanType {
EXECUTE_COMMAND,
SHOW_CONFIG_COMMAND,
REPLAY_COMMAND,
ALTER_SYSTEM_RENAME_COMPUTE_GROUP
ALTER_SYSTEM_RENAME_COMPUTE_GROUP,
KILL_QUERY_COMMAND,
KILL_CONNECTION_COMMAND,
KILL_ANALYZE_JOB_COMMAND,
DROP_ANALYZE_JOB_COMMAND;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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.StmtType;
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.StmtExecutor;

/**
* DROP ANALYZE JOB [JOB_ID]
*/
public class DropAnalyzeJobCommand extends DropCommand {
private final long jobId;

public DropAnalyzeJobCommand(long jobId) {
super(PlanType.DROP_ANALYZE_JOB_COMMAND);
this.jobId = jobId;
}

public long getJobId() {
return jobId;
}

@Override
public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception {
ctx.getEnv().getAnalysisManager().dropAnalyzeJob(this);
}

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

@Override
public StmtType stmtType() {
return StmtType.DROP;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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.StmtType;
import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.StmtExecutor;

/**
* base class for all drop commands
*/
public abstract class DropCommand extends Command implements ForwardWithSync {
public DropCommand(PlanType type) {
super(type);
}

@Override
public StmtType stmtType() {
return StmtType.DROP;
}

@Override
public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
doRun(ctx, executor);
}

public abstract void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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.Env;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.FeNameFormat;
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.StmtExecutor;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* drop roles command
*/
public class DropRoleCommand extends DropCommand {
public static final Logger LOG = LogManager.getLogger(DropRoleCommand.class);
private final boolean ifExists;
private final String role;

/**
* constructor
*/
public DropRoleCommand(String role, boolean ifExists) {
super(PlanType.DROP_ROLE_COMMAND);
this.role = role;
this.ifExists = ifExists;
}

@Override
public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception {
if (Config.access_controller_type.equalsIgnoreCase("ranger-doris")) {
throw new AnalysisException("Drop role is prohibited when Ranger is enabled.");
}
FeNameFormat.checkRoleName(role, false /* can not be superuser */, "Can not drop role");
// check if current user has GRANT priv on GLOBAL level.
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.GRANT)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "DROP ROLE");
}
Env.getCurrentEnv().getAuth().dropRole(role, ifExists);
}

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