You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2024/02/01 17:20:45 UTC

(pinot) branch master updated: Implement IN and NOT_IN filters in FilterOperand class (#12285 fix) (#12305)

This is an automated email from the ASF dual-hosted git repository.

jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 04cf96e03e Implement IN and NOT_IN filters in FilterOperand class (#12285 fix) (#12305)
04cf96e03e is described below

commit 04cf96e03e3266ad922ff16112e99a7f0d0a6589
Author: Miklos Gyorfi <gy...@users.noreply.github.com>
AuthorDate: Thu Feb 1 18:20:39 2024 +0100

    Implement IN and NOT_IN filters in FilterOperand class (#12285 fix) (#12305)
---
 .../runtime/operator/operands/FilterOperand.java   | 32 ++++++++++++++++++++++
 .../operator/operands/TransformOperandFactory.java |  6 ++++
 2 files changed, 38 insertions(+)

diff --git a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/FilterOperand.java b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/FilterOperand.java
index 62fd6478a9..46fc0845de 100644
--- a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/FilterOperand.java
+++ b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/FilterOperand.java
@@ -110,6 +110,38 @@ public abstract class FilterOperand implements TransformOperand {
     }
   }
 
+  public static class In extends FilterOperand {
+    List<TransformOperand> _childOperands;
+    boolean _isNotIn;
+
+    public In(List<RexExpression> children, DataSchema dataSchema, boolean isNotIn) {
+      _childOperands = new ArrayList<>(children.size());
+      for (RexExpression child : children) {
+        _childOperands.add(TransformOperandFactory.getTransformOperand(child, dataSchema));
+      }
+      _isNotIn = isNotIn;
+    }
+
+    @Nullable
+    @Override
+    public Integer apply(Object[] row) {
+      Object firstResult = _childOperands.get(0).apply(row);
+      if (firstResult == null) {
+        return null;
+      }
+      for (int i = 1; i < _childOperands.size(); i++) {
+        Object result = _childOperands.get(i).apply(row);
+        if (result == null) {
+          return null;
+        }
+        if (firstResult.equals(result)) {
+          return _isNotIn ? 0 : 1;
+        }
+      }
+      return _isNotIn ? 1 : 0;
+    }
+  }
+
   public static class IsTrue extends FilterOperand {
     TransformOperand _childOperand;
 
diff --git a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/TransformOperandFactory.java b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/TransformOperandFactory.java
index 4a95a8b162..0759fc4ce3 100644
--- a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/TransformOperandFactory.java
+++ b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/TransformOperandFactory.java
@@ -46,6 +46,12 @@ public class TransformOperandFactory {
     int numOperands = operands.size();
     String canonicalName = OperatorUtils.canonicalizeFunctionName(functionCall.getFunctionName());
     switch (canonicalName) {
+      case "IN":
+        Preconditions.checkState(numOperands >= 2, "IN takes >=2 arguments, got: %s", numOperands);
+        return new FilterOperand.In(operands, dataSchema, false);
+      case "NOT_IN":
+        Preconditions.checkState(numOperands >= 2, "NOT_IN takes >=2 arguments, got: %s", numOperands);
+        return new FilterOperand.In(operands, dataSchema, true);
       case "AND":
         Preconditions.checkState(numOperands >= 2, "AND takes >=2 arguments, got: %s", numOperands);
         return new FilterOperand.And(operands, dataSchema);


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