raghavyadav01 commented on code in PR #17060:
URL: https://github.com/apache/pinot/pull/17060#discussion_r2512635184


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/filter/RawValueInvertedIndexFilterOperator.java:
##########
@@ -0,0 +1,193 @@
+/**
+ * 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 com.google.common.base.CaseFormat;
+import java.util.Collections;
+import java.util.List;
+import org.apache.pinot.common.request.context.predicate.EqPredicate;
+import org.apache.pinot.common.request.context.predicate.InPredicate;
+import org.apache.pinot.common.request.context.predicate.NotEqPredicate;
+import org.apache.pinot.common.request.context.predicate.NotInPredicate;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+import org.apache.pinot.core.common.BlockDocIdSet;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.ExplainAttributeBuilder;
+import org.apache.pinot.core.operator.docidsets.BitmapDocIdSet;
+import org.apache.pinot.core.operator.docidsets.EmptyDocIdSet;
+import org.apache.pinot.core.operator.filter.predicate.PredicateEvaluator;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import 
org.apache.pinot.segment.local.segment.index.readers.RawValueBitmapInvertedIndexReader;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.roaringbitmap.buffer.ImmutableRoaringBitmap;
+import org.roaringbitmap.buffer.MutableRoaringBitmap;
+
+/**
+ * Filter operator that uses raw value bitmap inverted index to handle 
predicates on raw encoded columns.
+ */
+public class RawValueInvertedIndexFilterOperator extends 
BaseColumnFilterOperator {
+  private static final String EXPLAIN_NAME = "FILTER_RAW_INVERTED_INDEX";
+
+  private final PredicateEvaluator _predicateEvaluator;
+  private final RawValueBitmapInvertedIndexReader _invertedIndexReader;
+  private final DataType _dataType;
+  private final boolean _exclusive;
+
+  public RawValueInvertedIndexFilterOperator(QueryContext queryContext, 
PredicateEvaluator predicateEvaluator,
+      DataSource dataSource, int numDocs) {
+    super(queryContext, dataSource, numDocs);
+    _predicateEvaluator = predicateEvaluator;
+    _invertedIndexReader = (RawValueBitmapInvertedIndexReader) 
dataSource.getInvertedIndex();
+    _dataType = dataSource.getDataSourceMetadata().getDataType();
+    _exclusive = predicateEvaluator.isExclusive();
+  }
+
+  @Override
+  protected BlockDocIdSet getTrues() {
+    // Handle null predicate
+    if (_predicateEvaluator.isAlwaysFalse()) {
+      return EmptyDocIdSet.getInstance();
+    }
+    if (_predicateEvaluator.isAlwaysTrue()) {
+      return new BitmapDocIdSet(new MutableRoaringBitmap(), _numDocs);
+    }
+
+    // Get bitmap for each matching value and OR them together
+    MutableRoaringBitmap result = computeMatchingBitmap();
+
+
+    return new BitmapDocIdSet(result, _numDocs);
+  }
+
+  private MutableRoaringBitmap computeMatchingBitmap() {
+    MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
+    Predicate predicate = _predicateEvaluator.getPredicate();
+    Predicate.Type predicateType = predicate.getType();
+    switch (predicateType) {
+      case EQ:
+        addMatchingValueBitmap(bitmap, ((EqPredicate) predicate).getValue());
+        break;
+      case NOT_EQ:
+        addMatchingValueBitmap(bitmap, ((NotEqPredicate) 
predicate).getValue());
+        break;
+      case IN:
+        for (String value : ((InPredicate) predicate).getValues()) {
+          addMatchingValueBitmap(bitmap, value);
+        }
+        break;
+      case NOT_IN:
+        for (String value : ((NotInPredicate) predicate).getValues()) {
+          addMatchingValueBitmap(bitmap, value);
+        }
+        break;
+      case RANGE:
+        // For range queries, we need to scan through all values and apply the 
predicate
+        // This is not efficient, but it's the only way to handle range 
queries with raw encoding
+        // TODO: Add support for range index with raw encoding
+        throw new UnsupportedOperationException("Range predicates not 
supported for raw encoded columns");

Review Comment:
   It will fail as of now. 



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