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


##########
processing/src/main/java/org/apache/druid/segment/RestrictedSegment.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.segment;
+
+import org.apache.druid.query.filter.DimFilter;
+import org.apache.druid.timeline.SegmentId;
+import org.joda.time.Interval;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Optional;
+
+/**
+ * A wrapped {@link SegmentReference} with a {@link DimFilter} restriction. 
The restriction must be applied on the
+ * segment.
+ */
+public class RestrictedSegment implements SegmentReference
+{
+  protected final SegmentReference delegate;
+  @Nullable
+  private final DimFilter filter;
+
+  public RestrictedSegment(
+      SegmentReference delegate,
+      @Nullable DimFilter filter
+  )
+  {
+    this.delegate = delegate;
+    this.filter = filter;
+  }
+
+  @Override
+  public Optional<Closeable> acquireReferences()
+  {
+    return delegate.acquireReferences();
+  }
+
+  @Override
+  public SegmentId getId()
+  {
+    return delegate.getId();
+  }
+
+  @Override
+  public Interval getDataInterval()
+  {
+    return delegate.getDataInterval();
+  }
+
+  @Override
+  public CursorFactory asCursorFactory()
+  {
+    return new RestrictedCursorFactory(delegate.asCursorFactory(), filter);
+  }
+
+  @Nullable
+  @Override
+  public QueryableIndex asQueryableIndex()
+  {
+    return null;
+  }
+
+  @Nullable
+  @Override
+  public <T> T as(@Nonnull Class<T> clazz)

Review Comment:
   > exception targeted at developers to indicate that they should call 
as(BypassRestrictedSegment.class)
   
   I was thinking that query engines might have fall-back code to do something 
cursor-based if `QueryableIndex` isn't available. They would need this anyway 
if they wanted to work on real-time data. Returning `null` in these cases lets 
the fall-back code activate.



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