Skip to content

Commit

Permalink
Optimize NullableSingleInputAggregationFunction when entire block is …
Browse files Browse the repository at this point in the history
…null (apache#13758)
  • Loading branch information
yashmayya authored Aug 14, 2024
1 parent 68252b7 commit 14e51e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public void forEachNotNull(int length, BlockValSet blockValSet, BatchConsumer co
return;
}

forEachNotNull(length, roaringBitmap.getIntIterator(), consumer);
// Skip if entire block is null
if (!roaringBitmap.contains(0, length)) {
forEachNotNull(length, roaringBitmap.getIntIterator(), consumer);
}
}

/**
Expand Down Expand Up @@ -118,6 +121,11 @@ public <A> A foldNotNull(int length, BlockValSet blockValSet, A initialAcum, Red
* @param <A> The type of the accumulator
*/
public <A> A foldNotNull(int length, @Nullable RoaringBitmap roaringBitmap, A initialAcum, Reducer<A> reducer) {
// Exit early if entire block is null
if (_nullHandlingEnabled && roaringBitmap != null && roaringBitmap.contains(0, length)) {
return initialAcum;
}

IntIterator intIterator = roaringBitmap == null ? null : roaringBitmap.getIntIterator();
return foldNotNull(length, intIterator, initialAcum, reducer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public class BenchmarkModeAggregation extends AbstractAggregationFunctionBenchma
@Param({"100", "50", "0"})
public int _nullHandlingEnabledPerCent;
private boolean _nullHandlingEnabled;
@Param({"2", "4", "8", "16", "32", "64", "128"})
@Param({"1", "2", "4", "8", "16", "32", "64", "128"})
protected int _nullPeriod;
private final Random _segmentNullRandomGenerator = new Random(42);
private double _modeIgnoringNull;
private double _modeNullAware;
private Double _modeIgnoringNull;
private Double _modeNullAware;
private final int _numDocs = DocIdSetPlanNode.MAX_DOC_PER_CALL;

public static void main(String[] args)
Expand Down Expand Up @@ -122,11 +122,15 @@ public void setupTrial() {
.get()
.getKey()
.doubleValue();
_modeNullAware = nullAwareDistribution.entrySet().stream()
.max(Comparator.comparingInt(Map.Entry::getValue))
.get()
.getKey()
.doubleValue();
if (nullAwareDistribution.isEmpty()) {
_modeNullAware = null;
} else {
_modeNullAware = nullAwareDistribution.entrySet().stream()
.max(Comparator.comparingInt(Map.Entry::getValue))
.get()
.getKey()
.doubleValue();
}
}

@Override
Expand Down

0 comments on commit 14e51e8

Please sign in to comment.