LakshSingla commented on code in PR #17564: URL: https://github.com/apache/druid/pull/17564#discussion_r1903721744
########## processing/src/main/java/org/apache/druid/query/RestrictedDataSource.java: ########## @@ -0,0 +1,212 @@ +/* + * 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.druid.query; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.collect.ImmutableList; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.query.planning.DataSourceAnalysis; +import org.apache.druid.query.policy.Policy; +import org.apache.druid.segment.RestrictedSegment; +import org.apache.druid.segment.SegmentReference; +import org.apache.druid.utils.JvmUtils; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Function; + +/** + * Reperesents a TableDataSource with row-level restriction. + * <p> + * A RestrictedDataSource means the base TableDataSource has restriction imposed. A table without any restriction should + * never be transformed to a RestrictedDataSource. Druid internal system and admin users would have a null rowFilter, + * while external users would have a rowFilter based on the applied restriction. + */ +public class RestrictedDataSource implements DataSource +{ + private final TableDataSource base; + private final Policy policy; + + @JsonProperty("base") + public TableDataSource getBase() + { + return base; + } + + @JsonProperty("policy") + public Policy getPolicy() + { + return policy; + } + + RestrictedDataSource(TableDataSource base, Policy policy) + { + this.base = base; + this.policy = policy; + } + + @JsonCreator + public static RestrictedDataSource create( + @JsonProperty("base") DataSource base, + @JsonProperty("policy") Policy policy + ) + { + if (!(base instanceof TableDataSource)) { + throw new IAE("Expected a TableDataSource, got [%s]", base.getClass()); + } + if (Objects.isNull(policy)) { + throw new IAE("Policy can't be null for RestrictedDataSource"); Review Comment: Passer-by nits: 1. It is better to use DruidExceptions instead of IAE/ISE. That would inform the readers as to whom the error message is intended for. It also guides the wording of the error message. Currently, it is not actionable. It is fine if the check is defensive, but if it is a user-facing error it would be nice to word it in a way that's easier for users to understand/take action upon. 2. The interpolations `[]` can be in a [different manner](https://github.com/apache/druid/blob/master/dev/style-conventions.md#message-formatting-for-logs-and-exceptions), where the exception is still understandable even if the interpolated phrases are removed, like: "Incorrect datasource [%s] received, expected a TableDataSource" -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
