forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] (nereids)implement alterRoleCommand in nereids
- Loading branch information
Showing
8 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Alter commands | ||
*/ | ||
public abstract class AlterCommand extends Command implements ForwardWithSync { | ||
public AlterCommand(PlanType type) { | ||
super(type); | ||
} | ||
|
||
@Override | ||
public StmtType stmtType() { | ||
return StmtType.ALTER; | ||
} | ||
|
||
@Override | ||
public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { | ||
doRun(ctx, executor); | ||
} | ||
|
||
public abstract void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception; | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterRoleCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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.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.StmtExecutor; | ||
|
||
import com.google.common.base.Strings; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
/** | ||
* alter role command | ||
*/ | ||
public class AlterRoleCommand extends AlterCommand { | ||
public static final Logger LOG = LogManager.getLogger(AlterRoleCommand.class); | ||
private final String role; | ||
private final String comment; | ||
|
||
/** | ||
* constructor | ||
*/ | ||
|
||
public AlterRoleCommand(String role, String comment) { | ||
super(PlanType.ALTER_ROLE_COMMAND); | ||
this.role = role; | ||
this.comment = Strings.nullToEmpty(comment); | ||
|
||
} | ||
|
||
@Override | ||
public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { | ||
// 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, "ALTER ROLE"); | ||
} | ||
Env.getCurrentEnv().getAuth().alterRole(role, comment); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) { | ||
return visitor.visitAlterRoleCommand(this, context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
regression-test/suites/nereids_p0/ddl/alter/test_nereids_role.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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. | ||
|
||
import org.junit.Assert; | ||
|
||
suite("test_nereids_role", "account") { | ||
def role= 'account_role_test' | ||
def user = 'acount_role_user_test' | ||
def dbName = 'account_role_test_db' | ||
def pwd = 'C123_567p' | ||
|
||
try_sql("DROP ROLE ${role}") | ||
try_sql("DROP USER ${user}") | ||
sql """DROP DATABASE IF EXISTS ${dbName}""" | ||
sql """CREATE DATABASE ${dbName}""" | ||
|
||
sql """CREATE ROLE ${role}""" | ||
sql """GRANT SELECT_PRIV ON ${context.config.defaultDb} TO ROLE '${role}'""" | ||
sql """GRANT SELECT_PRIV ON ${dbName} TO ROLE '${role}'""" | ||
sql """CREATE USER '${user}' IDENTIFIED BY '${pwd}' DEFAULT ROLE '${role}'""" | ||
def result1 = connect(user=user, password="${pwd}", url=context.config.jdbcUrl) { | ||
sql "show databases like '${dbName}'" | ||
} | ||
assertEquals(result1.size(), 1) | ||
|
||
sql """REVOKE SELECT_PRIV ON ${dbName} FROM ROLE '${role}'""" | ||
def result2 = connect(user=user, password="${pwd}", url=context.config.jdbcUrl) { | ||
sql "show databases like '${dbName}'" | ||
} | ||
assertEquals(result2.size(), 0) | ||
|
||
sql """DROP USER ${user}""" | ||
sql """DROP ROLE ${role}""" | ||
sql """DROP DATABASE ${dbName}""" | ||
|
||
// test comment | ||
// create role with comment | ||
sql """CREATE ROLE ${role} comment 'account_p0_account_role_test_comment_create'""" | ||
def roles_create = sql """show roles""" | ||
logger.info("roles_create: " + roles_create.toString()) | ||
assertTrue(roles_create.toString().contains("account_p0_account_role_test_comment_create")) | ||
// alter role with comment | ||
checkNereidsExecute("ALTER ROLE ${role} comment 'account_p0_account_role_test_comment_alter';"); | ||
def roles_alter = sql """show roles""" | ||
logger.info("roles_alter: " + roles_alter.toString()) | ||
assertTrue(roles_alter.toString().contains("account_p0_account_role_test_comment_alter")) | ||
// drop role | ||
sql """DROP ROLE ${role}""" | ||
def roles_drop = sql """show roles""" | ||
logger.info("roles_drop: " + roles_drop.toString()) | ||
assertFalse(roles_drop.toString().contains("account_p0_account_role_test_comment_alter")) | ||
} | ||
|