You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/06/18 21:25:20 UTC

[GitHub] [incubator-pinot] Jackie-Jiang commented on a change in pull request #7068: Make BitmapDocIdSetOperator a top level operator

Jackie-Jiang commented on a change in pull request #7068:
URL: https://github.com/apache/incubator-pinot/pull/7068#discussion_r654077802



##########
File path: pinot-core/src/main/java/org/apache/pinot/core/operator/BitmapDocIdSetOperator.java
##########
@@ -0,0 +1,71 @@
+/**
+ * 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.pinot.core.operator;
+
+import org.apache.pinot.core.operator.blocks.DocIdSetBlock;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.roaringbitmap.ImmutableBitmapDataProvider;
+import org.roaringbitmap.IntIterator;
+
+
+/**
+ * The <code>BitmapDocIdSetOperator</code> takes a bitmap of document ids and returns blocks of document ids.
+ * <p>Should call {@link #nextBlock()} multiple times until it returns <code>null</code> (already exhausts all the
+ * documents) or already gathered enough documents (for selection queries).
+ */
+public class BitmapDocIdSetOperator extends BaseOperator<DocIdSetBlock> {
+  private static final String OPERATOR_NAME = "BitmapDocIdSetOperator";
+
+  private final IntIterator _intIterator;
+  private final int[] _docIdBuffer;
+
+  public BitmapDocIdSetOperator(ImmutableBitmapDataProvider bitmap) {
+    _intIterator = bitmap.getIntIterator();
+    _docIdBuffer = new int[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+  }
+
+  public BitmapDocIdSetOperator(ImmutableBitmapDataProvider bitmap, int numDocs) {
+    _intIterator = bitmap.getIntIterator();
+    _docIdBuffer = new int[Math.min(numDocs, DocIdSetPlanNode.MAX_DOC_PER_CALL)];
+  }
+
+  public BitmapDocIdSetOperator(ImmutableBitmapDataProvider bitmap, int[] docIdBuffer) {
+    _intIterator = bitmap.getIntIterator();
+    _docIdBuffer = docIdBuffer;
+  }
+
+  @Override
+  protected DocIdSetBlock getNextBlock() {
+    int bufferSize = _docIdBuffer.length;
+    int index = 0;
+    while (index < bufferSize && _intIterator.hasNext()) {
+      _docIdBuffer[index++] = _intIterator.next();
+    }

Review comment:
       Good point. Currently in order to use the batch iterator, we have to use a second buffer to hold the ids for the container and then copy them into the main buffer. This extra logic will bring overhead and might not worth it. If we can modify the roaring bitmap's batch iterator semantic, then that's definitely a good optimization. For now I'll put a TODO for the potential optimization.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org