Search in sources :

Example 6 with BigArrays

use of org.elasticsearch.common.util.BigArrays in project elasticsearch by elastic.

the class IndexModuleTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    indicesQueryCache = new IndicesQueryCache(settings);
    indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
    index = indexSettings.getIndex();
    environment = new Environment(settings);
    threadPool = new TestThreadPool("test");
    circuitBreakerService = new NoneCircuitBreakerService();
    bigArrays = new BigArrays(settings, circuitBreakerService);
    ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(emptyList());
    ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
    ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
    scriptService = new ScriptService(settings, environment, new ResourceWatcherService(settings, threadPool), scriptEngineRegistry, scriptContextRegistry, scriptSettings);
    clusterService = ClusterServiceUtils.createClusterService(threadPool);
    nodeEnvironment = new NodeEnvironment(settings, environment);
    mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry();
}
Also used : IndicesQueryCache(org.elasticsearch.indices.IndicesQueryCache) ScriptService(org.elasticsearch.script.ScriptService) BigArrays(org.elasticsearch.common.util.BigArrays) IndicesModule(org.elasticsearch.indices.IndicesModule) ScriptSettings(org.elasticsearch.script.ScriptSettings) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) ScriptEngineRegistry(org.elasticsearch.script.ScriptEngineRegistry) Environment(org.elasticsearch.env.Environment) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ResourceWatcherService(org.elasticsearch.watcher.ResourceWatcherService) ScriptContextRegistry(org.elasticsearch.script.ScriptContextRegistry) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 7 with BigArrays

use of org.elasticsearch.common.util.BigArrays in project elasticsearch by elastic.

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();
    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);
            values.setDocument(doc);
            counts.increment(bucket, values.count());
        }
    };
}
Also used : BigArrays(org.elasticsearch.common.util.BigArrays) LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues)

Example 8 with BigArrays

use of org.elasticsearch.common.util.BigArrays in project elasticsearch by elastic.

the class ExtendedStatsAggregator 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();
    final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= counts.size()) {
                final long from = counts.size();
                final long overSize = BigArrays.overSize(bucket + 1);
                counts = bigArrays.resize(counts, overSize);
                sums = bigArrays.resize(sums, overSize);
                mins = bigArrays.resize(mins, overSize);
                maxes = bigArrays.resize(maxes, overSize);
                sumOfSqrs = bigArrays.resize(sumOfSqrs, overSize);
                mins.fill(from, overSize, Double.POSITIVE_INFINITY);
                maxes.fill(from, overSize, Double.NEGATIVE_INFINITY);
            }
            values.setDocument(doc);
            final int valuesCount = values.count();
            counts.increment(bucket, valuesCount);
            double sum = 0;
            double sumOfSqr = 0;
            double min = mins.get(bucket);
            double max = maxes.get(bucket);
            for (int i = 0; i < valuesCount; i++) {
                double value = values.valueAt(i);
                sum += value;
                sumOfSqr += value * value;
                min = Math.min(min, value);
                max = Math.max(max, value);
            }
            sums.increment(bucket, sum);
            sumOfSqrs.increment(bucket, sumOfSqr);
            mins.set(bucket, min);
            maxes.set(bucket, max);
        }
    };
}
Also used : BigArrays(org.elasticsearch.common.util.BigArrays) LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues)

Example 9 with BigArrays

use of org.elasticsearch.common.util.BigArrays in project elasticsearch by elastic.

the class SumAggregator 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();
    final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            sums = bigArrays.grow(sums, bucket + 1);
            values.setDocument(doc);
            final int valuesCount = values.count();
            double sum = 0;
            for (int i = 0; i < valuesCount; i++) {
                sum += values.valueAt(i);
            }
            sums.increment(bucket, sum);
        }
    };
}
Also used : BigArrays(org.elasticsearch.common.util.BigArrays) LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues)

Example 10 with BigArrays

use of org.elasticsearch.common.util.BigArrays in project elasticsearch by elastic.

the class GeoBoundsAggregator method getLeafCollector.

@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final MultiGeoPointValues values = valuesSource.geoPointValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= tops.size()) {
                long from = tops.size();
                tops = bigArrays.grow(tops, bucket + 1);
                tops.fill(from, tops.size(), Double.NEGATIVE_INFINITY);
                bottoms = bigArrays.resize(bottoms, tops.size());
                bottoms.fill(from, bottoms.size(), Double.POSITIVE_INFINITY);
                posLefts = bigArrays.resize(posLefts, tops.size());
                posLefts.fill(from, posLefts.size(), Double.POSITIVE_INFINITY);
                posRights = bigArrays.resize(posRights, tops.size());
                posRights.fill(from, posRights.size(), Double.NEGATIVE_INFINITY);
                negLefts = bigArrays.resize(negLefts, tops.size());
                negLefts.fill(from, negLefts.size(), Double.POSITIVE_INFINITY);
                negRights = bigArrays.resize(negRights, tops.size());
                negRights.fill(from, negRights.size(), Double.NEGATIVE_INFINITY);
            }
            values.setDocument(doc);
            final int valuesCount = values.count();
            for (int i = 0; i < valuesCount; ++i) {
                GeoPoint value = values.valueAt(i);
                double top = tops.get(bucket);
                if (value.lat() > top) {
                    top = value.lat();
                }
                double bottom = bottoms.get(bucket);
                if (value.lat() < bottom) {
                    bottom = value.lat();
                }
                double posLeft = posLefts.get(bucket);
                if (value.lon() >= 0 && value.lon() < posLeft) {
                    posLeft = value.lon();
                }
                double posRight = posRights.get(bucket);
                if (value.lon() >= 0 && value.lon() > posRight) {
                    posRight = value.lon();
                }
                double negLeft = negLefts.get(bucket);
                if (value.lon() < 0 && value.lon() < negLeft) {
                    negLeft = value.lon();
                }
                double negRight = negRights.get(bucket);
                if (value.lon() < 0 && value.lon() > negRight) {
                    negRight = value.lon();
                }
                tops.set(bucket, top);
                bottoms.set(bucket, bottom);
                posLefts.set(bucket, posLeft);
                posRights.set(bucket, posRight);
                negLefts.set(bucket, negLeft);
                negRights.set(bucket, negRight);
            }
        }
    };
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) BigArrays(org.elasticsearch.common.util.BigArrays) LeafBucketCollectorBase(org.elasticsearch.search.aggregations.LeafBucketCollectorBase) MultiGeoPointValues(org.elasticsearch.index.fielddata.MultiGeoPointValues) GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Aggregations

BigArrays (org.elasticsearch.common.util.BigArrays)26 LeafBucketCollectorBase (org.elasticsearch.search.aggregations.LeafBucketCollectorBase)12 ThreadPool (org.elasticsearch.threadpool.ThreadPool)10 SortedNumericDoubleValues (org.elasticsearch.index.fielddata.SortedNumericDoubleValues)8 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)7 Settings (org.elasticsearch.common.settings.Settings)7 CircuitBreakerService (org.elasticsearch.indices.breaker.CircuitBreakerService)6 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)6 NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)5 NetworkPlugin (org.elasticsearch.plugins.NetworkPlugin)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 HttpServerTransport (org.elasticsearch.http.HttpServerTransport)4 Transport (org.elasticsearch.transport.Transport)4 List (java.util.List)3 NetworkService (org.elasticsearch.common.network.NetworkService)3 MockBigArrays (org.elasticsearch.common.util.MockBigArrays)3 NumericDoubleValues (org.elasticsearch.index.fielddata.NumericDoubleValues)3 Closeable (java.io.Closeable)2 IOException (java.io.IOException)2