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

 ##########
 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:
   strengthened javadoc assertions about what is expected of these methods, 
also added a precondition check in `Filters.shouldUseBitmapIndex` to make sure 
the column has a bitmap index.

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