cecemei commented on code in PR #17055:
URL: https://github.com/apache/druid/pull/17055#discussion_r1759577277
##########
processing/src/main/java/org/apache/druid/query/filter/FilterBundle.java:
##########
@@ -151,6 +151,91 @@ public interface MatcherBundle
boolean canVectorize();
}
+ /**
+ * Wraps info needed to build a {@link FilterBundle}, and provides an
estimated compute cost for
+ * {@link BitmapColumnIndex#computeBitmapResult}.
+ */
+ public static class Builder
+ {
+ private final Filter filter;
+ private final ColumnIndexSelector columnIndexSelector;
+ @Nullable
+ private final BitmapColumnIndex bitmapColumnIndex;
+ private final List<FilterBundle.Builder> childBuilders;
+ private final int estimatedComputeCost;
+
+ public Builder(Filter filter, ColumnIndexSelector columnIndexSelector)
+ {
+ this.filter = filter;
+ this.columnIndexSelector = columnIndexSelector;
+ this.bitmapColumnIndex =
filter.getBitmapColumnIndex(columnIndexSelector);
+ // Construct Builder instances for all child filters recursively.
+ this.childBuilders = new ArrayList<>(filter.getFilters().size());
+ for (Filter childFilter : filter.getFilters()) {
+ childBuilders.add(new FilterBundle.Builder(childFilter,
columnIndexSelector));
+ }
+ // Sort child builders by cost in ASCENDING order, should be stable by
default.
+
this.childBuilders.sort(Comparator.comparingInt(FilterBundle.Builder::getEstimatedComputeCost));
+ this.estimatedComputeCost = calculateEstimatedComputeCost();
+ }
+
+ private int calculateEstimatedComputeCost()
+ {
+ if (this.bitmapColumnIndex == null) {
+ return Integer.MAX_VALUE;
+ }
+ int cost = this.bitmapColumnIndex.estimatedComputeCost();
+ if (cost == Integer.MAX_VALUE) {
+ return Integer.MAX_VALUE;
+ }
+
+ for (FilterBundle.Builder childBuilder : this.childBuilders) {
+ int childCost = childBuilder.getEstimatedComputeCost();
+ if (childCost >= Integer.MAX_VALUE - cost) {
+ return Integer.MAX_VALUE;
+ }
+ cost += childCost;
+ }
+ return cost;
+ }
+
+ public Filter getFilter()
+ {
+ return this.filter;
+ }
+
+ public ColumnIndexSelector getColumnIndexSelector()
+ {
+ return this.columnIndexSelector;
+ }
+
+ @Nullable
+ public BitmapColumnIndex getBitmapColumnIndex()
+ {
+ return this.bitmapColumnIndex;
+ }
+
+ public List<FilterBundle.Builder> getChildBuilders()
+ {
+ return this.childBuilders;
+ }
+
+ public int getEstimatedComputeCost()
Review Comment:
updated variable name to `estimatedIndexComputeCost`.
--
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]