leventov commented on a change in pull request #8209: add mechanism to control 
filter optimization in historical query processing
URL: https://github.com/apache/incubator-druid/pull/8209#discussion_r311688559
 
 

 ##########
 File path: 
processing/src/main/java/org/apache/druid/segment/filter/Filters.java
 ##########
 @@ -651,4 +652,31 @@ private static void generateAllCombinations(
       generateAllCombinations(result, andList.subList(1, andList.size()), 
nonAndList);
     }
   }
+
+  /**
+   * This method provides a "standard" implementation of {@link 
Filter#shouldUseIndex(BitmapIndexSelector)} which takes
+   * a {@link Filter}, a {@link BitmapIndexSelector}, and {@link FilterTuning} 
to determine if:
+   *  a) the filter supports bitmap indexes
+   *  b) the filter tuning specifies that it should use the index
+   *  c) the cardinality of the column is above the minimum threshold and 
below the maximum threshold to use the index
+   *
+   * If all these things are true, {@link 
org.apache.druid.segment.QueryableIndexStorageAdapter} will utilize the
+   * indexes.
+   */
+  public static boolean shouldUseIndex(
+      Filter filter,
+      BitmapIndexSelector indexSelector,
+      @Nullable FilterTuning filterTuning
+  )
+  {
+    final FilterTuning tuning = filterTuning != null ? filterTuning : 
FilterTuning.createDefault(filter, indexSelector);
+    if (filter.supportsBitmapIndex(indexSelector) && tuning.getUseIndex()) {
+      return filter.getRequiredColumns().stream().allMatch(column -> {
+        final int cardinality = 
indexSelector.getBitmapIndex(column).getCardinality();
 
 Review comment:
   It's not obvious that `filter.supportsBitmapIndex(indexSelector)` above 
guarantees that `indexSelector.getBitmapIndex(column)` is non-null for every 
column. If it does, please add the corresponding mandate in the Javadoc for 
`supportsBitmapIndex()`. If it doesn't please add a null guard.
   
   Please also annotate `BitmapIndexSelector.supportsBitmapIndex()` as 
`@Nullable`.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to