github-code-scanning[bot] commented on code in PR #15058:
URL: https://github.com/apache/druid/pull/15058#discussion_r1341324963


##########
processing/src/main/java/org/apache/druid/query/filter/vector/VectorValueMatcher.java:
##########
@@ -33,13 +37,121 @@
 {
   /**
    * Examine the current vector and return a match indicating what is accepted.
-   *
+   * <p>
    * Does not modify "mask".
    *
-   * @param mask must not be null; use {@link VectorMatch#allTrue} if you 
don't need a mask.
-   *
+   * @param mask           must not be null; use {@link VectorMatch#allTrue} 
if you don't need a mask.
+   * @param includeUnknown mapping for Druid native two state logic system 
into SQL three-state logic system. If set
+   *                       to true, this method should also return true if the 
result is 'unknown' to be a match, such
+   *                       as from the input being null valued. Used primarily 
to allow
+   *                       {@link org.apache.druid.segment.filter.NotFilter} 
to invert a match in an SQL compliant
+   *                       manner
    * @return the subset of "mask" that this value matcher accepts. May be the 
same instance as {@param mask} if
    * every row in the mask matches the filter.
    */
-  ReadableVectorMatch match(ReadableVectorMatch mask);
+  ReadableVectorMatch match(ReadableVectorMatch mask, boolean includeUnknown);
+
+  /**
+   * Make a {@link VectorValueMatcher} that only selects input rows with null 
values
+   * @param selector
+   * @return
+   */
+  static VectorValueMatcher nullMatcher(VectorValueSelector selector)
+  {
+    return new BaseVectorValueMatcher(selector)
+    {
+      final VectorMatch match = VectorMatch.wrap(new 
int[selector.getMaxVectorSize()]);
+
+      @Override
+      public ReadableVectorMatch match(final ReadableVectorMatch mask, boolean 
includeUnknown)
+      {
+        return matchNulls(mask, match, selector.getNullVector());
+      }
+    };
+  }
+
+  /**
+   * Make an always false {@link VectorValueMatcher} for a {@link 
VectorValueSelector}. When {@code includeUnknown} is
+   * specified to the {@link VectorValueMatcher#match(ReadableVectorMatch, 
boolean)} function, this matcher will add
+   * the rows indicated as null values of {@link 
VectorValueSelector#getNullVector()} to the {@link ReadableVectorMatch}
+   * as selections, to participate in Druid 2-state logic system to SQL 
3-state logic system conversion.
+   */
+  static BaseVectorValueMatcher allFalseMatcher(VectorValueSelector selector)
+  {
+    return new BaseVectorValueMatcher(selector)
+    {
+      final VectorMatch match = VectorMatch.wrap(new 
int[selector.getMaxVectorSize()]);
+
+      @Override
+      public ReadableVectorMatch match(final ReadableVectorMatch mask, boolean 
includeUnknown)
+      {
+        if (includeUnknown) {
+          return matchNulls(mask, match, selector.getNullVector());
+        }
+        return VectorMatch.allFalse();
+      }
+    };
+  }
+
+  /**
+   * Make an always false {@link VectorValueMatcher} for a {@link 
VectorObjectSelector}. When {@code includeUnknown} is
+   * specified to the {@link VectorValueMatcher#match(ReadableVectorMatch, 
boolean)} function, this matcher will add
+   * all rows of {@link VectorObjectSelector#getObjectVector()} which are null 
to the {@link ReadableVectorMatch} as
+   * selections, to participate in Druid 2-state logic system to SQL 3-state 
logic system conversion.
+   */
+  static VectorValueMatcher allFalseMatcher(VectorObjectSelector selector)

Review Comment:
   ## Confusing overloading of methods
   
   Method VectorValueMatcher.allFalseMatcher(..) could be confused with 
overloaded method [allFalseMatcher](1), since dispatch depends on static types.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5839)



##########
processing/src/main/java/org/apache/druid/segment/filter/ValueMatchers.java:
##########
@@ -315,6 +339,123 @@
     };
   }
 
+  public static ValueMatcher makeAlwaysFalseMatcher(final DimensionSelector 
selector, boolean multiValue)
+  {
+    final IdLookup lookup = selector.idLookup();
+    // if the column doesn't have null
+    if (lookup == null || !selector.nameLookupPossibleInAdvance()) {
+      return new ValueMatcher()
+      {
+        @Override
+        public boolean matches(boolean includeUnknown)
+        {
+          if (includeUnknown) {
+            IndexedInts row = selector.getRow();
+            if (row.size() == 0) {
+              return true;
+            }
+            for (int i = 0; i < row.size(); i++) {
+              if 
(NullHandling.isNullOrEquivalent(selector.lookupName(row.get(i)))) {
+                return true;
+              }
+            }
+          }
+          return false;
+        }
+
+        @Override
+        public void inspectRuntimeShape(RuntimeShapeInspector inspector)
+        {
+          inspector.visit("selector", selector);
+        }
+      };
+    } else {
+      final int nullId = lookup.lookupId(null);
+      if (nullId < 0) {
+        // column doesn't have null value so no unknowns, can safely return 
always false matcher
+        return ValueMatchers.allFalse();
+      }
+      if (multiValue) {
+        return new ValueMatcher()
+        {
+          @Override
+          public boolean matches(boolean includeUnknown)
+          {
+            if (includeUnknown) {
+              IndexedInts row = selector.getRow();
+              if (row.size() == 0) {
+                return true;
+              }
+              for (int i = 0; i < row.size(); i++) {
+                if (row.get(i) == nullId) {
+                  return true;
+                }
+              }
+            }
+            return false;
+          }
+
+          @Override
+          public void inspectRuntimeShape(RuntimeShapeInspector inspector)
+          {
+            inspector.visit("selector", selector);
+          }
+        };
+      } else {
+        return new ValueMatcher()
+        {
+          @Override
+          public boolean matches(boolean includeUnknown)
+          {
+            return includeUnknown && selector.getRow().get(0) == nullId;
+          }
+
+          @Override
+          public void inspectRuntimeShape(RuntimeShapeInspector inspector)
+          {
+            inspector.visit("selector", selector);
+          }
+        };
+      }
+    }
+  }
+
+  public static ValueMatcher 
makeAlwaysFalseMatcher(BaseNullableColumnValueSelector selector)

Review Comment:
   ## Confusing overloading of methods
   
   Method ValueMatchers.makeAlwaysFalseMatcher(..) could be confused with 
overloaded method [makeAlwaysFalseMatcher](1), since dispatch depends on static 
types.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5840)



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