You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "shenyu0127 (via GitHub)" <gi...@apache.org> on 2023/07/21 16:29:19 UTC

[GitHub] [pinot] shenyu0127 commented on a diff in pull request #11078: Filtering NULL support.

shenyu0127 commented on code in PR #11078:
URL: https://github.com/apache/pinot/pull/11078#discussion_r1270846159


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/docidsets/BitmapDocIdSet.java:
##########
@@ -27,6 +27,13 @@ public class BitmapDocIdSet implements BlockDocIdSet {
   private final BitmapDocIdIterator _iterator;
 
   public BitmapDocIdSet(ImmutableRoaringBitmap docIds, int numDocs) {
+    this(docIds, numDocs, false);
+  }
+
+  public BitmapDocIdSet(ImmutableRoaringBitmap docIds, int numDocs, boolean exclusive) {

Review Comment:
   Good suggestion. Done.



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/NullHandlingSupportedFilterOperator.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.pinot.core.operator.filter;
+
+import java.util.Arrays;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.operator.blocks.FilterBlock;
+import org.apache.pinot.core.operator.docidsets.AndDocIdSet;
+import org.apache.pinot.core.operator.docidsets.BitmapDocIdSet;
+import org.apache.pinot.core.operator.docidsets.MatchAllDocIdSet;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+
+
+public abstract class NullHandlingSupportedFilterOperator extends BaseFilterOperator {
+  protected final QueryContext _queryContext;
+  protected final DataSource _dataSource;
+  protected final int _numDocs;
+
+  protected NullHandlingSupportedFilterOperator(QueryContext queryContext, DataSource dataSource, int numDocs) {
+    _queryContext = queryContext;
+    _dataSource = dataSource;
+    _numDocs = numDocs;
+  }
+
+  @Override
+  protected FilterBlock getNextBlock() {
+    if (_queryContext.isNullHandlingEnabled()) {
+      return new FilterBlock(excludeNulls(getNextBlockWithoutNullHandling()));
+    } else {
+      return new FilterBlock(getNextBlockWithoutNullHandling());
+    }
+  }
+
+  protected abstract BlockDocIdSet getNextBlockWithoutNullHandling();
+
+  private BlockDocIdSet excludeNulls(BlockDocIdSet blockDocIdSet) {
+    return new AndDocIdSet(
+        Arrays.asList(blockDocIdSet, fromNonNullBitmap()),
+        _queryContext.getQueryOptions());

Review Comment:
   Good catch. This comment no longer applies because I changed this code block.



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/NullHandlingSupportedFilterOperator.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.pinot.core.operator.filter;
+
+import java.util.Arrays;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.operator.blocks.FilterBlock;
+import org.apache.pinot.core.operator.docidsets.AndDocIdSet;
+import org.apache.pinot.core.operator.docidsets.BitmapDocIdSet;
+import org.apache.pinot.core.operator.docidsets.MatchAllDocIdSet;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+
+
+public abstract class NullHandlingSupportedFilterOperator extends BaseFilterOperator {

Review Comment:
   We can't put this logic inside `BaseFilterOperator` because some subclasses do not share the same logic. Here are some examples:
   
   - Non-leaf filter operators, e.g. `AndFilterOperator`
   - `TextMatchFilterOperator`
   - `ExpressionFilterOperator` (the `nullBitmap` is from `TransformFunction::getNullBitmap` so we don't need `_dataSource`)
   
   I renamed the class to `NullHandlingSupportedFilterOperator` to indicate it's the base class of a subset of filter operators.
   
   We might do some tweaks to make some leaf filter operators a subclass of this class, but I'd defer that to not increase the scope of this PR.



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/NullHandlingSupportedFilterOperator.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.pinot.core.operator.filter;
+
+import java.util.Arrays;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.operator.blocks.FilterBlock;
+import org.apache.pinot.core.operator.docidsets.AndDocIdSet;
+import org.apache.pinot.core.operator.docidsets.BitmapDocIdSet;
+import org.apache.pinot.core.operator.docidsets.MatchAllDocIdSet;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+
+
+public abstract class NullHandlingSupportedFilterOperator extends BaseFilterOperator {
+  protected final QueryContext _queryContext;
+  protected final DataSource _dataSource;
+  protected final int _numDocs;
+
+  protected NullHandlingSupportedFilterOperator(QueryContext queryContext, DataSource dataSource, int numDocs) {
+    _queryContext = queryContext;
+    _dataSource = dataSource;
+    _numDocs = numDocs;
+  }
+
+  @Override
+  protected FilterBlock getNextBlock() {
+    if (_queryContext.isNullHandlingEnabled()) {
+      return new FilterBlock(excludeNulls(getNextBlockWithoutNullHandling()));
+    } else {
+      return new FilterBlock(getNextBlockWithoutNullHandling());
+    }
+  }
+
+  protected abstract BlockDocIdSet getNextBlockWithoutNullHandling();
+
+  private BlockDocIdSet excludeNulls(BlockDocIdSet blockDocIdSet) {
+    return new AndDocIdSet(

Review Comment:
   Done.



-- 
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: commits-unsubscribe@pinot.apache.org

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