gianm commented on code in PR #17564:
URL: https://github.com/apache/druid/pull/17564#discussion_r1910683359


##########
processing/src/main/java/org/apache/druid/query/RestrictedDataSource.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * 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.NoRestrictionPolicy;
+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 policy restriction.
+ * <p>
+ * A RestrictedDataSource means the base TableDataSource has policy imposed. A 
table without any policy should never be
+ * transformed to a RestrictedDataSource. Druid internal system and admin 
users would have a {@link NoRestrictionPolicy}.
+ */
+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 data source type [%s]", 
base.getClass());
+    }
+    if (Objects.isNull(policy)) {
+      throw new IAE("Policy can't be null for RestrictedDataSource");
+    }
+    return new RestrictedDataSource((TableDataSource) base, policy);
+  }
+
+  @Override
+  public Set<String> getTableNames()
+  {
+    return base.getTableNames();
+  }
+
+  @Override
+  public List<DataSource> getChildren()
+  {
+    return ImmutableList.of(base);
+  }
+
+  @Override
+  public DataSource withChildren(List<DataSource> children)
+  {
+    if (children.size() != 1) {
+      throw new IAE("Expected [1] child, got [%d]", children.size());
+    }
+
+    return create(children.get(0), policy);
+  }
+
+  @Override
+  public boolean isCacheable(boolean isBroker)
+  {
+    return false;

Review Comment:
   Just noting that this `return false` here means that when policies are in 
play, caching won't be possible. This is OK for this patch. We'll want to 
address it in a follow up by adding `getCacheKey()` to `Policy` and using those 
to compute the cache key for `RestrictedDataSource`.



-- 
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]

Reply via email to