morrySnow commented on code in PR #38301:
URL: https://github.com/apache/doris/pull/38301#discussion_r1734308271


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreatePolicyCommand.java:
##########
@@ -80,6 +88,26 @@ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) 
{
 
     @Override
     public void run(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
+        if (policyType == PolicyTypeEnum.DATA_MASK) {
+            if (user != null) {
+                user.analyze();
+                if (user.isRootUser() || user.isAdminUser()) {
+                    
ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, 
"CreatePolicyStmt",
+                            user.getQualifiedUser(), user.getHost(), 
nameParts.get(0));
+                }
+            }
+            // check auth
+            if (!Env.getCurrentEnv().getAccessManager()
+                    .checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.GRANT)) {
+                
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR,
+                        PrivPredicate.GRANT.getPrivs().toString());
+            }
+            Policy policy = new 
DorisDataMaskPolicy(Env.getCurrentEnv().getNextId(), policyName, user, roleName,
+                    nameParts.get(0), nameParts.get(1), nameParts.get(2), 
nameParts.get(3), dataMaskType);
+            Env.getCurrentEnv().getPolicyMgr().createPolicy(policy, 
ifNotExists);
+            return;
+        }
+        ctx.getSessionVariable().enableFallbackToOriginalPlannerOnce();

Review Comment:
   no need to enableFallbackToOriginalPlannerOnce, MustFallbackException will 
ignore enable_fallback variable and use legacy planner to execute it directly



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropPolicyCommand.java:
##########
@@ -0,0 +1,78 @@
+// 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.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.exceptions.MustFallbackException;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.policy.DropPolicyLog;
+import org.apache.doris.policy.PolicyTypeEnum;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+
+/**
+ * drop policy command
+ */
+public class DropPolicyCommand extends Command implements ForwardWithSync {
+
+    private final PolicyTypeEnum policyType;
+    private final String policyName;
+    private final boolean ifExists;
+
+    /**
+     * constructor for drop command
+     */
+    public DropPolicyCommand(PolicyTypeEnum policyType, String policyName, 
boolean ifExists) {
+        super(PlanType.DROP_POLICY_COMMAND);
+        this.policyType = policyType;
+        this.policyName = policyName;
+        this.ifExists = ifExists;
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitDropPolicyCommand(this, context);
+    }
+
+    @Override
+    public void run(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
+        if (policyType == PolicyTypeEnum.DATA_MASK) {
+            // check auth
+            if (!Env.getCurrentEnv().getAccessManager()
+                     .checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.GRANT)) {
+                
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR,
+                        PrivPredicate.GRANT.getPrivs().toString());
+            }
+            DropPolicyLog dropPolicyLog = new DropPolicyLog(policyType, 
policyName);
+            Env.getCurrentEnv().getPolicyMgr().dropPolicy(dropPolicyLog, 
ifExists);
+            return;
+        }
+        ctx.getSessionVariable().enableFallbackToOriginalPlannerOnce();

Review Comment:
   ditto



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowPolicyCommand.java:
##########
@@ -0,0 +1,73 @@
+// 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.UserIdentity;
+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.exceptions.MustFallbackException;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.policy.PolicyTypeEnum;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.ShowResultSet;
+import org.apache.doris.qe.StmtExecutor;
+
+/**
+ * show policy
+ */
+public class ShowPolicyCommand extends Command implements NoForward {
+
+    private final PolicyTypeEnum policyType;
+
+    private final UserIdentity user;
+
+    private final String roleName;
+
+    public ShowPolicyCommand(PolicyTypeEnum policyType, UserIdentity user, 
String roleName) {
+        super(PlanType.SHOW_POLICY_COMMAND);
+        this.policyType = policyType;
+        this.user = user;
+        this.roleName = roleName;
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitShowPolicyCommand(this, context);
+    }
+
+    @Override
+    public void run(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
+        if (policyType == PolicyTypeEnum.DATA_MASK) {
+            if (user != null) {
+                user.analyze();
+            }
+            // check auth
+            if 
(!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
+                
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"ADMIN");
+            }
+            ShowResultSet showResultSet = 
Env.getCurrentEnv().getPolicyMgr().showPolicy(user, roleName, policyType);
+            executor.sendResultSet(showResultSet);
+            return;
+        }
+        ctx.getSessionVariable().enableFallbackToOriginalPlannerOnce();

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to