Search in sources :

Example 1 with ValuesSource

use of org.opensearch.search.aggregations.support.ValuesSource in project OpenSearch by opensearch-project.

the class ParentAggregatorFactory method doCreateInternal.

@Override
protected Aggregator doCreateInternal(SearchContext searchContext, Aggregator children, CardinalityUpperBound cardinality, Map<String, Object> metadata) throws IOException {
    ValuesSource rawValuesSource = config.getValuesSource();
    if (rawValuesSource instanceof WithOrdinals == false) {
        throw new AggregationExecutionException("ValuesSource type " + rawValuesSource.toString() + "is not supported for aggregation " + this.name());
    }
    WithOrdinals valuesSource = (WithOrdinals) rawValuesSource;
    long maxOrd = valuesSource.globalMaxOrd(searchContext.searcher());
    return new ChildrenToParentAggregator(name, factories, searchContext, children, childFilter, parentFilter, valuesSource, maxOrd, cardinality, metadata);
}
Also used : WithOrdinals(org.opensearch.search.aggregations.support.ValuesSource.Bytes.WithOrdinals) ValuesSource(org.opensearch.search.aggregations.support.ValuesSource) AggregationExecutionException(org.opensearch.search.aggregations.AggregationExecutionException)

Example 2 with ValuesSource

use of org.opensearch.search.aggregations.support.ValuesSource in project OpenSearch by opensearch-project.

the class ChildrenAggregatorFactory method doCreateInternal.

@Override
protected Aggregator doCreateInternal(SearchContext searchContext, Aggregator parent, CardinalityUpperBound cardinality, Map<String, Object> metadata) throws IOException {
    ValuesSource rawValuesSource = config.getValuesSource();
    if (rawValuesSource instanceof WithOrdinals == false) {
        throw new AggregationExecutionException("ValuesSource type " + rawValuesSource.toString() + "is not supported for aggregation " + this.name());
    }
    WithOrdinals valuesSource = (WithOrdinals) rawValuesSource;
    long maxOrd = valuesSource.globalMaxOrd(searchContext.searcher());
    return new ParentToChildrenAggregator(name, factories, searchContext, parent, childFilter, parentFilter, valuesSource, maxOrd, cardinality, metadata);
}
Also used : WithOrdinals(org.opensearch.search.aggregations.support.ValuesSource.Bytes.WithOrdinals) ValuesSource(org.opensearch.search.aggregations.support.ValuesSource) AggregationExecutionException(org.opensearch.search.aggregations.AggregationExecutionException)

Example 3 with ValuesSource

use of org.opensearch.search.aggregations.support.ValuesSource in project OpenSearch by opensearch-project.

the class CardinalityAggregator method pickCollector.

private Collector pickCollector(LeafReaderContext ctx) throws IOException {
    if (valuesSource == null) {
        emptyCollectorsUsed++;
        return new EmptyCollector();
    }
    if (valuesSource instanceof ValuesSource.Numeric) {
        ValuesSource.Numeric source = (ValuesSource.Numeric) valuesSource;
        MurmurHash3Values hashValues = source.isFloatingPoint() ? MurmurHash3Values.hash(source.doubleValues(ctx)) : MurmurHash3Values.hash(source.longValues(ctx));
        numericCollectorsUsed++;
        return new DirectCollector(counts, hashValues);
    }
    if (valuesSource instanceof ValuesSource.Bytes.WithOrdinals) {
        ValuesSource.Bytes.WithOrdinals source = (ValuesSource.Bytes.WithOrdinals) valuesSource;
        final SortedSetDocValues ordinalValues = source.ordinalsValues(ctx);
        final long maxOrd = ordinalValues.getValueCount();
        if (maxOrd == 0) {
            emptyCollectorsUsed++;
            return new EmptyCollector();
        }
        final long ordinalsMemoryUsage = OrdinalsCollector.memoryOverhead(maxOrd);
        final long countsMemoryUsage = HyperLogLogPlusPlus.memoryUsage(precision);
        // only use ordinals if they don't increase memory usage by more than 25%
        if (ordinalsMemoryUsage < countsMemoryUsage / 4) {
            ordinalsCollectorsUsed++;
            return new OrdinalsCollector(counts, ordinalValues, context.bigArrays());
        }
        ordinalsCollectorsOverheadTooHigh++;
    }
    stringHashingCollectorsUsed++;
    return new DirectCollector(counts, MurmurHash3Values.hash(valuesSource.bytesValues(ctx)));
}
Also used : SortedSetDocValues(org.apache.lucene.index.SortedSetDocValues) ValuesSource(org.opensearch.search.aggregations.support.ValuesSource)

Example 4 with ValuesSource

use of org.opensearch.search.aggregations.support.ValuesSource in project OpenSearch by opensearch-project.

the class ValueCountAggregator method getLeafCollector.

@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    if (valuesSource instanceof ValuesSource.Numeric) {
        final SortedNumericDocValues values = ((ValuesSource.Numeric) valuesSource).longValues(ctx);
        return new LeafBucketCollectorBase(sub, values) {

            @Override
            public void collect(int doc, long bucket) throws IOException {
                counts = bigArrays.grow(counts, bucket + 1);
                if (values.advanceExact(doc)) {
                    counts.increment(bucket, values.docValueCount());
                }
            }
        };
    }
    if (valuesSource instanceof ValuesSource.Bytes.GeoPoint) {
        MultiGeoPointValues values = ((ValuesSource.GeoPoint) valuesSource).geoPointValues(ctx);
        return new LeafBucketCollectorBase(sub, null) {

            @Override
            public void collect(int doc, long bucket) throws IOException {
                counts = bigArrays.grow(counts, bucket + 1);
                if (values.advanceExact(doc)) {
                    counts.increment(bucket, values.docValueCount());
                }
            }
        };
    }
    // The following is default collector. Including the keyword FieldType
    final SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            counts = bigArrays.grow(counts, bucket + 1);
            if (values.advanceExact(doc)) {
                counts.increment(bucket, values.docValueCount());
            }
        }
    };
}
Also used : BigArrays(org.opensearch.common.util.BigArrays) SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) LeafBucketCollectorBase(org.opensearch.search.aggregations.LeafBucketCollectorBase) ValuesSource(org.opensearch.search.aggregations.support.ValuesSource) MultiGeoPointValues(org.opensearch.index.fielddata.MultiGeoPointValues) SortedBinaryDocValues(org.opensearch.index.fielddata.SortedBinaryDocValues)

Aggregations

ValuesSource (org.opensearch.search.aggregations.support.ValuesSource)4 AggregationExecutionException (org.opensearch.search.aggregations.AggregationExecutionException)2 WithOrdinals (org.opensearch.search.aggregations.support.ValuesSource.Bytes.WithOrdinals)2 SortedNumericDocValues (org.apache.lucene.index.SortedNumericDocValues)1 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)1 BigArrays (org.opensearch.common.util.BigArrays)1 MultiGeoPointValues (org.opensearch.index.fielddata.MultiGeoPointValues)1 SortedBinaryDocValues (org.opensearch.index.fielddata.SortedBinaryDocValues)1 LeafBucketCollectorBase (org.opensearch.search.aggregations.LeafBucketCollectorBase)1