loquisgon commented on a change in pull request #10742:
URL: https://github.com/apache/druid/pull/10742#discussion_r557576226



##########
File path: 
server/src/main/java/org/apache/druid/segment/indexing/LookupIntervalBuckets.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.indexing;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Iterators;
+import org.apache.druid.java.util.common.DateTimes;
+import org.apache.druid.java.util.common.guava.Comparators;
+import org.joda.time.DateTime;
+import org.joda.time.Interval;
+
+import java.util.Iterator;
+import java.util.TreeSet;
+
+public class LookupIntervalBuckets
+{
+  private final Iterable<Interval> intervalIterable;
+  private final TreeSet<Interval> intervals;
+
+  public LookupIntervalBuckets(Iterable<Interval> intervalIterable)

Review comment:
       I added this class to more cleanly re-use the TreeSet logic for bucket 
extraction among the `ArbitraryGranularitySpec` and the 
`UniformGranularitySpec`. The code in this PR goal is to avoid materialization 
of intervals in the Overlord only. We will deal with materialization issues 
elsewhere later. Thus when code outside the Overlord needs to get a bucket for 
a particuar `DateTime` then the code will actually materialize all the 
intervals and stores them in a fast lookup data structure (like `TreeSet`) to 
return the bucket. We could still iterate through all the intervals and find 
the bucket (since the intervals are sorted) but that would be linear in the 
number of the intervals for every call. This is not acceptable given the 
frequency of calling the method to find the bucket. We feel we can improve on 
this but we decided to divide the work and at least for now prevent the 
materialization of intervals in the overlord (see PR description also).




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

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