private void increaseRounding() { try (LongHash oldBucketOrds = bucketOrds) { LongHash newBucketOrds = new LongHash(1, context.bigArrays()); long[] mergeMap = new long[(int) oldBucketOrds.size()]; Rounding newRounding = roundingInfos[++roundingIdx].rounding; for (int i = 0; i < oldBucketOrds.size(); i++) { long oldKey = oldBucketOrds.get(i); long newKey = newRounding.round(oldKey); long newBucketOrd = newBucketOrds.add(newKey); if (newBucketOrd >= 0) { mergeMap[i] = newBucketOrd; } else { mergeMap[i] = -1 - newBucketOrd; } } mergeBuckets(mergeMap, newBucketOrds.size()); if (deferringCollector != null) { deferringCollector.mergeBuckets(mergeMap); } bucketOrds = newBucketOrds; } } };
@Override public InternalAggregation buildAggregation(long bucket) throws IOException { if (selectedBuckets == null) { throw new IllegalStateException("Collection has not been replayed yet."); } final long rebasedBucket = selectedBuckets.find(bucket); if (rebasedBucket == -1) { throw new IllegalStateException("Cannot build for a bucket which has not been collected"); } return in.buildAggregation(rebasedBucket); }
/** * Try to add <code>key</code>. Return its newly allocated id if it wasn't in the hash table yet, or <code>-1-id</code> * if it was already present in the hash table. */ public long add(long key) { if (size >= maxSize) { assert size == maxSize; grow(); } assert size < maxSize; return set(key, size); }
@Override public InternalAggregation buildAggregation(long owningBucketOrdinal) throws IOException { assert owningBucketOrdinal == 0; consumeBucketsAndMaybeBreak((int) bucketOrds.size()); long[] bucketOrdArray = new long[(int) bucketOrds.size()]; for (int i = 0; i < bucketOrds.size(); i++) { bucketOrdArray[i] = i; } runDeferredCollections(bucketOrdArray); List<InternalAutoDateHistogram.Bucket> buckets = new ArrayList<>((int) bucketOrds.size()); for (long i = 0; i < bucketOrds.size(); i++) { buckets.add(new InternalAutoDateHistogram.Bucket(bucketOrds.get(i), bucketDocCount(i), formatter, bucketAggregations(i))); } // the contract of the histogram aggregation is that shards must return // buckets ordered by key in ascending order CollectionUtil.introSort(buckets, BucketOrder.key(true).comparator(this)); // value source will be null for unmapped fields InternalAutoDateHistogram.BucketInfo emptyBucketInfo = new InternalAutoDateHistogram.BucketInfo(roundingInfos, roundingIdx, buildEmptySubAggregations()); return new InternalAutoDateHistogram(name, buckets, targetBuckets, emptyBucketInfo, formatter, pipelineAggregators(), metaData(), 1); }
GeoHashGridAggregator(String name, AggregatorFactories factories, GeoGridAggregationBuilder.CellIdSource valuesSource, int requiredSize, int shardSize, SearchContext aggregationContext, Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException { super(name, factories, aggregationContext, parent, pipelineAggregators, metaData); this.valuesSource = valuesSource; this.requiredSize = requiredSize; this.shardSize = shardSize; bucketOrds = new LongHash(1, aggregationContext.bigArrays()); }
final LongHash hash = new LongHash(selectedBuckets.length, BigArrays.NON_RECYCLING_INSTANCE); for (long bucket : selectedBuckets) { hash.add(bucket); doc += docDeltaIterator.next(); final long bucket = buckets.next(); final long rebasedBucket = hash.find(bucket); if (rebasedBucket != -1) { if (needsScores) {
private void collectGlobalOrd(int doc, long globalOrd, LeafBucketCollector sub) throws IOException { if (bucketOrds == null) { collectExistingBucket(sub, doc, globalOrd); } else { long bucketOrd = bucketOrds.add(globalOrd); if (bucketOrd < 0) { bucketOrd = -1 - bucketOrd; collectExistingBucket(sub, doc, bucketOrd); } else { collectBucket(sub, doc, bucketOrd); } } }
SignificantStringTerms.Bucket spare = null; final boolean needsFullScan = bucketOrds == null || bucketCountThresholds.getMinDocCount() == 0; final long maxId = needsFullScan ? valueCount : bucketOrds.size(); for (long ord = 0; ord < maxId; ord++) { final long globalOrd; final long bucketOrd; if (needsFullScan) { bucketOrd = bucketOrds == null ? ord : bucketOrds.find(ord); globalOrd = ord; } else { assert bucketOrds != null; bucketOrd = ord; globalOrd = bucketOrds.get(ord);
assert owningBucketOrdinal == 0; if (bucketCountThresholds.getMinDocCount() == 0 && (InternalOrder.isCountDesc(order) == false || bucketOrds.size() < bucketCountThresholds.getRequiredSize())) { long value = values.nextValue(); if (longFilter == null || longFilter.accept(value)) { bucketOrds.add(value); final int size = (int) Math.min(bucketOrds.size(), bucketCountThresholds.getShardSize()); long otherDocCount = 0; BucketPriorityQueue<LongTerms.Bucket> ordered = new BucketPriorityQueue<>(size, order.comparator(this)); LongTerms.Bucket spare = null; for (long i = 0; i < bucketOrds.size(); i++) { if (spare == null) { spare = new LongTerms.Bucket(0, 0, null, showTermDocCountError, 0, format); spare.term = bucketOrds.get(i); spare.docCount = bucketDocCount(i); otherDocCount += spare.docCount;
@Override public void collect(int doc, long bucket) throws IOException { assert bucket == 0; if (values.advanceExact(doc)) { final int valuesCount = values.docValueCount(); long previousRounded = Long.MIN_VALUE; for (int i = 0; i < valuesCount; ++i) { long value = values.nextValue(); long rounded = roundingInfos[roundingIdx].rounding.round(value); assert rounded >= previousRounded; if (rounded == previousRounded) { continue; } long bucketOrd = bucketOrds.add(rounded); if (bucketOrd < 0) { // already seen bucketOrd = -1 - bucketOrd; collectExistingBucket(sub, doc, bucketOrd); } else { collectBucket(sub, doc, bucketOrd); while (roundingIdx < roundingInfos.length - 1 && bucketOrds.size() > (targetBuckets * roundingInfos[roundingIdx].getMaximumInnerInterval())) { increaseRounding(); } } previousRounded = rounded; } } }
@Override public InternalAggregation buildAggregation(long bucket) throws IOException { assert bucket == 0; consumeBucketsAndMaybeBreak((int) bucketOrds.size()); List<InternalHistogram.Bucket> buckets = new ArrayList<>((int) bucketOrds.size()); for (long i = 0; i < bucketOrds.size(); i++) { double roundKey = Double.longBitsToDouble(bucketOrds.get(i)); double key = roundKey * interval + offset; buckets.add(new InternalHistogram.Bucket(key, bucketDocCount(i), keyed, formatter, bucketAggregations(i))); } // the contract of the histogram aggregation is that shards must return buckets ordered by key in ascending order CollectionUtil.introSort(buckets, BucketOrder.key(true).comparator(this)); EmptyBucketInfo emptyBucketInfo = null; if (minDocCount == 0) { emptyBucketInfo = new EmptyBucketInfo(interval, offset, minBound, maxBound, buildEmptySubAggregations()); } return new InternalHistogram(name, buckets, order, minDocCount, emptyBucketInfo, formatter, keyed, pipelineAggregators(), metaData()); }
public LongTermsAggregator(String name, AggregatorFactories factories, ValuesSource.Numeric valuesSource, DocValueFormat format, BucketOrder order, BucketCountThresholds bucketCountThresholds, SearchContext aggregationContext, Aggregator parent, SubAggCollectionMode subAggCollectMode, boolean showTermDocCountError, IncludeExclude.LongFilter longFilter, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException { super(name, factories, aggregationContext, parent, bucketCountThresholds, order, format, subAggCollectMode, pipelineAggregators, metaData); this.valuesSource = valuesSource; this.showTermDocCountError = showTermDocCountError; this.longFilter = longFilter; bucketOrds = new LongHash(1, aggregationContext.bigArrays()); }
final LongHash hash = new LongHash(selectedBuckets.length, BigArrays.NON_RECYCLING_INSTANCE); for (long bucket : selectedBuckets) { hash.add(bucket); doc += docDeltaIterator.next(); final long bucket = buckets.next(); final long rebasedBucket = hash.find(bucket); if (rebasedBucket != -1) { if (needsScores) {
@Override public void collect(int doc, long bucket) throws IOException { assert bucket == 0; if (values.advanceExact(doc)) { final int valuesCount = values.docValueCount(); double previousKey = Double.NEGATIVE_INFINITY; for (int i = 0; i < valuesCount; ++i) { double value = values.nextValue(); double key = Math.floor((value - offset) / interval); assert key >= previousKey; if (key == previousKey) { continue; } long bucketOrd = bucketOrds.add(Double.doubleToLongBits(key)); if (bucketOrd < 0) { // already seen bucketOrd = -1 - bucketOrd; collectExistingBucket(sub, doc, bucketOrd); } else { collectBucket(sub, doc, bucketOrd); } previousKey = key; } } } };
OrdBucket spare = new OrdBucket(-1, 0, null, showTermDocCountError, 0); final boolean needsFullScan = bucketOrds == null || bucketCountThresholds.getMinDocCount() == 0; final long maxId = needsFullScan ? valueCount : bucketOrds.size(); for (long ord = 0; ord < maxId; ord++) { final long globalOrd; final long bucketOrd; if (needsFullScan) { bucketOrd = bucketOrds == null ? ord : bucketOrds.find(ord); globalOrd = ord; } else { assert bucketOrds != null; bucketOrd = ord; globalOrd = bucketOrds.get(ord);
/** * Try to add <code>key</code>. Return its newly allocated id if it wasn't in the hash table yet, or <code>-1-id</code> * if it was already present in the hash table. */ public long add(long key) { if (size >= maxSize) { assert size == maxSize; grow(); } assert size < maxSize; return set(key, size); }
/** * Get the id associated with <code>key</code> or -1 if the key is not contained in the hash. */ public long find(long key) { final long slot = slot(hash(key), mask); for (long index = slot; ; index = nextSlot(index, mask)) { final long id = id(index); if (id == -1 || keys.get(id) == key) { return id; } } }