morrySnow commented on code in PR #38301: URL: https://github.com/apache/doris/pull/38301#discussion_r1722924118
########## fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4: ########## @@ -151,6 +152,10 @@ supportedCreateStatement AS type=(RESTRICTIVE | PERMISSIVE) TO (user=userIdentify | ROLE roleName=identifier) USING LEFT_PAREN booleanExpression RIGHT_PAREN #createRowPolicy + | CREATE DATA MASK POLICY (IF NOT EXISTS)? name=identifier + ON column=multipartIdentifier + TO (user=userIdentify | ROLE roleName=identifier) + USING dataMaskType=identifier #createDataMaskPolicy Review Comment: ```suggestion | CREATE DATA MASK POLICY (IF NOT EXISTS)? name=identifier ON column=multipartIdentifier TO (user=userIdentify | ROLE roleName=identifier) USING dataMaskType=identifier #createDataMaskPolicy ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropPolicyCommand.java: ########## @@ -0,0 +1,79 @@ +// 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.DropPolicyStmt; +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.AnalysisException; +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.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) { + DropPolicyStmt dropPolicyStmt = new DropPolicyStmt(PolicyTypeEnum.DATA_MASK, ifExists, policyName, Review Comment: do not reuse DropPolicyStmt ########## fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnName.java: ########## @@ -0,0 +1,162 @@ +// 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. +// This file is copied from +// https://github.com/apache/impala/blob/branch-2.9.0/fe/src/main/java/org/apache/impala/TableName.java +// and modified by Doris + +package org.apache.doris.analysis; + +import org.apache.doris.catalog.Env; +import org.apache.doris.common.AnalysisException; +import org.apache.doris.common.ErrorCode; +import org.apache.doris.common.ErrorReport; +import org.apache.doris.common.io.Writable; +import org.apache.doris.datasource.InternalCatalog; + +import com.google.common.base.Strings; +import com.google.gson.annotations.SerializedName; + +import java.io.DataOutput; +import java.io.IOException; +import java.util.Objects; +import java.util.stream.Stream; + +public class ColumnName implements Writable { Review Comment: ```suggestion public class ColumnName { ``` ########## fe/fe-core/src/main/java/org/apache/doris/policy/DorisDataMaskPolicy.java: ########## @@ -0,0 +1,221 @@ +// 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.policy; + +import org.apache.doris.analysis.UserIdentity; +import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.ScalarType; +import org.apache.doris.catalog.Type; +import org.apache.doris.common.AnalysisException; +import org.apache.doris.mysql.privilege.DataMaskPolicy; +import org.apache.doris.nereids.parser.NereidsParser; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.Slot; +import org.apache.doris.nereids.trees.expressions.literal.StringLiteral; +import org.apache.doris.qe.ShowResultSetMetaData; + +import com.google.common.collect.Lists; +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.IOException; +import java.util.List; +import java.util.Locale; +import java.util.Objects; + +@Data +public class DorisDataMaskPolicy extends Policy implements DataMaskPolicy { + + public static final ShowResultSetMetaData DATA_MASK_META_DATA = + ShowResultSetMetaData.builder() + .addColumn(new Column("PolicyName", ScalarType.createVarchar(100))) + .addColumn(new Column("CatalogName", ScalarType.createVarchar(100))) + .addColumn(new Column("DbName", ScalarType.createVarchar(100))) + .addColumn(new Column("TableName", ScalarType.createVarchar(100))) + .addColumn(new Column("ColumnName", ScalarType.createVarchar(100))) + .addColumn(new Column("DataMaskType", ScalarType.createVarchar(20))) + .addColumn(new Column("DataMaskDef", ScalarType.createVarchar(65535))) Review Comment: varchar length max is 65533 ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreatePolicyCommand.java: ########## @@ -80,6 +88,27 @@ 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) { + ColumnName columnName = new ColumnName(nameParts.get(0), nameParts.get(1), nameParts.get(2), + nameParts.get(3)); + CreatePolicyStmt policyStmt = new CreatePolicyStmt(PolicyTypeEnum.DATA_MASK, ifNotExists, policyName, Review Comment: if data mask policy is a new feature, please do not reuse CreatePolicyStmt to create it in Nereids, because we want to remove all xxxStmt in future. ########## fe/fe-core/src/main/java/org/apache/doris/nereids/util/RelationUtil.java: ########## @@ -79,6 +79,53 @@ public static List<String> getQualifierName(ConnectContext context, List<String> } } + /** + * get qualifier column name + */ + public static List<String> getQualifierColumnName(ConnectContext context, List<String> nameParts) { + switch (nameParts.size()) { + case 1: { // col + throw new IllegalStateException("must specify a table."); Review Comment: throw Nereids' AnalysisException ########## fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4: ########## @@ -161,6 +166,11 @@ supportedAlterStatement supportedDropStatement : DROP CATALOG RECYCLE BIN WHERE idType=STRING_LITERAL EQ id=INTEGER_VALUE #dropCatalogRecycleBin + | DROP DATA MASK POLICY (IF EXISTS)? name=identifier #dropDataMaskPolicy Review Comment: ```suggestion : DROP CATALOG RECYCLE BIN WHERE idType=STRING_LITERAL EQ id=INTEGER_VALUE #dropCatalogRecycleBin | DROP DATA MASK POLICY (IF EXISTS)? name=identifier #dropDataMaskPolicy ``` ########## fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/InternalAccessController.java: ########## @@ -78,7 +79,9 @@ public boolean checkCloudPriv(UserIdentity currentUser, String resourceName, @Override public Optional<DataMaskPolicy> evalDataMaskPolicy(UserIdentity currentUser, String ctl, String db, String tbl, String col) { - return Optional.empty(); + DorisDataMaskPolicy dataMaskPolicy = Env.getCurrentEnv().getPolicyMgr().getDataMaskPolicy(ctl, db, tbl, col, + currentUser); + return dataMaskPolicy == null ? Optional.empty() : Optional.of(dataMaskPolicy); Review Comment: ```suggestion return Optional.ofNullable(dataMaskPolicy); ``` ########## fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4: ########## @@ -371,6 +371,7 @@ LOGICAL: 'LOGICAL'; LOW_PRIORITY: 'LOW_PRIORITY'; MANUAL: 'MANUAL'; MAP: 'MAP'; +MASK: 'MASK'; Review Comment: should add to non-reserved key word list in DorisParser.g4 ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowPolicyCommand.java: ########## @@ -0,0 +1,75 @@ +// 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.ShowPolicyStmt; +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.AnalysisException; +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) { + ShowPolicyStmt showPolicyStmt = new ShowPolicyStmt(PolicyTypeEnum.DATA_MASK, user, roleName); Review Comment: do not reuse ShowPolicyStmt -- 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