morningman commented on code in PR #9786: URL: https://github.com/apache/incubator-doris/pull/9786#discussion_r885434959
########## fe/fe-core/src/main/java/org/apache/doris/policy/RowPolicy.java: ########## @@ -0,0 +1,174 @@ +// 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.CreatePolicyStmt; +import org.apache.doris.analysis.Expr; +import org.apache.doris.analysis.SqlParser; +import org.apache.doris.analysis.SqlScanner; +import org.apache.doris.analysis.UserIdentity; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.Table; +import org.apache.doris.common.AnalysisException; +import org.apache.doris.common.io.Text; +import org.apache.doris.common.util.SqlParserUtils; +import org.apache.doris.persist.gson.GsonUtils; + +import com.google.common.collect.Lists; +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import org.apache.commons.lang.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.DataInput; +import java.io.IOException; +import java.io.StringReader; +import java.util.List; + +/** + * Save policy for filtering data. + **/ +@Data +public class RowPolicy extends Policy { + + private static final Logger LOG = LogManager.getLogger(RowPolicy.class); + + /** + * Policy bind user. + **/ + @SerializedName(value = "user") + private UserIdentity user = null; + + @SerializedName(value = "dbId") + private long dbId = -1; + + @SerializedName(value = "tableId") + private long tableId = -1; + + /** + * PERMISSIVE | RESTRICTIVE, If multiple types exist, the last type prevails. + **/ + @SerializedName(value = "filterType") + private FilterType filterType = null; + + /** + * Use for Serialization/deserialization. + **/ + @SerializedName(value = "originStmt") + private String originStmt; + + private Expr wherePredicate = null; + + public RowPolicy() {} + + /** + * Policy for Table. Policy of ROW or others. + * + * @param type PolicyType + * @param policyName policy name + * @param dbId database i + * @param user username + * @param originStmt origin stmt + * @param tableId table id + * @param filterType filter type + * @param wherePredicate where predicate + */ + public RowPolicy(final PolicyTypeEnum type, final String policyName, long dbId, + UserIdentity user, String originStmt, final long tableId, + final FilterType filterType, final Expr wherePredicate) { + super(type, policyName); + this.user = user; + this.dbId = dbId; + this.tableId = tableId; + this.filterType = filterType; + this.originStmt = originStmt; + this.wherePredicate = wherePredicate; + } + + /** + * Use for SHOW POLICY. + **/ + public List<String> getShowInfo() throws AnalysisException { + Database database = Catalog.getCurrentCatalog().getDbOrAnalysisException(this.dbId); + Table table = database.getTableOrAnalysisException(this.tableId); + return Lists.newArrayList(this.policyName, database.getFullName(), table.getName(), this.type.name(), + this.filterType.name(), this.wherePredicate.toSql(), this.user.getQualifiedUser(), this.originStmt); + } + + /** + * Read Table Policy from file. + **/ + public static RowPolicy read(DataInput in) throws IOException { Review Comment: This `read` method should be implement in `Policy` abstract class. And you need to add a `RuntimeTypeAdapterFactory` in `GsonUtils` for derived class. You can refer to `Resource.java` and its derived class like `SparkResource` and `S3Resource`. And please add ut for the read/write method of RowPolicy, you can refer to `DropInfoTest.java` -- 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