Skip to content

Commit 5a9082d

Browse files
committed
remove singleton DV related change
Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com>
1 parent 8641bbc commit 5a9082d

File tree

2 files changed

+2
-161
lines changed

2 files changed

+2
-161
lines changed

server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/FilterRewriteOptimizationContext.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
import org.apache.lucene.index.NumericDocValues;
1616
import org.apache.lucene.index.PointValues;
1717
import org.apache.lucene.search.DocIdSetIterator;
18-
import org.apache.lucene.search.Weight;
1918
import org.apache.lucene.util.DocIdSetBuilder;
2019
import org.opensearch.index.mapper.DocCountFieldMapper;
2120
import org.opensearch.search.aggregations.BucketCollector;
2221
import org.opensearch.search.aggregations.LeafBucketCollector;
2322
import org.opensearch.search.internal.SearchContext;
2423

2524
import java.io.IOException;
26-
import java.util.List;
2725
import java.util.concurrent.atomic.AtomicInteger;
2826
import java.util.function.BiConsumer;
2927
import java.util.function.Supplier;
@@ -74,7 +72,6 @@ public FilterRewriteOptimizationContext(
7472
private boolean canOptimize(final Object parent, final int subAggLength, SearchContext context) throws IOException {
7573
if (context.maxAggRewriteFilters() == 0) return false;
7674

77-
// if (parent != null || subAggLength != 0) return false;
7875
if (parent != null) return false;
7976
this.subAggLength = subAggLength;
8077

@@ -139,7 +136,6 @@ public boolean tryOptimize(
139136
Ranges ranges = getRanges(leafCtx, segmentMatchAll);
140137
if (ranges == null) return false;
141138

142-
// pass in the information of whether subagg exists
143139
Supplier<DocIdSetBuilder> disBuilderSupplier = null;
144140
if (subAggLength != 0) {
145141
disBuilderSupplier = () -> {
@@ -150,7 +146,6 @@ public boolean tryOptimize(
150146
}
151147
};
152148
}
153-
154149
OptimizeResult optimizeResult = aggregatorBridge.tryOptimize(values, incrementDocCount, ranges, disBuilderSupplier);
155150
consumeDebugInfo(optimizeResult);
156151

@@ -181,12 +176,6 @@ public boolean tryOptimize(
181176
return true;
182177
}
183178

184-
List<Weight> weights;
185-
186-
public List<Weight> getWeights() {
187-
return weights;
188-
}
189-
190179
Ranges getRanges(LeafReaderContext leafCtx, boolean segmentMatchAll) {
191180
if (!preparedAtShardLevel) {
192181
try {
@@ -196,7 +185,6 @@ Ranges getRanges(LeafReaderContext leafCtx, boolean segmentMatchAll) {
196185
return null;
197186
}
198187
}
199-
logger.debug("number of ranges: {}", ranges.lowers.length);
200188
return ranges;
201189
}
202190

server/src/main/java/org/opensearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregator.java

Lines changed: 2 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131

3232
package org.opensearch.search.aggregations.bucket.histogram;
3333

34-
import org.apache.lucene.index.DocValues;
3534
import org.apache.lucene.index.LeafReaderContext;
36-
import org.apache.lucene.index.NumericDocValues;
3735
import org.apache.lucene.index.SortedNumericDocValues;
3836
import org.apache.lucene.search.CollectionTerminatedException;
3937
import org.apache.lucene.search.ScoreMode;
@@ -247,8 +245,6 @@ public final DeferringBucketCollector getDeferringCollector() {
247245

248246
protected abstract LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) throws IOException;
249247

250-
protected abstract LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) throws IOException;
251-
252248
@Override
253249
public final LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) throws IOException {
254250
if (valuesSource == null) {
@@ -265,8 +261,7 @@ public final LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBuc
265261
if (optimized) throw new CollectionTerminatedException();
266262

267263
final SortedNumericDocValues values = valuesSource.longValues(ctx);
268-
final NumericDocValues singleton = DocValues.unwrapSingleton(values);
269-
final LeafBucketCollector iteratingCollector = singleton != null ? getLeafCollector(singleton, sub) : getLeafCollector(values, sub);
264+
final LeafBucketCollector iteratingCollector = getLeafCollector(values, sub);
270265
return new LeafBucketCollectorBase(sub, values) {
271266
@Override
272267
public void collect(int doc, long owningBucketOrd) throws IOException {
@@ -330,7 +325,7 @@ protected final void merge(long[] mergeMap, long newNumBuckets) {
330325
@Override
331326
public void collectDebugInfo(BiConsumer<String, Object> add) {
332327
super.collectDebugInfo(add);
333-
// filterRewriteOptimizationContext.populateDebugInfo(add);
328+
filterRewriteOptimizationContext.populateDebugInfo(add);
334329
}
335330

336331
/**
@@ -487,65 +482,6 @@ private void increaseRoundingIfNeeded(long rounded) {
487482
};
488483
}
489484

490-
protected LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) throws IOException {
491-
return new LeafBucketCollectorBase(sub, values) {
492-
@Override
493-
public void collect(int doc, long owningBucketOrd) throws IOException {
494-
assert owningBucketOrd == 0;
495-
// if (false == values.advanceExact(doc)) {
496-
// return;
497-
// }
498-
//
499-
// long value = values.longValue();
500-
// long rounded = preparedRounding.round(value);
501-
// collectValue(doc, rounded);
502-
if (values.advanceExact(doc)) {
503-
collectValue(doc, preparedRounding.round(values.longValue()));
504-
}
505-
}
506-
507-
private void collectValue(int doc, long rounded) throws IOException {
508-
long bucketOrd = bucketOrds.add(0, rounded);
509-
if (bucketOrd < 0) { // already seen
510-
bucketOrd = -1 - bucketOrd;
511-
collectExistingBucket(sub, doc, bucketOrd);
512-
return;
513-
}
514-
collectBucket(sub, doc, bucketOrd);
515-
increaseRoundingIfNeeded(rounded);
516-
}
517-
518-
private void increaseRoundingIfNeeded(long rounded) {
519-
if (roundingIdx >= roundingInfos.length - 1) {
520-
return;
521-
}
522-
min = Math.min(min, rounded);
523-
max = Math.max(max, rounded);
524-
if (bucketOrds.size() <= targetBuckets * roundingInfos[roundingIdx].getMaximumInnerInterval()
525-
&& max - min <= targetBuckets * roundingInfos[roundingIdx].getMaximumRoughEstimateDurationMillis()) {
526-
return;
527-
}
528-
do {
529-
try (LongKeyedBucketOrds oldOrds = bucketOrds) {
530-
preparedRounding = prepareRounding(++roundingIdx);
531-
long[] mergeMap = new long[Math.toIntExact(oldOrds.size())];
532-
bucketOrds = new LongKeyedBucketOrds.FromSingle(context.bigArrays());
533-
LongKeyedBucketOrds.BucketOrdsEnum ordsEnum = oldOrds.ordsEnum(0);
534-
while (ordsEnum.next()) {
535-
long oldKey = ordsEnum.value();
536-
long newKey = preparedRounding.round(oldKey);
537-
long newBucketOrd = bucketOrds.add(0, newKey);
538-
mergeMap[(int) ordsEnum.ord()] = newBucketOrd >= 0 ? newBucketOrd : -1 - newBucketOrd;
539-
}
540-
merge(mergeMap, bucketOrds.size());
541-
}
542-
} while (roundingIdx < roundingInfos.length - 1
543-
&& (bucketOrds.size() > targetBuckets * roundingInfos[roundingIdx].getMaximumInnerInterval()
544-
|| max - min > targetBuckets * roundingInfos[roundingIdx].getMaximumRoughEstimateDurationMillis()));
545-
}
546-
};
547-
}
548-
549485
@Override
550486
public InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws IOException {
551487
return buildAggregations(bucketOrds, l -> roundingIdx, owningBucketOrds);
@@ -794,89 +730,6 @@ private int increaseRoundingIfNeeded(long owningBucketOrd, int oldEstimatedBucke
794730
};
795731
}
796732

797-
@Override
798-
protected LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) throws IOException {
799-
return new LeafBucketCollectorBase(sub, values) {
800-
@Override
801-
public void collect(int doc, long owningBucketOrd) throws IOException {
802-
if (false == values.advanceExact(doc)) {
803-
return;
804-
}
805-
806-
int roundingIdx = roundingIndexFor(owningBucketOrd);
807-
long value = values.longValue();
808-
long rounded = preparedRoundings[roundingIdx].round(value);
809-
collectValue(owningBucketOrd, roundingIdx, doc, rounded);
810-
}
811-
812-
private int collectValue(long owningBucketOrd, int roundingIdx, int doc, long rounded) throws IOException {
813-
long bucketOrd = bucketOrds.add(owningBucketOrd, rounded);
814-
if (bucketOrd < 0) { // already seen
815-
bucketOrd = -1 - bucketOrd;
816-
collectExistingBucket(sub, doc, bucketOrd);
817-
return roundingIdx;
818-
}
819-
collectBucket(sub, doc, bucketOrd);
820-
liveBucketCountUnderestimate = context.bigArrays().grow(liveBucketCountUnderestimate, owningBucketOrd + 1);
821-
int estimatedBucketCount = liveBucketCountUnderestimate.increment(owningBucketOrd, 1);
822-
return increaseRoundingIfNeeded(owningBucketOrd, estimatedBucketCount, rounded, roundingIdx);
823-
}
824-
825-
/**
826-
* Increase the rounding of {@code owningBucketOrd} using
827-
* estimated, bucket counts, {@link FromMany#rebucket()} rebucketing} the all
828-
* buckets if the estimated number of wasted buckets is too high.
829-
*/
830-
private int increaseRoundingIfNeeded(long owningBucketOrd, int oldEstimatedBucketCount, long newKey, int oldRounding) {
831-
if (oldRounding >= roundingInfos.length - 1) {
832-
return oldRounding;
833-
}
834-
if (mins.size() < owningBucketOrd + 1) {
835-
long oldSize = mins.size();
836-
mins = context.bigArrays().grow(mins, owningBucketOrd + 1);
837-
mins.fill(oldSize, mins.size(), Long.MAX_VALUE);
838-
}
839-
if (maxes.size() < owningBucketOrd + 1) {
840-
long oldSize = maxes.size();
841-
maxes = context.bigArrays().grow(maxes, owningBucketOrd + 1);
842-
maxes.fill(oldSize, maxes.size(), Long.MIN_VALUE);
843-
}
844-
845-
long min = Math.min(mins.get(owningBucketOrd), newKey);
846-
mins.set(owningBucketOrd, min);
847-
long max = Math.max(maxes.get(owningBucketOrd), newKey);
848-
maxes.set(owningBucketOrd, max);
849-
if (oldEstimatedBucketCount <= targetBuckets * roundingInfos[oldRounding].getMaximumInnerInterval()
850-
&& max - min <= targetBuckets * roundingInfos[oldRounding].getMaximumRoughEstimateDurationMillis()) {
851-
return oldRounding;
852-
}
853-
long oldRoughDuration = roundingInfos[oldRounding].roughEstimateDurationMillis;
854-
int newRounding = oldRounding;
855-
int newEstimatedBucketCount;
856-
do {
857-
newRounding++;
858-
double ratio = (double) oldRoughDuration / (double) roundingInfos[newRounding].getRoughEstimateDurationMillis();
859-
newEstimatedBucketCount = (int) Math.ceil(oldEstimatedBucketCount * ratio);
860-
} while (newRounding < roundingInfos.length - 1
861-
&& (newEstimatedBucketCount > targetBuckets * roundingInfos[newRounding].getMaximumInnerInterval()
862-
|| max - min > targetBuckets * roundingInfos[newRounding].getMaximumRoughEstimateDurationMillis()));
863-
setRounding(owningBucketOrd, newRounding);
864-
mins.set(owningBucketOrd, preparedRoundings[newRounding].round(mins.get(owningBucketOrd)));
865-
maxes.set(owningBucketOrd, preparedRoundings[newRounding].round(maxes.get(owningBucketOrd)));
866-
wastedBucketsOverestimate += oldEstimatedBucketCount - newEstimatedBucketCount;
867-
if (wastedBucketsOverestimate > nextRebucketAt) {
868-
rebucket();
869-
// Bump the threshold for the next rebucketing
870-
wastedBucketsOverestimate = 0;
871-
nextRebucketAt *= 2;
872-
} else {
873-
liveBucketCountUnderestimate.set(owningBucketOrd, newEstimatedBucketCount);
874-
}
875-
return newRounding;
876-
}
877-
};
878-
}
879-
880733
private void rebucket() {
881734
rebucketCount++;
882735
try (LongKeyedBucketOrds oldOrds = bucketOrds) {

0 commit comments

Comments
 (0)