gianm commented on a change in pull request #6794: Query vectorization.
URL: https://github.com/apache/incubator-druid/pull/6794#discussion_r300593686
 
 

 ##########
 File path: 
processing/src/main/java/org/apache/druid/query/vector/VectorCursorGranularizer.java
 ##########
 @@ -0,0 +1,171 @@
+/*
+ * 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.vector;
+
+import com.google.common.collect.Iterables;
+import org.apache.druid.java.util.common.granularity.Granularity;
+import org.apache.druid.segment.StorageAdapter;
+import org.apache.druid.segment.column.ColumnHolder;
+import org.apache.druid.segment.vector.VectorCursor;
+import org.apache.druid.segment.vector.VectorValueSelector;
+import org.joda.time.DateTime;
+import org.joda.time.Interval;
+
+import javax.annotation.Nullable;
+
+/**
+ * Class that helps vectorized query engines handle "granularity" parameters. 
Nonvectorized engines have it handled
+ * for them by the StorageAdapter. Vectorized engines don't, because they can 
get efficiency gains by pushing
+ * granularity handling into the engine layer.
+ */
+public class VectorCursorGranularizer
+{
+  // And a cursor that has been made from it.
+  private final VectorCursor cursor;
+
+  // Iterable that iterates over time buckets.
+  private final Iterable<Interval> bucketIterable;
+
+  // Vector selector for the "__time" column.
+  @Nullable
+  private final VectorValueSelector timeSelector;
+
+  // Current time vector.
+  @Nullable
+  private long[] timestamps = null;
+
+  // Offset into the vector that we should start reading from.
+  private int startOffset = 0;
+
+  // Offset into the vector that is one past the last one we should read.
+  private int endOffset = 0;
+
+  private VectorCursorGranularizer(
+      VectorCursor cursor,
+      Iterable<Interval> bucketIterable,
+      @Nullable VectorValueSelector timeSelector
+  )
+  {
+    this.cursor = cursor;
+    this.bucketIterable = bucketIterable;
+    this.timeSelector = timeSelector;
+  }
+
+  @Nullable
+  public static VectorCursorGranularizer create(
+      final StorageAdapter storageAdapter,
+      final VectorCursor cursor,
+      final Granularity granularity,
+      final Interval cursorInterval
+  )
+  {
+    final DateTime minTime = storageAdapter.getMinTime();
+    final DateTime maxTime = storageAdapter.getMaxTime();
+    final Interval actualInterval = cursorInterval.overlap(new 
Interval(minTime, granularity.bucketEnd(maxTime)));
 
 Review comment:
   I thought about it a bit and I think `clippedQueryInterval` is the clearest 
name. I used that one.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org
For additional commands, e-mail: commits-h...@druid.apache.org

Reply via email to