From 59027cdbdb425a59c7899c5c92091eda68118cea Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 10 Oct 2025 15:44:52 +0100 Subject: [PATCH 1/3] FieldData to use SortedNumericLongValues in place of SortedNumericDocValues We don't need doc-by-doc iteration in FieldData, so this simplifies several implementations and also doesn't make unimplemented APIs available. --- .../script/ScriptScoreBenchmark.java | 6 +- .../AutoDateHistogramAggregator.java | 21 ++-- .../timeseries/TimeSeriesAggregator.java | 4 +- .../mapper/extras/ScaledFloatFieldMapper.java | 9 +- .../field/murmur3/Murmur3DocValueField.java | 4 +- .../AbstractSortingNumericDocValues.java | 53 --------- .../fielddata/BooleanScriptDocValues.java | 2 +- .../fielddata/BooleanScriptFieldData.java | 15 ++- .../index/fielddata/DateScriptFieldData.java | 15 ++- .../index/fielddata/FieldData.java | 69 +++++------ .../fielddata/GeoPointScriptDocValues.java | 2 +- .../fielddata/GeoPointScriptFieldData.java | 3 +- .../index/fielddata/GeoPointValues.java | 4 +- .../fielddata/IndexNumericFieldData.java | 10 +- .../index/fielddata/LeafNumericFieldData.java | 4 +- .../index/fielddata/LeafPointFieldData.java | 2 +- .../index/fielddata/LongScriptDocValues.java | 2 +- .../index/fielddata/LongScriptFieldData.java | 15 ++- .../index/fielddata/MultiGeoPointValues.java | 8 +- .../index/fielddata/MultiPointValues.java | 5 +- .../index/fielddata/PointValues.java | 6 +- .../SortableLongBitsNumericDocValues.java | 10 +- ...ortableLongBitsSortedNumericDocValues.java | 5 +- ...SortableLongBitsToNumericDoubleValues.java | 7 +- ...leLongBitsToSortedNumericDoubleValues.java | 9 +- .../fielddata/SortedNumericLongValues.java | 110 ++++++++++++++++++ ...ues.java => SortingNumericLongValues.java} | 9 +- ...lueFetcherSortedBooleanIndexFieldData.java | 37 ++---- ...lueFetcherSortedNumericIndexFieldData.java | 35 ++---- .../IntValuesComparatorSource.java | 5 +- .../LongValuesComparatorSource.java | 53 +++++++-- .../FormattedSortedNumericDocValues.java | 6 +- .../plain/LatLonPointDVLeafFieldData.java | 6 +- .../fielddata/plain/LeafDoubleFieldData.java | 4 +- .../plain/LeafGeoPointFieldData.java | 2 +- .../plain/SortedDoublesIndexFieldData.java | 3 +- .../plain/SortedNumericIndexFieldData.java | 29 ++--- .../index/mapper/DateFieldMapper.java | 8 +- .../index/query/TermsSetQueryBuilder.java | 4 +- ...SortedNumericDocValuesLongFieldScript.java | 6 +- .../field/AbstractLongDocValuesField.java | 6 +- .../script/field/BooleanDocValuesField.java | 6 +- .../script/field/ByteDocValuesField.java | 6 +- .../field/DateMillisDocValuesField.java | 6 +- .../script/field/DateNanosDocValuesField.java | 6 +- .../script/field/IntegerDocValuesField.java | 6 +- .../script/field/LongDocValuesField.java | 4 +- .../script/field/SeqNoDocValuesField.java | 4 +- .../script/field/ShortDocValuesField.java | 6 +- .../script/field/VersionDocValuesField.java | 4 +- .../elasticsearch/search/MultiValueMode.java | 50 ++++---- .../bucket/composite/GeoTileValuesSource.java | 4 +- .../composite/HistogramValuesSource.java | 4 +- .../bucket/composite/LongValuesSource.java | 17 ++- .../composite/RoundingValuesSource.java | 61 ++-------- .../bucket/geogrid/CellIdSource.java | 33 +++--- .../bucket/geogrid/GeoGridAggregator.java | 13 +-- .../bucket/geogrid/GeoHashCellIdSource.java | 12 +- .../bucket/geogrid/GeoTileCellIdSource.java | 12 +- .../histogram/DateHistogramAggregator.java | 13 +-- .../GeoDistanceRangeAggregatorFactory.java | 4 +- .../DiversifiedNumericSamplerAggregator.java | 7 +- .../bucket/terms/LongRareTermsAggregator.java | 15 ++- .../bucket/terms/NumericTermsAggregator.java | 23 ++-- .../metrics/CardinalityAggregator.java | 21 ++-- .../metrics/ValueCountAggregator.java | 4 +- .../aggregations/support/MissingValues.java | 13 +-- .../aggregations/support/ValuesSource.java | 33 +++--- .../support/values/ScriptLongValues.java | 4 +- .../index/fielddata/FieldDataTests.java | 42 +++---- .../IntegralDocValuesFieldTests.java | 4 +- .../ScriptDocValuesGeoPointsTests.java | 2 +- .../fielddata/ScriptDocValuesLongsTests.java | 2 +- ...ava => SortingNumericLongValuesTests.java} | 24 +--- .../mapper/BooleanScriptFieldTypeTests.java | 4 +- .../index/mapper/DateFieldTypeTests.java | 10 +- .../mapper/DateScriptFieldTypeTests.java | 4 +- .../mapper/LongScriptFieldTypeTests.java | 4 +- .../functionscore/FunctionScoreTests.java | 4 +- .../search/MultiValueModeTests.java | 35 ++---- .../CompositeValuesCollectorQueueTests.java | 7 +- .../support/MissingValuesTests.java | 7 +- .../support/ValuesSourceConfigTests.java | 14 +-- .../multiterms/MultiTermsAggregator.java | 13 +-- .../topmetrics/TopMetricsAggregator.java | 4 +- .../TopMetricsAggregatorMetricsTests.java | 12 +- .../compute/lucene/LuceneMaxFactory.java | 7 +- .../compute/lucene/LuceneMinFactory.java | 7 +- .../compute/lucene/LuceneMinMaxOperator.java | 6 +- .../querydsl/query/SingleValueMatchQuery.java | 8 +- ...tcherSortedUnsignedLongIndexFieldData.java | 38 ++---- .../UnsignedLongDocValuesField.java | 4 +- .../UnsignedLongIndexFieldData.java | 6 +- .../UnsignedLongLeafFieldData.java | 15 ++- .../mr/ItemSetMapReduceValueSource.java | 12 +- .../plain/CartesianPointDVLeafFieldData.java | 6 +- .../plain/LeafCartesianPointFieldData.java | 2 +- .../bucket/geogrid/GeoHexCellIdSource.java | 12 +- .../bucket/geogrid/GeoShapeCellIdSource.java | 4 +- .../bucket/geogrid/GeoShapeCellValues.java | 4 +- .../support/CartesianPointValuesSource.java | 16 +-- .../CartesianPointValuesSourceType.java | 6 +- 102 files changed, 628 insertions(+), 721 deletions(-) delete mode 100644 server/src/main/java/org/elasticsearch/index/fielddata/AbstractSortingNumericDocValues.java create mode 100644 server/src/main/java/org/elasticsearch/index/fielddata/SortedNumericLongValues.java rename server/src/main/java/org/elasticsearch/index/fielddata/{SortingNumericDocValues.java => SortingNumericLongValues.java} (90%) rename server/src/test/java/org/elasticsearch/index/fielddata/{SortingNumericDocValuesTests.java => SortingNumericLongValuesTests.java} (77%) diff --git a/benchmarks/src/main/java/org/elasticsearch/benchmark/script/ScriptScoreBenchmark.java b/benchmarks/src/main/java/org/elasticsearch/benchmark/script/ScriptScoreBenchmark.java index f4edff01c901d..bb325e3683ae3 100644 --- a/benchmarks/src/main/java/org/elasticsearch/benchmark/script/ScriptScoreBenchmark.java +++ b/benchmarks/src/main/java/org/elasticsearch/benchmark/script/ScriptScoreBenchmark.java @@ -15,7 +15,6 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig.OpenMode; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; @@ -29,6 +28,7 @@ import org.elasticsearch.index.fielddata.FieldDataContext; import org.elasticsearch.index.fielddata.IndexFieldDataCache; import org.elasticsearch.index.fielddata.IndexNumericFieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.IndexType; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MappingLookup; @@ -179,14 +179,14 @@ private ScoreScript.Factory bareMetalScript() { return new ScoreScript.LeafFactory() { @Override public ScoreScript newInstance(DocReader docReader) throws IOException { - SortedNumericDocValues values = ifd.load(((DocValuesDocReader) docReader).getLeafReaderContext()).getLongValues(); + SortedNumericLongValues values = ifd.load(((DocValuesDocReader) docReader).getLeafReaderContext()).getLongValues(); return new ScoreScript(params, null, docReader) { private int docId; @Override public double execute(ExplanationHolder explanation) { try { - values.advance(docId); + values.advanceExact(docId); if (values.docValueCount() != 1) { throw new IllegalArgumentException("script only works when there is exactly one value"); } diff --git a/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregator.java b/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregator.java index abd482d8298ef..e84cbc674a80f 100644 --- a/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregator.java +++ b/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregator.java @@ -8,9 +8,7 @@ */ package org.elasticsearch.aggregations.bucket.histogram; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.aggregations.bucket.histogram.AutoDateHistogramAggregationBuilder.RoundingInfo; @@ -19,6 +17,7 @@ import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.LongArray; import org.elasticsearch.core.Releasables; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregationExecutionContext; import org.elasticsearch.search.aggregations.Aggregator; @@ -125,17 +124,17 @@ public final DeferringBucketCollector buildDeferringCollector() { return deferringCollector; } - protected abstract LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) throws IOException; + protected abstract LeafBucketCollector getLeafCollector(SortedNumericLongValues values, LeafBucketCollector sub) throws IOException; - protected abstract LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) throws IOException; + protected abstract LeafBucketCollector getLeafCollector(LongValues values, LeafBucketCollector sub) throws IOException; @Override public final LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx, LeafBucketCollector sub) throws IOException { if (valuesSource == null) { return LeafBucketCollector.NO_OP_COLLECTOR; } - final SortedNumericDocValues values = valuesSource.longValues(aggCtx.getLeafReaderContext()); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = valuesSource.longValues(aggCtx.getLeafReaderContext()); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); return singleton != null ? getLeafCollector(singleton, sub) : getLeafCollector(values, sub); } @@ -239,7 +238,7 @@ private static class FromSingle extends AutoDateHistogramAggregator { } @Override - protected LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) { + protected LeafBucketCollector getLeafCollector(SortedNumericLongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -265,7 +264,7 @@ public void collect(int doc, long owningBucketOrd) throws IOException { } @Override - protected LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) { + protected LeafBucketCollector getLeafCollector(LongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -461,7 +460,7 @@ private static class FromMany extends AutoDateHistogramAggregator { } @Override - protected LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) { + protected LeafBucketCollector getLeafCollector(SortedNumericLongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -487,7 +486,7 @@ public void collect(int doc, long owningBucketOrd) throws IOException { } @Override - protected LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) { + protected LeafBucketCollector getLeafCollector(LongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { diff --git a/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/timeseries/TimeSeriesAggregator.java b/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/timeseries/TimeSeriesAggregator.java index 63472bca1d9ac..b71f3377f3e34 100644 --- a/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/timeseries/TimeSeriesAggregator.java +++ b/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/timeseries/TimeSeriesAggregator.java @@ -9,12 +9,12 @@ package org.elasticsearch.aggregations.bucket.timeseries; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.ObjectArray; import org.elasticsearch.core.Releasables; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.RoutingPathFields; import org.elasticsearch.index.mapper.TimeSeriesIdFieldMapper; import org.elasticsearch.search.aggregations.AggregationExecutionContext; @@ -121,7 +121,7 @@ protected LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCt for (var entry : dimensionValueSources.entrySet()) { String fieldName = entry.getKey(); if (entry.getValue() instanceof ValuesSource.Numeric numericVS) { - SortedNumericDocValues docValues = numericVS.longValues(aggCtx.getLeafReaderContext()); + SortedNumericLongValues docValues = numericVS.longValues(aggCtx.getLeafReaderContext()); dimensionConsumers.put(entry.getKey(), (docId, tsidBuilder) -> { if (docValues.advanceExact(docId)) { assert docValues.docValueCount() == 1 : "Dimension field cannot be a multi-valued field"; diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldMapper.java index d2bae840b905d..d0bbf3059395d 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldMapper.java @@ -9,10 +9,8 @@ package org.elasticsearch.index.mapper.extras; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.Query; import org.elasticsearch.common.Explicit; import org.elasticsearch.common.settings.Setting; @@ -28,6 +26,7 @@ import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.SourceValueFetcherSortedDoubleIndexFieldData; import org.elasticsearch.index.fielddata.plain.LeafDoubleFieldData; import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData; @@ -831,8 +830,8 @@ public void close() { @Override public SortedNumericDoubleValues getDoubleValues() { - final SortedNumericDocValues values = scaledFieldData.getLongValues(); - final NumericDocValues singleValues = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = scaledFieldData.getLongValues(); + final LongValues singleValues = SortedNumericLongValues.unwrapSingleton(values); if (singleValues != null) { return FieldData.singleton(new NumericDoubleValues() { @Override diff --git a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/script/field/murmur3/Murmur3DocValueField.java b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/script/field/murmur3/Murmur3DocValueField.java index 324fe910d36bb..2d21452846880 100644 --- a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/script/field/murmur3/Murmur3DocValueField.java +++ b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/script/field/murmur3/Murmur3DocValueField.java @@ -9,12 +9,12 @@ package org.elasticsearch.script.field.murmur3; -import org.apache.lucene.index.SortedNumericDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.field.AbstractLongDocValuesField; public class Murmur3DocValueField extends AbstractLongDocValuesField { - public Murmur3DocValueField(SortedNumericDocValues input, String name) { + public Murmur3DocValueField(SortedNumericLongValues input, String name) { super(input, name); } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/AbstractSortingNumericDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/AbstractSortingNumericDocValues.java deleted file mode 100644 index 076b2fecf4bef..0000000000000 --- a/server/src/main/java/org/elasticsearch/index/fielddata/AbstractSortingNumericDocValues.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.index.fielddata; - -import org.apache.lucene.search.DocIdSetIterator; - -import java.io.IOException; -import java.util.function.LongConsumer; - -/** - * Base implementation that throws an {@link IOException} for the - * {@link DocIdSetIterator} APIs. This impl is safe to use for sorting and - * aggregations, which only use {@link #advanceExact(int)} and - * {@link #docValueCount()} and {@link #nextValue()}. - */ -public abstract class AbstractSortingNumericDocValues extends SortingNumericDocValues { - - public AbstractSortingNumericDocValues() { - super(); - } - - public AbstractSortingNumericDocValues(LongConsumer circuitBreakerConsumer) { - super(circuitBreakerConsumer); - } - - @Override - public int docID() { - throw new UnsupportedOperationException(); - } - - @Override - public int nextDoc() { - throw new UnsupportedOperationException(); - } - - @Override - public int advance(int target) { - throw new UnsupportedOperationException(); - } - - @Override - public long cost() { - throw new UnsupportedOperationException(); - } - -} diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptDocValues.java index 027bdfffe3d1e..2fa15ac786b7f 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptDocValues.java @@ -11,7 +11,7 @@ import org.elasticsearch.script.BooleanFieldScript; -public final class BooleanScriptDocValues extends AbstractSortedNumericDocValues { +public final class BooleanScriptDocValues extends SortedNumericLongValues { private final BooleanFieldScript script; private int cursor; diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptFieldData.java index 0f6db38e9e562..cdf04bd79706e 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptFieldData.java @@ -10,7 +10,6 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.index.fielddata.plain.LeafLongFieldData; import org.elasticsearch.indices.breaker.CircuitBreakerService; @@ -25,12 +24,12 @@ public final class BooleanScriptFieldData extends IndexNumericFieldData { public static class Builder implements IndexFieldData.Builder { private final String name; private final BooleanFieldScript.LeafFactory leafFactory; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; public Builder( String name, BooleanFieldScript.LeafFactory leafFactory, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { this.name = name; this.leafFactory = leafFactory; @@ -45,12 +44,12 @@ public BooleanScriptFieldData build(IndexFieldDataCache cache, CircuitBreakerSer private final String fieldName; private final BooleanFieldScript.LeafFactory leafFactory; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; private BooleanScriptFieldData( String fieldName, BooleanFieldScript.LeafFactory leafFactory, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { this.fieldName = fieldName; this.leafFactory = leafFactory; @@ -98,11 +97,11 @@ protected boolean isIndexed() { public static class BooleanScriptLeafFieldData extends LeafLongFieldData { private final BooleanScriptDocValues booleanScriptDocValues; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; BooleanScriptLeafFieldData( BooleanScriptDocValues booleanScriptDocValues, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(0); this.booleanScriptDocValues = booleanScriptDocValues; @@ -110,7 +109,7 @@ public static class BooleanScriptLeafFieldData extends LeafLongFieldData { } @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { return booleanScriptDocValues; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/DateScriptFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/DateScriptFieldData.java index 45a550be5252a..b3fe59ae71c39 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/DateScriptFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/DateScriptFieldData.java @@ -10,7 +10,6 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.index.fielddata.plain.LeafLongFieldData; import org.elasticsearch.indices.breaker.CircuitBreakerService; @@ -25,12 +24,12 @@ public final class DateScriptFieldData extends IndexNumericFieldData { public static class Builder implements IndexFieldData.Builder { private final String name; private final DateFieldScript.LeafFactory leafFactory; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; public Builder( String name, DateFieldScript.LeafFactory leafFactory, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { this.name = name; this.leafFactory = leafFactory; @@ -45,12 +44,12 @@ public DateScriptFieldData build(IndexFieldDataCache cache, CircuitBreakerServic private final String fieldName; private final DateFieldScript.LeafFactory leafFactory; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; private DateScriptFieldData( String fieldName, DateFieldScript.LeafFactory leafFactory, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { this.fieldName = fieldName; this.leafFactory = leafFactory; @@ -98,11 +97,11 @@ protected boolean isIndexed() { public static class DateScriptLeafFieldData extends LeafLongFieldData { private final LongScriptDocValues longScriptDocValues; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; DateScriptLeafFieldData( LongScriptDocValues longScriptDocValues, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(0); this.longScriptDocValues = longScriptDocValues; @@ -110,7 +109,7 @@ public static class DateScriptLeafFieldData extends LeafLongFieldData { } @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { return longScriptDocValues; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/FieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/FieldData.java index 6c8d52ac18280..cc1c860635ece 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/FieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/FieldData.java @@ -15,6 +15,7 @@ import org.apache.lucene.index.SortedDocValues; import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; import org.elasticsearch.common.geo.SpatialPoint; @@ -115,7 +116,7 @@ public boolean advanceExact(int doc) throws IOException { * Returns a {@link DocValueBits} representing all documents from docValues that have * a value. */ - public static DocValueBits docsWithValue(final SortedNumericDocValues docValues) { + public static DocValueBits docsWithValue(final SortedNumericLongValues docValues) { return new DocValueBits() { @Override public boolean advanceExact(int doc) throws IOException { @@ -130,16 +131,16 @@ public boolean advanceExact(int doc) throws IOException { * to sortable long bits using * {@link org.apache.lucene.util.NumericUtils#doubleToSortableLong(double)}. */ - public static SortedNumericDocValues toSortableLongBits(SortedNumericDoubleValues values) { + public static SortedNumericLongValues toSortableLongBits(SortedNumericDoubleValues values) { final NumericDoubleValues singleton = unwrapSingleton(values); if (singleton != null) { - final NumericDocValues longBits; + final LongValues longBits; if (singleton instanceof SortableLongBitsToNumericDoubleValues) { longBits = ((SortableLongBitsToNumericDoubleValues) singleton).getLongValues(); } else { longBits = new SortableLongBitsNumericDocValues(singleton); } - return DocValues.singleton(longBits); + return SortedNumericLongValues.singleton(longBits); } else { if (values instanceof SortableLongBitsToSortedNumericDoubleValues) { return ((SortableLongBitsToSortedNumericDoubleValues) values).getLongValues(); @@ -150,12 +151,12 @@ public static SortedNumericDocValues toSortableLongBits(SortedNumericDoubleValue } /** - * Given a {@link SortedNumericDocValues}, return a {@link SortedNumericDoubleValues} + * Given a {@link SortedNumericLongValues}, return a {@link SortedNumericDoubleValues} * instance that will translate long values to doubles using * {@link org.apache.lucene.util.NumericUtils#sortableLongToDouble(long)}. */ - public static SortedNumericDoubleValues sortableLongBitsToDoubles(SortedNumericDocValues values) { - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + public static SortedNumericDoubleValues sortableLongBitsToDoubles(SortedNumericLongValues values) { + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); if (singleton != null) { final NumericDoubleValues doubles; if (singleton instanceof SortableLongBitsNumericDocValues) { @@ -176,8 +177,8 @@ public static SortedNumericDoubleValues sortableLongBitsToDoubles(SortedNumericD /** * Wrap the provided {@link SortedNumericDocValues} instance to cast all values to doubles. */ - public static SortedNumericDoubleValues castToDouble(final SortedNumericDocValues values) { - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + public static SortedNumericDoubleValues castToDouble(final SortedNumericLongValues values) { + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); if (singleton != null) { return singleton(new DoubleCastedValues(singleton)); } else { @@ -188,10 +189,10 @@ public static SortedNumericDoubleValues castToDouble(final SortedNumericDocValue /** * Wrap the provided {@link SortedNumericDoubleValues} instance to cast all values to longs. */ - public static SortedNumericDocValues castToLong(final SortedNumericDoubleValues values) { + public static SortedNumericLongValues castToLong(final SortedNumericDoubleValues values) { final NumericDoubleValues singleton = unwrapSingleton(values); if (singleton != null) { - return DocValues.singleton(new LongCastedValues(singleton)); + return SortedNumericLongValues.singleton(new LongCastedValues(singleton)); } else { return new SortedLongCastedValues(values); } @@ -248,9 +249,9 @@ public static BinaryDocValues unwrapSingleton(SortedBinaryDocValues values) { * typically used for scripts or for the `map` execution mode of terms aggs. * NOTE: this is very slow! */ - public static SortedBinaryDocValues toString(final SortedNumericDocValues values) { + public static SortedBinaryDocValues toString(final SortedNumericLongValues values) { { - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); if (singleton != null) { return FieldData.singleton(toString(singleton)); } @@ -275,7 +276,7 @@ public void get(List list) throws IOException { * typically used for scripts or for the `map` execution mode of terms aggs. * NOTE: this is very slow! */ - public static BinaryDocValues toString(final NumericDocValues values) { + public static BinaryDocValues toString(final LongValues values) { return toString(new ToStringValue() { @Override public boolean advanceExact(int doc) throws IOException { @@ -506,9 +507,9 @@ private interface ToStringValue { private static class DoubleCastedValues extends NumericDoubleValues { - private final NumericDocValues values; + private final LongValues values; - DoubleCastedValues(NumericDocValues values) { + DoubleCastedValues(LongValues values) { this.values = values; } @@ -526,9 +527,9 @@ public boolean advanceExact(int doc) throws IOException { private static class SortedDoubleCastedValues extends SortedNumericDoubleValues { - private final SortedNumericDocValues values; + private final SortedNumericLongValues values; - SortedDoubleCastedValues(SortedNumericDocValues in) { + SortedDoubleCastedValues(SortedNumericLongValues in) { this.values = in; } @@ -549,10 +550,9 @@ public int docValueCount() { } - private static class LongCastedValues extends AbstractNumericDocValues { + private static class LongCastedValues extends LongValues { private final NumericDoubleValues values; - private int docID = -1; LongCastedValues(NumericDoubleValues values) { this.values = values; @@ -560,7 +560,6 @@ private static class LongCastedValues extends AbstractNumericDocValues { @Override public boolean advanceExact(int target) throws IOException { - docID = target; return values.advanceExact(target); } @@ -568,14 +567,9 @@ public boolean advanceExact(int target) throws IOException { public long longValue() throws IOException { return (long) values.doubleValue(); } - - @Override - public int docID() { - return docID; - } } - private static class SortedLongCastedValues extends AbstractSortedNumericDocValues { + private static class SortedLongCastedValues extends SortedNumericLongValues { private final SortedNumericDoubleValues values; @@ -600,21 +594,28 @@ public long nextValue() throws IOException { } + public static LongValues EMPTY = new LongValues() { + @Override + public long longValue() throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public boolean advanceExact(int doc) throws IOException { + return false; + } + }; + /** * Return a {@link NumericDocValues} instance that has a value for every * document, returns the same value as {@code values} if there is a value * for the current document and {@code missing} otherwise. */ - public static NumericDocValues replaceMissing(NumericDocValues values, long missing) { - return new AbstractNumericDocValues() { + public static LongValues replaceMissing(LongValues values, long missing) { + return new LongValues() { private long value; - @Override - public int docID() { - return values.docID(); - } - @Override public boolean advanceExact(int target) throws IOException { if (values.advanceExact(target)) { diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptDocValues.java index c9aed46377c3f..9d15ae19def5a 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptDocValues.java @@ -13,7 +13,7 @@ import org.apache.lucene.util.IntroSorter; import org.elasticsearch.script.GeoPointFieldScript; -public final class GeoPointScriptDocValues extends AbstractSortedNumericDocValues { +public final class GeoPointScriptDocValues extends SortedNumericLongValues { private final GeoPointFieldScript script; private int cursor; diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptFieldData.java index e6bd6c3e59656..3b2d47586da08 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptFieldData.java @@ -10,7 +10,6 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.SortField; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.index.fielddata.plain.LeafGeoPointFieldData; @@ -94,7 +93,7 @@ public LeafPointFieldData load(LeafReaderContext context) { GeoPointFieldScript script = leafFactory.newInstance(context); return new LeafGeoPointFieldData(toScriptFieldFactory) { @Override - public SortedNumericDocValues getSortedNumericDocValues() { + public SortedNumericLongValues getSortedNumericLongValues() { return new GeoPointScriptDocValues(script); } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointValues.java index 502d9a807b5f6..7fe0f3728cc36 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointValues.java @@ -9,7 +9,7 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.NumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.geo.GeoPoint; import java.io.IOException; @@ -21,7 +21,7 @@ public final class GeoPointValues extends PointValues { private final GeoPoint point = new GeoPoint(); - GeoPointValues(NumericDocValues values) { + GeoPointValues(LongValues values) { super(values); } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/IndexNumericFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/IndexNumericFieldData.java index 4e7cf8ead2d7b..506cb1fc5086b 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/IndexNumericFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/IndexNumericFieldData.java @@ -9,7 +9,6 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortedNumericSelector; import org.apache.lucene.search.SortedNumericSortField; @@ -265,8 +264,8 @@ protected XFieldComparatorSource dateNanosComparatorSource(@Nullable Object miss /** * Convert the values in dvs using the provided converter. */ - protected static SortedNumericDocValues convertNumeric(SortedNumericDocValues values, LongUnaryOperator converter) { - return new AbstractSortedNumericDocValues() { + protected static SortedNumericLongValues convertNumeric(SortedNumericLongValues values, LongUnaryOperator converter) { + return new SortedNumericLongValues() { @Override public boolean advanceExact(int target) throws IOException { @@ -282,11 +281,6 @@ public long nextValue() throws IOException { public int docValueCount() { return values.docValueCount(); } - - @Override - public int nextDoc() throws IOException { - return values.nextDoc(); - } }; } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/LeafNumericFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/LeafNumericFieldData.java index 902f4c87d14fb..adf53d8a0cc18 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/LeafNumericFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/LeafNumericFieldData.java @@ -9,8 +9,6 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.SortedNumericDocValues; - /** * Specialization of {@link LeafFieldData} for numeric data. */ @@ -21,7 +19,7 @@ public interface LeafNumericFieldData extends LeafFieldData { * stores floating-point numbers then these values will return the same * values but casted to longs. */ - SortedNumericDocValues getLongValues(); + SortedNumericLongValues getLongValues(); /** * Return a floating-point view of the values in this segment. If the diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/LeafPointFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/LeafPointFieldData.java index 56c1797c1ca42..2d57a26774ade 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/LeafPointFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/LeafPointFieldData.java @@ -26,6 +26,6 @@ public abstract class LeafPointFieldData toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; public Builder( String name, LongFieldScript.LeafFactory leafFactory, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { this.name = name; this.leafFactory = leafFactory; @@ -45,12 +44,12 @@ public LongScriptFieldData build(IndexFieldDataCache cache, CircuitBreakerServic private final String fieldName; private final LongFieldScript.LeafFactory leafFactory; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; private LongScriptFieldData( String fieldName, LongFieldScript.LeafFactory leafFactory, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { this.fieldName = fieldName; this.leafFactory = leafFactory; @@ -98,11 +97,11 @@ protected boolean isIndexed() { public static class LongScriptLeafFieldData extends LeafLongFieldData { private final LongScriptDocValues longScriptDocValues; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; LongScriptLeafFieldData( LongScriptDocValues longScriptDocValues, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(0); this.longScriptDocValues = longScriptDocValues; @@ -110,7 +109,7 @@ public static class LongScriptLeafFieldData extends LeafLongFieldData { } @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { return longScriptDocValues; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/MultiGeoPointValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/MultiGeoPointValues.java index 06deda44dc364..d625439c5364e 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/MultiGeoPointValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/MultiGeoPointValues.java @@ -8,9 +8,7 @@ */ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.geo.GeoPoint; import java.io.IOException; @@ -33,7 +31,7 @@ public class MultiGeoPointValues extends MultiPointValues { private final GeoPoint point = new GeoPoint(); - public MultiGeoPointValues(SortedNumericDocValues numericValues) { + public MultiGeoPointValues(SortedNumericLongValues numericValues) { super(numericValues); } @@ -46,7 +44,7 @@ public GeoPoint nextValue() throws IOException { * Returns a single-valued view of the {@link MultiPointValues} if possible, otherwise null. */ protected GeoPointValues getPointValues() { - final NumericDocValues singleton = DocValues.unwrapSingleton(numericValues); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(numericValues); return singleton != null ? new GeoPointValues(singleton) : null; } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/MultiPointValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/MultiPointValues.java index 854f06d9b606a..1c18f9750b211 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/MultiPointValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/MultiPointValues.java @@ -8,7 +8,6 @@ */ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.SpatialPoint; @@ -19,12 +18,12 @@ */ public abstract class MultiPointValues { - protected final SortedNumericDocValues numericValues; + protected final SortedNumericLongValues numericValues; /** * Creates a new {@link MultiPointValues} instance */ - protected MultiPointValues(SortedNumericDocValues numericValues) { + protected MultiPointValues(SortedNumericLongValues numericValues) { this.numericValues = numericValues; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/PointValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/PointValues.java index 688217f086ae4..adcda6891304a 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/PointValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/PointValues.java @@ -9,7 +9,7 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.NumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.geo.SpatialPoint; import java.io.IOException; @@ -19,9 +19,9 @@ */ public abstract class PointValues { - protected final NumericDocValues values; + protected final LongValues values; - protected PointValues(NumericDocValues values) { + protected PointValues(LongValues values) { this.values = values; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsNumericDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsNumericDocValues.java index a4166c4dc2e1b..87e2e79ec12a4 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsNumericDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsNumericDocValues.java @@ -10,6 +10,7 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.NumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.NumericUtils; import java.io.IOException; @@ -19,9 +20,8 @@ * and converts the doubles to sortable long bits using * {@link NumericUtils#doubleToSortableLong(double)}. */ -final class SortableLongBitsNumericDocValues extends AbstractNumericDocValues { +final class SortableLongBitsNumericDocValues extends LongValues { - private int docID = -1; private final NumericDoubleValues values; SortableLongBitsNumericDocValues(NumericDoubleValues values) { @@ -35,15 +35,9 @@ public long longValue() throws IOException { @Override public boolean advanceExact(int target) throws IOException { - docID = target; return values.advanceExact(target); } - @Override - public int docID() { - return docID; - } - /** Return the wrapped values. */ public NumericDoubleValues getDoubleValues() { return values; diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsSortedNumericDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsSortedNumericDocValues.java index 9ea37f4afd4a5..1a9c4f5c95be7 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsSortedNumericDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsSortedNumericDocValues.java @@ -9,7 +9,6 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.Scorable; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.common.lucene.ScorerAware; @@ -17,11 +16,11 @@ import java.io.IOException; /** - * {@link SortedNumericDocValues} instance that wraps a {@link SortedNumericDoubleValues} + * {@link SortedNumericLongValues} instance that wraps a {@link SortedNumericDoubleValues} * and converts the doubles to sortable long bits using * {@link NumericUtils#doubleToSortableLong(double)}. */ -final class SortableLongBitsSortedNumericDocValues extends AbstractSortedNumericDocValues implements ScorerAware { +final class SortableLongBitsSortedNumericDocValues extends SortedNumericLongValues implements ScorerAware { private final SortedNumericDoubleValues values; diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToNumericDoubleValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToNumericDoubleValues.java index 5f674125b7c1b..8e210c1520b59 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToNumericDoubleValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToNumericDoubleValues.java @@ -10,6 +10,7 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.NumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.NumericUtils; import java.io.IOException; @@ -21,9 +22,9 @@ */ final class SortableLongBitsToNumericDoubleValues extends NumericDoubleValues { - private final NumericDocValues values; + private final LongValues values; - SortableLongBitsToNumericDoubleValues(NumericDocValues values) { + SortableLongBitsToNumericDoubleValues(LongValues values) { this.values = values; } @@ -38,7 +39,7 @@ public boolean advanceExact(int doc) throws IOException { } /** Return the wrapped values. */ - public NumericDocValues getLongValues() { + public LongValues getLongValues() { return values; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToSortedNumericDoubleValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToSortedNumericDoubleValues.java index ce95003985571..33519b4cb9fba 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToSortedNumericDoubleValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToSortedNumericDoubleValues.java @@ -9,21 +9,20 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.NumericUtils; import java.io.IOException; /** - * {@link SortedNumericDoubleValues} instance that wraps a {@link SortedNumericDocValues} + * {@link SortedNumericDoubleValues} instance that wraps a {@link SortedNumericLongValues} * and converts the doubles to sortable long bits using * {@link NumericUtils#sortableLongToDouble(long)}. */ final class SortableLongBitsToSortedNumericDoubleValues extends SortedNumericDoubleValues { - private final SortedNumericDocValues values; + private final SortedNumericLongValues values; - SortableLongBitsToSortedNumericDoubleValues(SortedNumericDocValues values) { + SortableLongBitsToSortedNumericDoubleValues(SortedNumericLongValues values) { this.values = values; } @@ -43,7 +42,7 @@ public int docValueCount() { } /** Return the wrapped values. */ - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { return values; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SortedNumericLongValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/SortedNumericLongValues.java new file mode 100644 index 0000000000000..d70fc86bb2a97 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SortedNumericLongValues.java @@ -0,0 +1,110 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +package org.elasticsearch.index.fielddata; + +import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; + +import java.io.IOException; + +public abstract class SortedNumericLongValues { + + public static SortedNumericLongValues EMPTY = new SortedNumericLongValues() { + @Override + public boolean advanceExact(int target) { + return false; + } + + @Override + public long nextValue() { + throw new UnsupportedOperationException(); + } + + @Override + public int docValueCount() { + throw new UnsupportedOperationException(); + } + }; + + /** Advance the iterator to exactly {@code target} and return whether + * {@code target} has a value. + * {@code target} must be greater than or equal to the current + * doc ID and must be a valid doc ID, ie. ≥ 0 and + * < {@code maxDoc}.*/ + public abstract boolean advanceExact(int target) throws IOException; + + /** + * Iterates to the next value in the current document. Do not call this more than + * {@link #docValueCount} times for the document. + */ + public abstract long nextValue() throws IOException; + + /** + * Retrieves the number of values for the current document. This must always + * be greater than zero. + * It is illegal to call this method after {@link #advanceExact(int)} + * returned {@code false}. + */ + public abstract int docValueCount(); + + public static LongValues unwrapSingleton(SortedNumericLongValues values) { + if (values instanceof SingletonSortedNumericLongValues sv) { + return sv.values; + } + return null; + } + + public static SortedNumericLongValues singleton(LongValues values) { + return new SingletonSortedNumericLongValues(values); + } + + private static class SingletonSortedNumericLongValues extends SortedNumericLongValues { + + private final LongValues values; + + private SingletonSortedNumericLongValues(LongValues values) { + this.values = values; + } + + @Override + public boolean advanceExact(int target) throws IOException { + return values.advanceExact(target); + } + + @Override + public long nextValue() throws IOException { + return values.longValue(); + } + + @Override + public int docValueCount() { + return 1; + } + } + + public static SortedNumericLongValues wrap(SortedNumericDocValues values) { + return new SortedNumericLongValues() { + @Override + public boolean advanceExact(int target) throws IOException { + return values.advanceExact(target); + } + + @Override + public long nextValue() throws IOException { + return values.nextValue(); + } + + @Override + public int docValueCount() { + return values.docValueCount(); + } + }; + } +} diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SortingNumericDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/SortingNumericLongValues.java similarity index 90% rename from server/src/main/java/org/elasticsearch/index/fielddata/SortingNumericDocValues.java rename to server/src/main/java/org/elasticsearch/index/fielddata/SortingNumericLongValues.java index 02f5de7e3c8ca..595726bf6f215 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SortingNumericDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SortingNumericLongValues.java @@ -9,7 +9,6 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.InPlaceMergeSorter; import org.apache.lucene.util.Sorter; @@ -17,9 +16,9 @@ import java.util.function.LongConsumer; /** - * Base class for building {@link SortedNumericDocValues} instances based on unsorted content. + * Base class for building {@link SortedNumericLongValues} instances based on unsorted content. */ -public abstract class SortingNumericDocValues extends SortedNumericDocValues { +public abstract class SortingNumericLongValues extends SortedNumericLongValues { private int count; protected long[] values; @@ -27,11 +26,11 @@ public abstract class SortingNumericDocValues extends SortedNumericDocValues { private final Sorter sorter; private final LongConsumer circuitBreakerConsumer; - protected SortingNumericDocValues() { + protected SortingNumericLongValues() { this(l -> {}); } - protected SortingNumericDocValues(LongConsumer circuitBreakerConsumer) { + protected SortingNumericLongValues(LongConsumer circuitBreakerConsumer) { values = new long[1]; valuesCursor = 0; sorter = new InPlaceMergeSorter() { diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedBooleanIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedBooleanIndexFieldData.java index 56937d47b794d..757646c7b8ca9 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedBooleanIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedBooleanIndexFieldData.java @@ -10,7 +10,6 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.mapper.ValueFetcher; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.script.field.DocValuesScriptFieldFactory; @@ -22,16 +21,16 @@ import java.io.IOException; import java.util.Collections; -public class SourceValueFetcherSortedBooleanIndexFieldData extends SourceValueFetcherIndexFieldData { +public class SourceValueFetcherSortedBooleanIndexFieldData extends SourceValueFetcherIndexFieldData { - public static class Builder extends SourceValueFetcherIndexFieldData.Builder { + public static class Builder extends SourceValueFetcherIndexFieldData.Builder { public Builder( String fieldName, ValuesSourceType valuesSourceType, ValueFetcher valueFetcher, SourceProvider sourceProvider, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, valueFetcher, sourceProvider, toScriptFieldFactory); } @@ -53,20 +52,20 @@ protected SourceValueFetcherSortedBooleanIndexFieldData( ValuesSourceType valuesSourceType, ValueFetcher valueFetcher, SourceProvider sourceProvider, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, valueFetcher, sourceProvider, toScriptFieldFactory); } @Override - public SourceValueFetcherLeafFieldData loadDirect(LeafReaderContext context) { + public SourceValueFetcherLeafFieldData loadDirect(LeafReaderContext context) { return new SourceValueFetcherSortedBooleanLeafFieldData(toScriptFieldFactory, context, valueFetcher, sourceProvider); } - private static class SourceValueFetcherSortedBooleanLeafFieldData extends SourceValueFetcherLeafFieldData { + private static class SourceValueFetcherSortedBooleanLeafFieldData extends SourceValueFetcherLeafFieldData { private SourceValueFetcherSortedBooleanLeafFieldData( - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, LeafReaderContext leafReaderContext, ValueFetcher valueFetcher, SourceProvider sourceProvider @@ -83,7 +82,7 @@ public DocValuesScriptFieldFactory getScriptFieldFactory(String name) { } } - static class SourceValueFetcherSortedBooleanDocValues extends SortedNumericDocValues implements ValueFetcherDocValues { + static class SourceValueFetcherSortedBooleanDocValues extends SortedNumericLongValues implements ValueFetcherDocValues { private final LeafReaderContext leafReaderContext; @@ -133,25 +132,5 @@ public long nextValue() { assert iteratorIndex < trueCount + falseCount; return iteratorIndex++ < falseCount ? 0L : 1L; } - - @Override - public int docID() { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public int nextDoc() { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public int advance(int target) { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public long cost() { - throw new UnsupportedOperationException("not supported for source fallback"); - } } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedNumericIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedNumericIndexFieldData.java index ce1dff33e80ce..aab8cb26df8d4 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedNumericIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedNumericIndexFieldData.java @@ -10,7 +10,6 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.mapper.ValueFetcher; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.script.field.DocValuesScriptFieldFactory; @@ -25,16 +24,16 @@ import java.util.Iterator; import java.util.List; -public class SourceValueFetcherSortedNumericIndexFieldData extends SourceValueFetcherIndexFieldData { +public class SourceValueFetcherSortedNumericIndexFieldData extends SourceValueFetcherIndexFieldData { - public static class Builder extends SourceValueFetcherIndexFieldData.Builder { + public static class Builder extends SourceValueFetcherIndexFieldData.Builder { public Builder( String fieldName, ValuesSourceType valuesSourceType, ValueFetcher valueFetcher, SourceProvider sourceProvider, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, valueFetcher, sourceProvider, toScriptFieldFactory); } @@ -56,7 +55,7 @@ protected SourceValueFetcherSortedNumericIndexFieldData( ValuesSourceType valuesSourceType, ValueFetcher valueFetcher, SourceProvider sourceProvider, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, valueFetcher, sourceProvider, toScriptFieldFactory); } @@ -66,10 +65,10 @@ public SourceValueFetcherSortedNumericLeafFieldData loadDirect(LeafReaderContext return new SourceValueFetcherSortedNumericLeafFieldData(toScriptFieldFactory, context, valueFetcher, sourceProvider); } - public static class SourceValueFetcherSortedNumericLeafFieldData extends SourceValueFetcherLeafFieldData { + public static class SourceValueFetcherSortedNumericLeafFieldData extends SourceValueFetcherLeafFieldData { public SourceValueFetcherSortedNumericLeafFieldData( - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, LeafReaderContext leafReaderContext, ValueFetcher valueFetcher, SourceProvider sourceProvider @@ -86,7 +85,7 @@ public DocValuesScriptFieldFactory getScriptFieldFactory(String name) { } } - public static class SourceValueFetcherSortedNumericDocValues extends SortedNumericDocValues implements ValueFetcherDocValues { + public static class SourceValueFetcherSortedNumericDocValues extends SortedNumericLongValues implements ValueFetcherDocValues { protected final LeafReaderContext leafReaderContext; @@ -133,25 +132,5 @@ public long nextValue() { assert iterator.hasNext(); return iterator.next(); } - - @Override - public int docID() { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public int nextDoc() { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public int advance(int target) { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public long cost() { - throw new UnsupportedOperationException("not supported for source fallback"); - } } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/IntValuesComparatorSource.java b/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/IntValuesComparatorSource.java index 184288d0437b8..544b933772065 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/IntValuesComparatorSource.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/IntValuesComparatorSource.java @@ -12,6 +12,7 @@ import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.search.FieldComparator; import org.apache.lucene.search.LeafFieldComparator; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.Pruning; import org.apache.lucene.search.SortField; import org.apache.lucene.search.comparators.IntComparator; @@ -59,7 +60,7 @@ public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws I return new IntLeafComparator(context) { @Override protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException { - return IntValuesComparatorSource.this.getNumericDocValues(context, iMissingValue); + return wrap(getLongValues(context, iMissingValue)); } }; } @@ -80,7 +81,7 @@ public BucketedSort newBucketedSort( @Override public Leaf forLeaf(LeafReaderContext ctx) throws IOException { return new Leaf(ctx) { - private final NumericDocValues docValues = getNumericDocValues(ctx, iMissingValue); + private final LongValues docValues = getLongValues(ctx, iMissingValue); private int docValue; @Override diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/LongValuesComparatorSource.java b/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/LongValuesComparatorSource.java index 84ad27efe7778..d27c1b4784311 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/LongValuesComparatorSource.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/LongValuesComparatorSource.java @@ -10,10 +10,10 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.FieldComparator; import org.apache.lucene.search.LeafFieldComparator; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.Pruning; import org.apache.lucene.search.SortField; import org.apache.lucene.search.comparators.LongComparator; @@ -26,6 +26,7 @@ import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType; import org.elasticsearch.index.fielddata.LeafNumericFieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.MultiValueMode; @@ -41,7 +42,7 @@ public class LongValuesComparatorSource extends IndexFieldData.XFieldComparatorSource { final IndexNumericFieldData indexFieldData; - private final Function converter; + private final Function converter; private final NumericType targetNumericType; public LongValuesComparatorSource( @@ -59,7 +60,7 @@ public LongValuesComparatorSource( @Nullable Object missingValue, MultiValueMode sortMode, Nested nested, - Function converter, + Function converter, NumericType targetNumericType ) { super(missingValue, sortMode, nested); @@ -73,9 +74,9 @@ public SortField.Type reducedType() { return SortField.Type.LONG; } - private SortedNumericDocValues loadDocValues(LeafReaderContext context) { + private SortedNumericLongValues loadDocValues(LeafReaderContext context) { final LeafNumericFieldData data = indexFieldData.load(context); - SortedNumericDocValues values; + SortedNumericLongValues values; if (data instanceof SortedNumericIndexFieldData.NanoSecondFieldData) { values = ((SortedNumericIndexFieldData.NanoSecondFieldData) data).getLongValuesAsNanos(); } else { @@ -84,8 +85,8 @@ private SortedNumericDocValues loadDocValues(LeafReaderContext context) { return converter != null ? converter.apply(values) : values; } - NumericDocValues getNumericDocValues(LeafReaderContext context, long missingValue) throws IOException { - final SortedNumericDocValues values = loadDocValues(context); + LongValues getLongValues(LeafReaderContext context, long missingValue) throws IOException { + final SortedNumericLongValues values = loadDocValues(context); if (nested == null) { return FieldData.replaceMissing(sortMode.select(values), missingValue); } @@ -108,7 +109,7 @@ public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws I return new LongLeafComparator(context) { @Override protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException { - return LongValuesComparatorSource.this.getNumericDocValues(context, lMissingValue); + return wrap(getLongValues(context, lMissingValue)); } }; } @@ -129,7 +130,7 @@ public BucketedSort newBucketedSort( @Override public Leaf forLeaf(LeafReaderContext ctx) throws IOException { return new Leaf(ctx) { - private final NumericDocValues docValues = getNumericDocValues(ctx, lMissingValue); + private final LongValues docValues = getLongValues(ctx, lMissingValue); private long docValue; @Override @@ -161,4 +162,38 @@ public Object missingObject(Object missingValue, boolean reversed) { } return super.missingObject(missingValue, reversed); } + + protected static NumericDocValues wrap(LongValues longValues) { + return new NumericDocValues() { + @Override + public long longValue() throws IOException { + return longValues.longValue(); + } + + @Override + public boolean advanceExact(int target) throws IOException { + return longValues.advanceExact(target); + } + + @Override + public int docID() { + throw new UnsupportedOperationException(); + } + + @Override + public int nextDoc() throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public int advance(int target) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public long cost() { + throw new UnsupportedOperationException(); + } + }; + } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/FormattedSortedNumericDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/FormattedSortedNumericDocValues.java index da64520c7c86c..0599e2d336100 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/FormattedSortedNumericDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/FormattedSortedNumericDocValues.java @@ -8,17 +8,17 @@ */ package org.elasticsearch.index.fielddata.plain; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.FormattedDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import java.io.IOException; public final class FormattedSortedNumericDocValues implements FormattedDocValues { - private final SortedNumericDocValues values; + private final SortedNumericLongValues values; private final DocValueFormat format; - public FormattedSortedNumericDocValues(SortedNumericDocValues values, DocValueFormat format) { + public FormattedSortedNumericDocValues(SortedNumericLongValues values, DocValueFormat format) { this.values = values; this.format = format; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/LatLonPointDVLeafFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/LatLonPointDVLeafFieldData.java index 64e6dd223caf4..2a998db041bf4 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/LatLonPointDVLeafFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/LatLonPointDVLeafFieldData.java @@ -10,8 +10,8 @@ import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReader; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.MultiGeoPointValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.field.ToScriptFieldFactory; import java.io.IOException; @@ -32,9 +32,9 @@ public long ramBytesUsed() { } @Override - public SortedNumericDocValues getSortedNumericDocValues() { + public SortedNumericLongValues getSortedNumericLongValues() { try { - return DocValues.getSortedNumeric(reader, fieldName); + return SortedNumericLongValues.wrap(DocValues.getSortedNumeric(reader, fieldName)); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafDoubleFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafDoubleFieldData.java index e870f7af22562..f3d4cad1aa65c 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafDoubleFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafDoubleFieldData.java @@ -9,12 +9,12 @@ package org.elasticsearch.index.fielddata.plain; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.FormattedDocValues; import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import java.io.IOException; @@ -35,7 +35,7 @@ public final SortedBinaryDocValues getBytesValues() { } @Override - public final SortedNumericDocValues getLongValues() { + public final SortedNumericLongValues getLongValues() { return FieldData.castToLong(getDoubleValues()); } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafGeoPointFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafGeoPointFieldData.java index 3d5e9846eab5f..35faf47d0cb0c 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafGeoPointFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafGeoPointFieldData.java @@ -25,7 +25,7 @@ public LeafGeoPointFieldData(ToScriptFieldFactory toScriptF @Override public final MultiGeoPointValues getPointValues() { - return new MultiGeoPointValues(getSortedNumericDocValues()); + return new MultiGeoPointValues(getSortedNumericLongValues()); } @Override diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedDoublesIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedDoublesIndexFieldData.java index ae20100f4c1f7..51d0cfd5072a3 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedDoublesIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedDoublesIndexFieldData.java @@ -24,6 +24,7 @@ import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.script.field.DocValuesScriptFieldFactory; import org.elasticsearch.script.field.ToScriptFieldFactory; @@ -350,7 +351,7 @@ static final class SortedNumericDoubleFieldData extends LeafDoubleFieldData { public SortedNumericDoubleValues getDoubleValues() { try { SortedNumericDocValues raw = DocValues.getSortedNumeric(reader, field); - return FieldData.sortableLongBitsToDoubles(raw); + return FieldData.sortableLongBitsToDoubles(SortedNumericLongValues.wrap(raw)); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericIndexFieldData.java index 98fd4e27f9422..e40f71b344b74 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericIndexFieldData.java @@ -21,6 +21,7 @@ import org.elasticsearch.index.fielddata.IndexFieldDataCache; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.fielddata.LeafNumericFieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.script.field.DocValuesScriptFieldFactory; @@ -42,13 +43,13 @@ public static class Builder implements IndexFieldData.Builder { private final String name; private final NumericType numericType; private final ValuesSourceType valuesSourceType; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; private final boolean indexed; public Builder( String name, NumericType numericType, - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, boolean indexed ) { this(name, numericType, numericType.getValuesSourceType(), toScriptFieldFactory, indexed); @@ -58,7 +59,7 @@ public Builder( String name, NumericType numericType, ValuesSourceType valuesSourceType, - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, boolean indexed ) { this.name = name; @@ -77,14 +78,14 @@ public SortedNumericIndexFieldData build(IndexFieldDataCache cache, CircuitBreak private final NumericType numericType; protected final String fieldName; protected final ValuesSourceType valuesSourceType; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; protected final boolean indexed; public SortedNumericIndexFieldData( String fieldName, NumericType numericType, ValuesSourceType valuesSourceType, - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, boolean indexed ) { this.fieldName = fieldName; @@ -177,9 +178,9 @@ public static final class NanoSecondFieldData extends LeafLongFieldData { private final LeafReader reader; private final String fieldName; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; - NanoSecondFieldData(LeafReader reader, String fieldName, ToScriptFieldFactory toScriptFieldFactory) { + NanoSecondFieldData(LeafReader reader, String fieldName, ToScriptFieldFactory toScriptFieldFactory) { super(0L); this.reader = reader; this.fieldName = fieldName; @@ -187,13 +188,13 @@ public static final class NanoSecondFieldData extends LeafLongFieldData { } @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { return convertNumeric(getLongValuesAsNanos(), DateUtils::toMilliSeconds); } - public SortedNumericDocValues getLongValuesAsNanos() { + public SortedNumericLongValues getLongValuesAsNanos() { try { - return DocValues.getSortedNumeric(reader, fieldName); + return SortedNumericLongValues.wrap(DocValues.getSortedNumeric(reader, fieldName)); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } @@ -225,9 +226,9 @@ public FormattedDocValues getFormattedValues(DocValueFormat format) { static final class SortedNumericLongFieldData extends LeafLongFieldData { final LeafReader reader; final String field; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; - SortedNumericLongFieldData(LeafReader reader, String field, ToScriptFieldFactory toScriptFieldFactory) { + SortedNumericLongFieldData(LeafReader reader, String field, ToScriptFieldFactory toScriptFieldFactory) { super(0L); this.reader = reader; this.field = field; @@ -235,9 +236,9 @@ static final class SortedNumericLongFieldData extends LeafLongFieldData { } @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { try { - return DocValues.getSortedNumeric(reader, field); + return SortedNumericLongValues.wrap(DocValues.getSortedNumeric(reader, field)); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java index cc4ec0c2f8296..9991abba7ba6a 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java @@ -20,7 +20,6 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.PointValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.IndexOrDocValuesQuery; import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery; import org.apache.lucene.search.Query; @@ -45,6 +44,7 @@ import org.elasticsearch.index.fielddata.FieldDataContext; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.SourceValueFetcherSortedNumericIndexFieldData; import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData; import org.elasticsearch.index.query.DateRangeIncludingNowQuery; @@ -186,9 +186,9 @@ public long roundUpToMillis(long value) { private final String type; private final NumericType numericType; - private final ToScriptFieldFactory toScriptFieldFactory; + private final ToScriptFieldFactory toScriptFieldFactory; - Resolution(String type, NumericType numericType, ToScriptFieldFactory toScriptFieldFactory) { + Resolution(String type, NumericType numericType, ToScriptFieldFactory toScriptFieldFactory) { this.type = type; this.numericType = numericType; this.toScriptFieldFactory = toScriptFieldFactory; @@ -202,7 +202,7 @@ NumericType numericType() { return numericType; } - ToScriptFieldFactory getDefaultToScriptFieldFactory() { + ToScriptFieldFactory getDefaultToScriptFieldFactory() { return toScriptFieldFactory; } diff --git a/server/src/main/java/org/elasticsearch/index/query/TermsSetQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/TermsSetQueryBuilder.java index b12b417e24aa8..232423bed08ca 100644 --- a/server/src/main/java/org/elasticsearch/index/query/TermsSetQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/TermsSetQueryBuilder.java @@ -9,7 +9,6 @@ package org.elasticsearch.index.query; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.Term; import org.apache.lucene.sandbox.search.CoveringQuery; import org.apache.lucene.search.DoubleValues; @@ -26,6 +25,7 @@ import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.index.fielddata.IndexNumericFieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.script.Script; import org.elasticsearch.script.TermsSetQueryScript; @@ -438,7 +438,7 @@ public int hashCode() { @Override public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { - SortedNumericDocValues values = fieldData.load(ctx).getLongValues(); + SortedNumericLongValues values = fieldData.load(ctx).getLongValues(); return new LongValues() { long current = -1; diff --git a/server/src/main/java/org/elasticsearch/script/SortedNumericDocValuesLongFieldScript.java b/server/src/main/java/org/elasticsearch/script/SortedNumericDocValuesLongFieldScript.java index d4ede3827092a..6801a939754e6 100644 --- a/server/src/main/java/org/elasticsearch/script/SortedNumericDocValuesLongFieldScript.java +++ b/server/src/main/java/org/elasticsearch/script/SortedNumericDocValuesLongFieldScript.java @@ -11,6 +11,7 @@ import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.OnScriptError; import org.elasticsearch.script.field.LongDocValuesField; import org.elasticsearch.search.lookup.SearchLookup; @@ -25,7 +26,10 @@ public class SortedNumericDocValuesLongFieldScript extends AbstractLongFieldScri public SortedNumericDocValuesLongFieldScript(String fieldName, SearchLookup lookup, LeafReaderContext ctx) { super(fieldName, Map.of(), lookup, OnScriptError.FAIL, ctx); try { - longDocValuesField = new LongDocValuesField(DocValues.getSortedNumeric(ctx.reader(), fieldName), fieldName); + longDocValuesField = new LongDocValuesField( + SortedNumericLongValues.wrap(DocValues.getSortedNumeric(ctx.reader(), fieldName)), + fieldName + ); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } diff --git a/server/src/main/java/org/elasticsearch/script/field/AbstractLongDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/AbstractLongDocValuesField.java index 1d54bfb4e701b..e9f7e641f9c12 100644 --- a/server/src/main/java/org/elasticsearch/script/field/AbstractLongDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/AbstractLongDocValuesField.java @@ -9,9 +9,9 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.ArrayUtil; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.util.NoSuchElementException; @@ -28,11 +28,11 @@ public abstract class AbstractLongDocValuesField extends AbstractScriptFieldFact // as a delegate to this field class protected ScriptDocValues scriptDocValues = null; - protected final SortedNumericDocValues input; + protected final SortedNumericLongValues input; protected long[] values = new long[0]; protected int count; - public AbstractLongDocValuesField(SortedNumericDocValues input, String name) { + public AbstractLongDocValuesField(SortedNumericLongValues input, String name) { this.input = input; this.name = name; } diff --git a/server/src/main/java/org/elasticsearch/script/field/BooleanDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/BooleanDocValuesField.java index cd63f665a98db..5dfbb06a55f6f 100644 --- a/server/src/main/java/org/elasticsearch/script/field/BooleanDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/BooleanDocValuesField.java @@ -9,9 +9,9 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.ArrayUtil; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.util.Arrays; @@ -24,7 +24,7 @@ public class BooleanDocValuesField extends AbstractScriptFieldFactory DocValuesScriptFieldFactory, ScriptDocValues.Supplier { - private final SortedNumericDocValues input; + private final SortedNumericLongValues input; private final String name; private boolean[] values = new boolean[0]; @@ -34,7 +34,7 @@ public class BooleanDocValuesField extends AbstractScriptFieldFactory // as a delegate to this field class private ScriptDocValues.Booleans booleans = null; - public BooleanDocValuesField(SortedNumericDocValues input, String name) { + public BooleanDocValuesField(SortedNumericLongValues input, String name) { this.input = input; this.name = name; } diff --git a/server/src/main/java/org/elasticsearch/script/field/ByteDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/ByteDocValuesField.java index 4dfbb379601f9..972e3e5c080f2 100644 --- a/server/src/main/java/org/elasticsearch/script/field/ByteDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/ByteDocValuesField.java @@ -9,9 +9,9 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.ArrayUtil; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.util.Iterator; @@ -23,7 +23,7 @@ public class ByteDocValuesField extends AbstractScriptFieldFactory DocValuesScriptFieldFactory, ScriptDocValues.Supplier { - protected final SortedNumericDocValues input; + protected final SortedNumericLongValues input; protected final String name; protected byte[] values = new byte[0]; @@ -31,7 +31,7 @@ public class ByteDocValuesField extends AbstractScriptFieldFactory private ScriptDocValues.Longs longs = null; - public ByteDocValuesField(SortedNumericDocValues input, String name) { + public ByteDocValuesField(SortedNumericLongValues input, String name) { this.input = input; this.name = name; } diff --git a/server/src/main/java/org/elasticsearch/script/field/DateMillisDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/DateMillisDocValuesField.java index 366a8a9044bbe..648d364265425 100644 --- a/server/src/main/java/org/elasticsearch/script/field/DateMillisDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/DateMillisDocValuesField.java @@ -9,9 +9,9 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.ArrayUtil; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.time.Instant; @@ -26,7 +26,7 @@ public class DateMillisDocValuesField extends AbstractScriptFieldFactory { - protected final SortedNumericDocValues input; + protected final SortedNumericLongValues input; protected final String name; protected ZonedDateTime[] values = new ZonedDateTime[0]; @@ -34,7 +34,7 @@ public class DateMillisDocValuesField extends AbstractScriptFieldFactory { - protected final SortedNumericDocValues input; + protected final SortedNumericLongValues input; protected final String name; protected ZonedDateTime[] values = new ZonedDateTime[0]; @@ -34,7 +34,7 @@ public class DateNanosDocValuesField extends AbstractScriptFieldFactory DocValuesScriptFieldFactory, ScriptDocValues.Supplier { - protected final SortedNumericDocValues input; + protected final SortedNumericLongValues input; protected final String name; protected int[] values = new int[0]; @@ -31,7 +31,7 @@ public class IntegerDocValuesField extends AbstractScriptFieldFactory private ScriptDocValues.Longs longs = null; - public IntegerDocValuesField(SortedNumericDocValues input, String name) { + public IntegerDocValuesField(SortedNumericLongValues input, String name) { this.input = input; this.name = name; } diff --git a/server/src/main/java/org/elasticsearch/script/field/LongDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/LongDocValuesField.java index a2795aaa2f569..c770863aebf49 100644 --- a/server/src/main/java/org/elasticsearch/script/field/LongDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/LongDocValuesField.java @@ -9,11 +9,11 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; public class LongDocValuesField extends AbstractLongDocValuesField { - public LongDocValuesField(SortedNumericDocValues input, String name) { + public LongDocValuesField(SortedNumericLongValues input, String name) { super(input, name); } } diff --git a/server/src/main/java/org/elasticsearch/script/field/SeqNoDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/SeqNoDocValuesField.java index 5b26dcec6a2bc..a04c502c5359c 100644 --- a/server/src/main/java/org/elasticsearch/script/field/SeqNoDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/SeqNoDocValuesField.java @@ -9,10 +9,10 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; public class SeqNoDocValuesField extends AbstractLongDocValuesField { - public SeqNoDocValuesField(SortedNumericDocValues input, String name) { + public SeqNoDocValuesField(SortedNumericLongValues input, String name) { super(input, name); } } diff --git a/server/src/main/java/org/elasticsearch/script/field/ShortDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/ShortDocValuesField.java index f75e7f7c50316..b0fe12d62575e 100644 --- a/server/src/main/java/org/elasticsearch/script/field/ShortDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/ShortDocValuesField.java @@ -9,9 +9,9 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.ArrayUtil; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.util.Iterator; @@ -23,7 +23,7 @@ public class ShortDocValuesField extends AbstractScriptFieldFactory DocValuesScriptFieldFactory, ScriptDocValues.Supplier { - protected final SortedNumericDocValues input; + protected final SortedNumericLongValues input; protected final String name; protected short[] values = new short[0]; @@ -31,7 +31,7 @@ public class ShortDocValuesField extends AbstractScriptFieldFactory private ScriptDocValues.Longs longs = null; - public ShortDocValuesField(SortedNumericDocValues input, String name) { + public ShortDocValuesField(SortedNumericLongValues input, String name) { this.input = input; this.name = name; } diff --git a/server/src/main/java/org/elasticsearch/script/field/VersionDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/VersionDocValuesField.java index 80dffbb8ceb45..9b8e49d79ca73 100644 --- a/server/src/main/java/org/elasticsearch/script/field/VersionDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/VersionDocValuesField.java @@ -9,10 +9,10 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; public class VersionDocValuesField extends AbstractLongDocValuesField { - public VersionDocValuesField(SortedNumericDocValues input, String name) { + public VersionDocValuesField(SortedNumericLongValues input, String name) { super(input, name); } } diff --git a/server/src/main/java/org/elasticsearch/search/MultiValueMode.java b/server/src/main/java/org/elasticsearch/search/MultiValueMode.java index 5ac25fe0ff695..1126898341afb 100644 --- a/server/src/main/java/org/elasticsearch/search/MultiValueMode.java +++ b/server/src/main/java/org/elasticsearch/search/MultiValueMode.java @@ -13,9 +13,9 @@ import org.apache.lucene.index.DocValues; import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.SortedDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.search.DocIdSetIterator; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.BitSet; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; @@ -23,12 +23,12 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.index.fielddata.AbstractBinaryDocValues; -import org.elasticsearch.index.fielddata.AbstractNumericDocValues; import org.elasticsearch.index.fielddata.AbstractSortedDocValues; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.util.Locale; @@ -42,7 +42,7 @@ public enum MultiValueMode implements Writeable { */ SUM { @Override - protected long pick(SortedNumericDocValues values) throws IOException { + protected long pick(SortedNumericLongValues values) throws IOException { final int count = values.docValueCount(); long total = 0; for (int index = 0; index < count; ++index) { @@ -53,7 +53,7 @@ protected long pick(SortedNumericDocValues values) throws IOException { @Override protected long pick( - SortedNumericDocValues values, + SortedNumericLongValues values, long missingValue, DocIdSetIterator docItr, int startDoc, @@ -123,7 +123,7 @@ protected double pick( */ AVG { @Override - protected long pick(SortedNumericDocValues values) throws IOException { + protected long pick(SortedNumericLongValues values) throws IOException { final int count = values.docValueCount(); long total = 0; for (int index = 0; index < count; ++index) { @@ -134,7 +134,7 @@ protected long pick(SortedNumericDocValues values) throws IOException { @Override protected long pick( - SortedNumericDocValues values, + SortedNumericLongValues values, long missingValue, DocIdSetIterator docItr, int startDoc, @@ -208,7 +208,7 @@ protected double pick( */ MEDIAN { @Override - protected long pick(SortedNumericDocValues values) throws IOException { + protected long pick(SortedNumericLongValues values) throws IOException { int count = values.docValueCount(); for (int i = 0; i < (count - 1) / 2; ++i) { values.nextValue(); @@ -239,13 +239,13 @@ protected double pick(SortedNumericDoubleValues values) throws IOException { */ MIN { @Override - protected long pick(SortedNumericDocValues values) throws IOException { + protected long pick(SortedNumericLongValues values) throws IOException { return values.nextValue(); } @Override protected long pick( - SortedNumericDocValues values, + SortedNumericLongValues values, long missingValue, DocIdSetIterator docItr, int startDoc, @@ -362,7 +362,7 @@ protected int pick(SortedDocValues values, DocIdSetIterator docItr, int startDoc */ MAX { @Override - protected long pick(SortedNumericDocValues values) throws IOException { + protected long pick(SortedNumericLongValues values) throws IOException { final int count = values.docValueCount(); for (int i = 0; i < count - 1; ++i) { values.nextValue(); @@ -372,7 +372,7 @@ protected long pick(SortedNumericDocValues values) throws IOException { @Override protected long pick( - SortedNumericDocValues values, + SortedNumericLongValues values, long missingValue, DocIdSetIterator docItr, int startDoc, @@ -520,12 +520,12 @@ public static MultiValueMode fromString(String sortMode) { * * Allowed Modes: SUM, AVG, MEDIAN, MIN, MAX */ - public NumericDocValues select(final SortedNumericDocValues values) { - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + public LongValues select(final SortedNumericLongValues values) { + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); if (singleton != null) { return singleton; } else { - return new AbstractNumericDocValues() { + return new LongValues() { private long value; @@ -538,11 +538,6 @@ public boolean advanceExact(int target) throws IOException { return false; } - @Override - public int docID() { - return values.docID(); - } - @Override public long longValue() { return value; @@ -551,7 +546,7 @@ public long longValue() { } } - protected long pick(SortedNumericDocValues values) throws IOException { + protected long pick(SortedNumericLongValues values) throws IOException { throw new IllegalArgumentException("Unsupported sort mode: " + this); } @@ -567,18 +562,18 @@ protected long pick(SortedNumericDocValues values) throws IOException { * NOTE: Calling the returned instance on docs that are not root docs is illegal * The returned instance can only be evaluate the current and upcoming docs */ - public NumericDocValues select( - final SortedNumericDocValues values, + public LongValues select( + final SortedNumericLongValues values, final long missingValue, final BitSet parentDocs, final DocIdSetIterator childDocs, int maxChildren ) throws IOException { if (parentDocs == null || childDocs == null) { - return FieldData.replaceMissing(DocValues.emptyNumeric(), missingValue); + return FieldData.replaceMissing(FieldData.EMPTY, missingValue); } - return new AbstractNumericDocValues() { + return new LongValues() { int lastSeenParentDoc = -1; long lastEmittedValue = missingValue; @@ -600,11 +595,6 @@ public boolean advanceExact(int parentDoc) throws IOException { return true; } - @Override - public int docID() { - return lastSeenParentDoc; - } - @Override public long longValue() { return lastEmittedValue; @@ -613,7 +603,7 @@ public long longValue() { } protected long pick( - SortedNumericDocValues values, + SortedNumericLongValues values, long missingValue, DocIdSetIterator docItr, int startDoc, diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileValuesSource.java index 535e7c49beb6d..e499f62f93bbb 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileValuesSource.java @@ -10,9 +10,9 @@ package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.core.CheckedFunction; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.search.DocValueFormat; @@ -29,7 +29,7 @@ class GeoTileValuesSource extends LongValuesSource { GeoTileValuesSource( BigArrays bigArrays, MappedFieldType fieldType, - CheckedFunction docValuesFunc, + CheckedFunction docValuesFunc, LongUnaryOperator rounding, DocValueFormat format, boolean missingBucket, diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSource.java index b24b453078960..50c8609224909 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSource.java @@ -10,10 +10,10 @@ package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.aggregations.support.ValuesSource; import java.io.IOException; @@ -86,7 +86,7 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext context) throws IOExc } @Override - public SortedNumericDocValues longValues(LeafReaderContext context) throws IOException { + public SortedNumericLongValues longValues(LeafReaderContext context) throws IOException { throw new UnsupportedOperationException("not applicable"); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java index 0e30a4cec3fc4..aa7071708774e 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java @@ -11,15 +11,13 @@ import org.apache.lucene.document.IntPoint; import org.apache.lucene.document.LongPoint; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.FieldExistsQuery; import org.apache.lucene.search.IndexOrDocValuesQuery; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.PointRangeQuery; import org.apache.lucene.search.Query; @@ -28,6 +26,7 @@ import org.elasticsearch.common.util.LongArray; import org.elasticsearch.core.CheckedFunction; import org.elasticsearch.core.Releasables; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.NumberFieldMapper; @@ -43,7 +42,7 @@ */ class LongValuesSource extends SingleDimensionValuesSource { private final BigArrays bigArrays; - private final CheckedFunction docValuesFunc; + private final CheckedFunction docValuesFunc; private final LongUnaryOperator rounding; private final BitArray bits; @@ -54,7 +53,7 @@ class LongValuesSource extends SingleDimensionValuesSource { LongValuesSource( BigArrays bigArrays, MappedFieldType fieldType, - CheckedFunction docValuesFunc, + CheckedFunction docValuesFunc, LongUnaryOperator rounding, DocValueFormat format, boolean missingBucket, @@ -172,12 +171,12 @@ Long toComparable(int slot) { @Override LeafBucketCollector getLeafCollector(LeafReaderContext context, LeafBucketCollector next) throws IOException { - final SortedNumericDocValues dvs = docValuesFunc.apply(context); - final NumericDocValues singleton = DocValues.unwrapSingleton(dvs); + final SortedNumericLongValues dvs = docValuesFunc.apply(context); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(dvs); return singleton != null ? getLeafCollector(singleton, next) : getLeafCollector(dvs, next); } - private LeafBucketCollector getLeafCollector(SortedNumericDocValues dvs, LeafBucketCollector next) { + private LeafBucketCollector getLeafCollector(SortedNumericLongValues dvs, LeafBucketCollector next) { return new LeafBucketCollector() { @Override public void collect(int doc, long bucket) throws IOException { @@ -200,7 +199,7 @@ public void collect(int doc, long bucket) throws IOException { }; } - private LeafBucketCollector getLeafCollector(NumericDocValues dvs, LeafBucketCollector next) { + private LeafBucketCollector getLeafCollector(LongValues dvs, LeafBucketCollector next) { return new LeafBucketCollector() { @Override public void collect(int doc, long bucket) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/RoundingValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/RoundingValuesSource.java index ff6900b4d2fc5..4208a7aca8e92 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/RoundingValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/RoundingValuesSource.java @@ -9,13 +9,12 @@ package org.elasticsearch.search.aggregations.bucket.composite; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.Rounding; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.aggregations.support.ValuesSource; import java.io.IOException; @@ -56,14 +55,14 @@ public double roundingSize(Rounding.DateTimeUnit unit) { } @Override - public SortedNumericDocValues longValues(LeafReaderContext context) throws IOException { - final SortedNumericDocValues values = vs.longValues(context); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); - return singleton != null ? DocValues.singleton(longSingleValues(singleton)) : longMultiValues(values); + public SortedNumericLongValues longValues(LeafReaderContext context) throws IOException { + final SortedNumericLongValues values = vs.longValues(context); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); + return singleton != null ? SortedNumericLongValues.singleton(longSingleValues(singleton)) : longMultiValues(values); } - private SortedNumericDocValues longMultiValues(SortedNumericDocValues values) { - return new SortedNumericDocValues() { + private SortedNumericLongValues longMultiValues(SortedNumericLongValues values) { + return new SortedNumericLongValues() { @Override public long nextValue() throws IOException { return round(values.nextValue()); @@ -78,31 +77,11 @@ public int docValueCount() { public boolean advanceExact(int target) throws IOException { return values.advanceExact(target); } - - @Override - public int docID() { - return values.docID(); - } - - @Override - public int nextDoc() throws IOException { - return values.nextDoc(); - } - - @Override - public int advance(int target) throws IOException { - return values.advance(target); - } - - @Override - public long cost() { - return values.cost(); - } }; } - private NumericDocValues longSingleValues(NumericDocValues values) { - return new NumericDocValues() { + private LongValues longSingleValues(LongValues values) { + return new LongValues() { @Override public long longValue() throws IOException { return round(values.longValue()); @@ -112,26 +91,6 @@ public long longValue() throws IOException { public boolean advanceExact(int target) throws IOException { return values.advanceExact(target); } - - @Override - public int docID() { - return values.docID(); - } - - @Override - public int nextDoc() throws IOException { - return values.nextDoc(); - } - - @Override - public int advance(int target) throws IOException { - return values.advance(target); - } - - @Override - public long cost() { - return values.cost(); - } }; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/CellIdSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/CellIdSource.java index 9a1256a0c1f58..9fc8c2df42760 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/CellIdSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/CellIdSource.java @@ -9,17 +9,15 @@ package org.elasticsearch.search.aggregations.bucket.geogrid; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.geo.GeoBoundingBox; -import org.elasticsearch.index.fielddata.AbstractNumericDocValues; -import org.elasticsearch.index.fielddata.AbstractSortingNumericDocValues; import org.elasticsearch.index.fielddata.GeoPointValues; import org.elasticsearch.index.fielddata.MultiGeoPointValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; +import org.elasticsearch.index.fielddata.SortingNumericLongValues; import org.elasticsearch.search.aggregations.support.ValuesSource; import java.io.IOException; @@ -56,37 +54,39 @@ public final boolean isFloatingPoint() { } @Override - public final SortedNumericDocValues longValues(LeafReaderContext ctx) { + public final SortedNumericLongValues longValues(LeafReaderContext ctx) { final MultiGeoPointValues multiGeoPointValues = valuesSource.geoPointValues(ctx); final GeoPointValues values = org.elasticsearch.index.fielddata.FieldData.unwrapSingleton(multiGeoPointValues); if (geoBoundingBox.isUnbounded()) { - return values == null ? unboundedCellMultiValues(multiGeoPointValues) : DocValues.singleton(unboundedCellSingleValue(values)); + return values == null + ? unboundedCellMultiValues(multiGeoPointValues) + : SortedNumericLongValues.singleton(unboundedCellSingleValue(values)); } else { return values == null ? boundedCellMultiValues(multiGeoPointValues, geoBoundingBox) - : DocValues.singleton(boundedCellSingleValue(values, geoBoundingBox)); + : SortedNumericLongValues.singleton(boundedCellSingleValue(values, geoBoundingBox)); } } /** * Generate an unbounded iterator of grid-cells for singleton case. */ - protected abstract NumericDocValues unboundedCellSingleValue(GeoPointValues values); + protected abstract LongValues unboundedCellSingleValue(GeoPointValues values); /** * Generate a bounded iterator of grid-cells for singleton case. */ - protected abstract NumericDocValues boundedCellSingleValue(GeoPointValues values, GeoBoundingBox boundingBox); + protected abstract LongValues boundedCellSingleValue(GeoPointValues values, GeoBoundingBox boundingBox); /** * Generate an unbounded iterator of grid-cells for multi-value case. */ - protected abstract SortedNumericDocValues unboundedCellMultiValues(MultiGeoPointValues values); + protected abstract SortedNumericLongValues unboundedCellMultiValues(MultiGeoPointValues values); /** * Generate a bounded iterator of grid-cells for multi-value case. */ - protected abstract SortedNumericDocValues boundedCellMultiValues(MultiGeoPointValues values, GeoBoundingBox boundingBox); + protected abstract SortedNumericLongValues boundedCellMultiValues(MultiGeoPointValues values, GeoBoundingBox boundingBox); @Override public final SortedNumericDoubleValues doubleValues(LeafReaderContext ctx) { @@ -120,7 +120,7 @@ protected boolean pointInBounds(double lon, double lat) { * the multi-value geo-doc-values. Class must encode the values and then * sort them in order to account for the cells correctly. */ - protected abstract static class CellMultiValues extends AbstractSortingNumericDocValues { + protected abstract static class CellMultiValues extends SortingNumericLongValues { private final MultiGeoPointValues geoValues; protected final int precision; @@ -162,7 +162,7 @@ public boolean advanceExact(int docId) throws IOException { * Class representing the long-encoded grid-cells belonging to * the singleton geo-doc-values. */ - protected abstract static class CellSingleValue extends AbstractNumericDocValues { + protected abstract static class CellSingleValue extends LongValues { private final GeoPointValues geoValues; protected final int precision; protected long value; @@ -191,10 +191,5 @@ public long longValue() throws IOException { * @return true if the value needs to be added, otherwise false. */ protected abstract boolean advance(org.elasticsearch.common.geo.GeoPoint target); - - @Override - public int docID() { - return -1; - } } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregator.java index b84dff6e73e0b..8259aa40c0346 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregator.java @@ -8,14 +8,13 @@ */ package org.elasticsearch.search.aggregations.bucket.geogrid; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.ObjectArray; import org.elasticsearch.core.Releasables; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.aggregations.AggregationExecutionContext; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; @@ -77,12 +76,12 @@ public ScoreMode scoreMode() { @Override public LeafBucketCollector getLeafCollector(final AggregationExecutionContext aggCtx, final LeafBucketCollector sub) throws IOException { - final SortedNumericDocValues values = valuesSource.longValues(aggCtx.getLeafReaderContext()); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = valuesSource.longValues(aggCtx.getLeafReaderContext()); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); return singleton != null ? getLeafCollector(singleton, sub) : getLeafCollector(values, sub); } - private LeafBucketCollector getLeafCollector(final NumericDocValues values, final LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(final LongValues values, final LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, null) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -100,7 +99,7 @@ public void collect(int doc, long owningBucketOrd) throws IOException { }; } - private LeafBucketCollector getLeafCollector(final SortedNumericDocValues values, final LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(final SortedNumericLongValues values, final LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, null) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashCellIdSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashCellIdSource.java index ddb6e5671f013..6c4cbd356703f 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashCellIdSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashCellIdSource.java @@ -8,12 +8,12 @@ */ package org.elasticsearch.search.aggregations.bucket.geogrid; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.geo.GeoBoundingBox; import org.elasticsearch.geometry.utils.Geohash; import org.elasticsearch.index.fielddata.GeoPointValues; import org.elasticsearch.index.fielddata.MultiGeoPointValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.aggregations.support.ValuesSource; import java.util.function.LongConsumer; @@ -33,7 +33,7 @@ public GeoHashCellIdSource( } @Override - protected NumericDocValues unboundedCellSingleValue(GeoPointValues values) { + protected LongValues unboundedCellSingleValue(GeoPointValues values) { return new CellSingleValue(values, precision()) { @Override protected boolean advance(org.elasticsearch.common.geo.GeoPoint target) { @@ -44,7 +44,7 @@ protected boolean advance(org.elasticsearch.common.geo.GeoPoint target) { } @Override - protected NumericDocValues boundedCellSingleValue(GeoPointValues values, GeoBoundingBox boundingBox) { + protected LongValues boundedCellSingleValue(GeoPointValues values, GeoBoundingBox boundingBox) { final GeoHashBoundedPredicate predicate = new GeoHashBoundedPredicate(precision(), boundingBox); return new CellSingleValue(values, precision()) { @Override @@ -60,7 +60,7 @@ protected boolean advance(org.elasticsearch.common.geo.GeoPoint target) { } @Override - protected SortedNumericDocValues unboundedCellMultiValues(MultiGeoPointValues values) { + protected SortedNumericLongValues unboundedCellMultiValues(MultiGeoPointValues values) { return new CellMultiValues(values, precision(), circuitBreakerConsumer) { @Override protected int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx) { @@ -71,7 +71,7 @@ protected int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int val } @Override - protected SortedNumericDocValues boundedCellMultiValues(MultiGeoPointValues values, GeoBoundingBox boundingBox) { + protected SortedNumericLongValues boundedCellMultiValues(MultiGeoPointValues values, GeoBoundingBox boundingBox) { final GeoHashBoundedPredicate predicate = new GeoHashBoundedPredicate(precision(), boundingBox); return new CellMultiValues(values, precision(), circuitBreakerConsumer) { @Override diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileCellIdSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileCellIdSource.java index 5b63841a5b286..214c9acde6903 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileCellIdSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileCellIdSource.java @@ -8,11 +8,11 @@ */ package org.elasticsearch.search.aggregations.bucket.geogrid; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.geo.GeoBoundingBox; import org.elasticsearch.index.fielddata.GeoPointValues; import org.elasticsearch.index.fielddata.MultiGeoPointValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.util.function.LongConsumer; @@ -26,7 +26,7 @@ public GeoTileCellIdSource(GeoPoint valuesSource, int precision, GeoBoundingBox } @Override - protected NumericDocValues unboundedCellSingleValue(GeoPointValues values) { + protected LongValues unboundedCellSingleValue(GeoPointValues values) { return new CellSingleValue(values, precision()) { @Override protected boolean advance(org.elasticsearch.common.geo.GeoPoint target) { @@ -37,7 +37,7 @@ protected boolean advance(org.elasticsearch.common.geo.GeoPoint target) { } @Override - protected NumericDocValues boundedCellSingleValue(GeoPointValues values, GeoBoundingBox boundingBox) { + protected LongValues boundedCellSingleValue(GeoPointValues values, GeoBoundingBox boundingBox) { final GeoTileBoundedPredicate predicate = new GeoTileBoundedPredicate(precision(), boundingBox); final int tiles = 1 << precision(); return new CellSingleValue(values, precision()) { @@ -55,7 +55,7 @@ protected boolean advance(org.elasticsearch.common.geo.GeoPoint target) { } @Override - protected SortedNumericDocValues unboundedCellMultiValues(MultiGeoPointValues values) { + protected SortedNumericLongValues unboundedCellMultiValues(MultiGeoPointValues values) { return new CellMultiValues(values, precision(), circuitBreakerConsumer) { @Override protected int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx) { @@ -66,7 +66,7 @@ protected int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int val } @Override - protected SortedNumericDocValues boundedCellMultiValues(MultiGeoPointValues values, GeoBoundingBox boundingBox) { + protected SortedNumericLongValues boundedCellMultiValues(MultiGeoPointValues values, GeoBoundingBox boundingBox) { final GeoTileBoundedPredicate predicate = new GeoTileBoundedPredicate(precision(), boundingBox); final int tiles = 1 << precision(); return new CellMultiValues(values, precision(), circuitBreakerConsumer) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java index 1eb0226ad8c8c..5b9febac9a452 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java @@ -10,9 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.common.Rounding; @@ -21,6 +19,7 @@ import org.elasticsearch.core.CheckedFunction; import org.elasticsearch.core.Nullable; import org.elasticsearch.core.Releasables; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AdaptingAggregator; import org.elasticsearch.search.aggregations.AggregationExecutionContext; @@ -289,12 +288,12 @@ public LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx, if (valuesSource == null) { return LeafBucketCollector.NO_OP_COLLECTOR; } - final SortedNumericDocValues values = valuesSource.longValues(aggCtx.getLeafReaderContext()); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = valuesSource.longValues(aggCtx.getLeafReaderContext()); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); return singleton != null ? getLeafCollector(singleton, sub) : getLeafCollector(values, sub); } - private LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(SortedNumericLongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -314,7 +313,7 @@ public void collect(int doc, long owningBucketOrd) throws IOException { }; } - private LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(LongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java index 4972fd19688c4..ac66e6e19adfb 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java @@ -10,7 +10,6 @@ package org.elasticsearch.search.aggregations.bucket.range; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoUtils; @@ -18,6 +17,7 @@ import org.elasticsearch.index.fielddata.MultiGeoPointValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; @@ -159,7 +159,7 @@ public boolean isFloatingPoint() { } @Override - public SortedNumericDocValues longValues(LeafReaderContext ctx) { + public SortedNumericLongValues longValues(LeafReaderContext ctx) { throw new UnsupportedOperationException(); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedNumericSamplerAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedNumericSamplerAggregator.java index c8805452b7334..c1b3b893fe4bf 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedNumericSamplerAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedNumericSamplerAggregator.java @@ -11,11 +11,11 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.misc.search.DiversifiedTopDocsCollector; import org.apache.lucene.search.TopDocsCollector; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.index.fielddata.AbstractNumericDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.bucket.DeferringBucketCollector; @@ -82,7 +82,7 @@ protected long getPriorityQueueSlotSize() { // a lookup from elasticsearch's ValuesSource class ValuesDiversifiedTopDocsCollector extends DiversifiedTopDocsCollector { - private SortedNumericDocValues values; + private SortedNumericLongValues values; ValuesDiversifiedTopDocsCollector(int numHits, int maxHitsPerKey) { super(numHits, maxHitsPerKey); @@ -111,7 +111,8 @@ public boolean advanceExact(int target) throws IOException { @Override public int docID() { - return values.docID(); + // TODO this can actually be a LongValues in the lucene class + throw new UnsupportedOperationException(); } @Override diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongRareTermsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongRareTermsAggregator.java index 45ea1245ec38d..eaa7ed5955b69 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongRareTermsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongRareTermsAggregator.java @@ -8,15 +8,14 @@ */ package org.elasticsearch.search.aggregations.bucket.terms; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.LongHash; import org.elasticsearch.common.util.ObjectArray; import org.elasticsearch.common.util.SetBackedScalingCuckooFilter; import org.elasticsearch.core.Releasables; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregationExecutionContext; import org.elasticsearch.search.aggregations.Aggregator; @@ -65,18 +64,18 @@ public class LongRareTermsAggregator extends AbstractRareTermsAggregator { this.bucketOrds = LongKeyedBucketOrds.build(bigArrays(), cardinality); } - protected static SortedNumericDocValues getValues(ValuesSource.Numeric valuesSource, LeafReaderContext ctx) throws IOException { + protected static SortedNumericLongValues getValues(ValuesSource.Numeric valuesSource, LeafReaderContext ctx) throws IOException { return valuesSource.longValues(ctx); } @Override public LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx, LeafBucketCollector sub) throws IOException { - final SortedNumericDocValues values = getValues(valuesSource, aggCtx.getLeafReaderContext()); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = getValues(valuesSource, aggCtx.getLeafReaderContext()); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); return singleton != null ? getLeafCollector(singleton, sub) : getLeafCollector(values, sub); } - private LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(SortedNumericLongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int docId, long owningBucketOrd) throws IOException { @@ -95,7 +94,7 @@ public void collect(int docId, long owningBucketOrd) throws IOException { }; } - private LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(LongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int docId, long owningBucketOrd) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/NumericTermsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/NumericTermsAggregator.java index a54053f712f8d..3bee48b6ede3a 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/NumericTermsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/NumericTermsAggregator.java @@ -8,10 +8,8 @@ */ package org.elasticsearch.search.aggregations.bucket.terms; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.common.util.IntArray; @@ -21,6 +19,7 @@ import org.elasticsearch.core.Releasable; import org.elasticsearch.core.Releasables; import org.elasticsearch.index.fielddata.FieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregationExecutionContext; import org.elasticsearch.search.aggregations.Aggregator; @@ -90,12 +89,12 @@ public ScoreMode scoreMode() { @Override public LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx, LeafBucketCollector sub) throws IOException { - final SortedNumericDocValues values = resultStrategy.getValues(aggCtx.getLeafReaderContext()); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = resultStrategy.getValues(aggCtx.getLeafReaderContext()); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); return resultStrategy.wrapCollector(singleton != null ? getLeafCollector(singleton, sub) : getLeafCollector(values, sub)); } - private LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(SortedNumericLongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -113,7 +112,7 @@ public void collect(int doc, long owningBucketOrd) throws IOException { }; } - private LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(LongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -235,7 +234,7 @@ private InternalAggregation[] buildAggregations(LongArray owningBucketOrds) thro /** * Resolve the doc values to collect results of this type. */ - abstract SortedNumericDocValues getValues(LeafReaderContext ctx) throws IOException; + abstract SortedNumericLongValues getValues(LeafReaderContext ctx) throws IOException; /** * Wrap the "standard" numeric terms collector to collect any more @@ -335,7 +334,7 @@ final void collectZeroDocEntriesIfNeeded(long owningBucketOrd, boolean excludeDe } // we need to fill-in the blanks for (LeafReaderContext ctx : searcher().getTopReaderContext().leaves()) { - SortedNumericDocValues values = getValues(ctx); + SortedNumericLongValues values = getValues(ctx); for (int docId = 0; docId < ctx.reader().maxDoc(); ++docId) { if (excludeDeletedDocs && ctx.reader().getLiveDocs() != null && ctx.reader().getLiveDocs().get(docId) == false) { continue; @@ -368,7 +367,7 @@ String describe() { } @Override - SortedNumericDocValues getValues(LeafReaderContext ctx) throws IOException { + SortedNumericLongValues getValues(LeafReaderContext ctx) throws IOException { return valuesSource.longValues(ctx); } @@ -451,7 +450,7 @@ String describe() { } @Override - SortedNumericDocValues getValues(LeafReaderContext ctx) throws IOException { + SortedNumericLongValues getValues(LeafReaderContext ctx) throws IOException { return FieldData.toSortableLongBits(valuesSource.doubleValues(ctx)); } @@ -548,7 +547,7 @@ class SignificantLongTermsResults extends ResultStrategy"narrowed" * but they'll accurately represent values up to {@link Long#MAX_VALUE}. */ - public abstract SortedNumericDocValues longValues(LeafReaderContext context) throws IOException; + public abstract SortedNumericLongValues longValues(LeafReaderContext context) throws IOException; /** * Get a double precision floating point view into the values in this leaf. @@ -482,7 +483,7 @@ public DocValueBits docsWithValue(LeafReaderContext context) throws IOException final SortedNumericDoubleValues values = doubleValues(context); return org.elasticsearch.index.fielddata.FieldData.docsWithValue(values); } else { - final SortedNumericDocValues values = longValues(context); + final SortedNumericLongValues values = longValues(context); return org.elasticsearch.index.fielddata.FieldData.docsWithValue(values); } } @@ -521,7 +522,7 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext context) throws IOExc } @Override - public SortedNumericDocValues longValues(LeafReaderContext context) throws IOException { + public SortedNumericLongValues longValues(LeafReaderContext context) throws IOException { return new LongValues(delegate.longValues(context), script.newInstance(context)); } @@ -530,12 +531,12 @@ public SortedNumericDoubleValues doubleValues(LeafReaderContext context) throws return new DoubleValues(delegate.doubleValues(context), script.newInstance(context)); } - static class LongValues extends AbstractSortingNumericDocValues implements ScorerAware { + static class LongValues extends SortingNumericLongValues implements ScorerAware { - private final SortedNumericDocValues longValues; + private final SortedNumericLongValues longValues; private final AggregationScript script; - LongValues(SortedNumericDocValues values, AggregationScript script) { + LongValues(SortedNumericLongValues values, AggregationScript script) { this.longValues = values; this.script = script; } @@ -612,7 +613,7 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext context) { } @Override - public SortedNumericDocValues longValues(LeafReaderContext context) { + public SortedNumericLongValues longValues(LeafReaderContext context) { return indexFieldData.load(context).getLongValues(); } @@ -640,7 +641,7 @@ public boolean isFloatingPoint() { } @Override - public SortedNumericDocValues longValues(LeafReaderContext context) throws IOException { + public SortedNumericLongValues longValues(LeafReaderContext context) throws IOException { return new ScriptLongValues(script.newInstance(context)); } @@ -705,8 +706,8 @@ public abstract static class GeoPoint extends ValuesSource { public static final GeoPoint EMPTY = new GeoPoint() { @Override - public SortedNumericDocValues geoSortedNumericDocValues(LeafReaderContext context) { - return DocValues.emptySortedNumeric(); + public SortedNumericLongValues geoSortedNumericDocValues(LeafReaderContext context) { + return SortedNumericLongValues.EMPTY; } @Override @@ -739,7 +740,7 @@ public final MultiGeoPointValues geoPointValues(LeafReaderContext context) { * A point is encoded as a long that can be decoded by using * {@link org.elasticsearch.common.geo.GeoPoint#resetFromEncoded(long)} */ - public abstract SortedNumericDocValues geoSortedNumericDocValues(LeafReaderContext context); + public abstract SortedNumericLongValues geoSortedNumericDocValues(LeafReaderContext context); public static class Fielddata extends GeoPoint { @@ -755,8 +756,8 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext context) { } @Override - public SortedNumericDocValues geoSortedNumericDocValues(LeafReaderContext context) { - return indexFieldData.load(context).getSortedNumericDocValues(); + public SortedNumericLongValues geoSortedNumericDocValues(LeafReaderContext context) { + return indexFieldData.load(context).getSortedNumericLongValues(); } } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java index 38891365dfdc2..b9b8d81d38469 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java @@ -11,7 +11,7 @@ import org.apache.lucene.search.Scorable; import org.apache.lucene.util.LongValues; import org.elasticsearch.common.lucene.ScorerAware; -import org.elasticsearch.index.fielddata.AbstractSortingNumericDocValues; +import org.elasticsearch.index.fielddata.SortingNumericLongValues; import org.elasticsearch.script.AggregationScript; import org.elasticsearch.search.aggregations.AggregationErrors; @@ -24,7 +24,7 @@ /** * {@link LongValues} implementation which is based on a script */ -public class ScriptLongValues extends AbstractSortingNumericDocValues implements ScorerAware { +public class ScriptLongValues extends SortingNumericLongValues implements ScorerAware { final AggregationScript script; diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/FieldDataTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/FieldDataTests.java index 94b5f2b054f48..fba9003709d98 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/FieldDataTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/FieldDataTests.java @@ -9,9 +9,7 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.test.ESTestCase; @@ -19,10 +17,9 @@ public class FieldDataTests extends ESTestCase { - private static class DummyValues extends AbstractNumericDocValues { + private static class DummyValues extends LongValues { private final long value; - private int docID = -1; DummyValues(long value) { this.value = value; @@ -30,15 +27,9 @@ private static class DummyValues extends AbstractNumericDocValues { @Override public boolean advanceExact(int target) throws IOException { - docID = target; return true; } - @Override - public int docID() { - return docID; - } - @Override public long longValue() throws IOException { return value; @@ -49,23 +40,23 @@ public void testSortableLongBitsToDoubles() throws IOException { final double value = randomDouble(); final long valueBits = NumericUtils.doubleToSortableLong(value); - NumericDocValues values = new DummyValues(valueBits); + LongValues values = new DummyValues(valueBits); - SortedNumericDoubleValues asMultiDoubles = FieldData.sortableLongBitsToDoubles(DocValues.singleton(values)); + SortedNumericDoubleValues asMultiDoubles = FieldData.sortableLongBitsToDoubles(SortedNumericLongValues.singleton(values)); NumericDoubleValues asDoubles = FieldData.unwrapSingleton(asMultiDoubles); assertNotNull(asDoubles); assertTrue(asDoubles.advanceExact(0)); assertEquals(value, asDoubles.doubleValue(), 0); values = new DummyValues(valueBits); - asMultiDoubles = FieldData.sortableLongBitsToDoubles(DocValues.singleton(values)); - NumericDocValues backToLongs = DocValues.unwrapSingleton(FieldData.toSortableLongBits(asMultiDoubles)); + asMultiDoubles = FieldData.sortableLongBitsToDoubles(SortedNumericLongValues.singleton(values)); + LongValues backToLongs = SortedNumericLongValues.unwrapSingleton(FieldData.toSortableLongBits(asMultiDoubles)); assertSame(values, backToLongs); - SortedNumericDocValues multiValues = new AbstractSortedNumericDocValues() { + SortedNumericLongValues multiValues = new SortedNumericLongValues() { @Override - public boolean advanceExact(int target) throws IOException { + public boolean advanceExact(int target) { return true; } @@ -101,8 +92,8 @@ public double doubleValue() { } }; - SortedNumericDocValues asMultiLongs = FieldData.toSortableLongBits(FieldData.singleton(values)); - NumericDocValues asLongs = DocValues.unwrapSingleton(asMultiLongs); + SortedNumericLongValues asMultiLongs = FieldData.toSortableLongBits(FieldData.singleton(values)); + LongValues asLongs = SortedNumericLongValues.unwrapSingleton(asMultiLongs); assertNotNull(asLongs); assertTrue(asLongs.advanceExact(0)); assertEquals(valueBits, asLongs.longValue()); @@ -129,16 +120,11 @@ public int docValueCount() { assertSame(multiValues, FieldData.sortableLongBitsToDoubles(asMultiLongs)); } - private static NumericDocValues asNumericDocValues(Long... values) { - return new AbstractNumericDocValues() { + private static LongValues asNumericDocValues(Long... values) { + return new LongValues() { int docID = -1; - @Override - public int docID() { - return docID; - } - @Override public boolean advanceExact(int target) throws IOException { docID = target; @@ -153,8 +139,8 @@ public long longValue() throws IOException { } public void testReplaceMissingLongs() throws IOException { - final NumericDocValues values = asNumericDocValues(null, 3L, 2L, null, 5L, null); - final NumericDocValues replaced = FieldData.replaceMissing(values, 4); + final LongValues values = asNumericDocValues(null, 3L, 2L, null, 5L, null); + final LongValues replaced = FieldData.replaceMissing(values, 4); assertTrue(replaced.advanceExact(0)); assertEquals(4L, replaced.longValue()); diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/IntegralDocValuesFieldTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/IntegralDocValuesFieldTests.java index 45a9146a454e1..50b14361f184f 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/IntegralDocValuesFieldTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/IntegralDocValuesFieldTests.java @@ -92,8 +92,8 @@ protected long[][] generate(LongSupplier supplier) { return values; } - protected AbstractSortedNumericDocValues wrap(long[][] values) { - return new AbstractSortedNumericDocValues() { + protected SortedNumericLongValues wrap(long[][] values) { + return new SortedNumericLongValues() { long[] current; int i; diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesGeoPointsTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesGeoPointsTests.java index 32289eb86b935..4f8c428c84252 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesGeoPointsTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesGeoPointsTests.java @@ -22,7 +22,7 @@ public class ScriptDocValuesGeoPointsTests extends ESTestCase { private static MultiGeoPointValues wrap(GeoPoint[][] points) { - return new MultiGeoPointValues(new AbstractSortedNumericDocValues() { + return new MultiGeoPointValues(new SortedNumericLongValues() { GeoPoint[] current; int i; diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesLongsTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesLongsTests.java index fbb8e8740da1a..1ff51cd2102e3 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesLongsTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesLongsTests.java @@ -65,7 +65,7 @@ public void testLongs() throws IOException { } private LongDocValuesField wrap(long[][] values) { - return new LongDocValuesField(new AbstractSortedNumericDocValues() { + return new LongDocValuesField(new SortedNumericLongValues() { long[] current; int i; diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericDocValuesTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericLongValuesTests.java similarity index 77% rename from server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericDocValuesTests.java rename to server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericLongValuesTests.java index 86a17d00d644f..90a09768bb750 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericDocValuesTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericLongValuesTests.java @@ -16,7 +16,7 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.function.LongConsumer; -public class SortingNumericDocValuesTests extends ESTestCase { +public class SortingNumericLongValuesTests extends ESTestCase { public void testResize() { final int oldSize = Integer.MAX_VALUE - 200; @@ -28,7 +28,7 @@ public void testResize() { long total = counter.addAndGet(value); assertThat(total, Matchers.greaterThanOrEqualTo(0L)); }; - SortingNumericDocValues docValues = new SortingNumericDocValues(consumer) { + SortingNumericLongValues docValues = new SortingNumericLongValues(consumer) { @Override protected void growExact(int newValuesLength) { @@ -44,26 +44,6 @@ protected int getArrayLength() { public boolean advanceExact(int target) { return false; } - - @Override - public int docID() { - return 0; - } - - @Override - public int nextDoc() { - return 0; - } - - @Override - public int advance(int target) { - return 0; - } - - @Override - public long cost() { - return 0; - } }; docValues.resize(newSize); final long diff = ArrayUtil.oversize(newSize, Long.BYTES) - oldSize; diff --git a/server/src/test/java/org/elasticsearch/index/mapper/BooleanScriptFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/BooleanScriptFieldTypeTests.java index 97cc3a5aa4ae1..a077767166ae8 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/BooleanScriptFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/BooleanScriptFieldTypeTests.java @@ -13,7 +13,6 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NoMergePolicy; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.StoredFields; import org.apache.lucene.search.Collector; import org.apache.lucene.search.IndexSearcher; @@ -36,6 +35,7 @@ import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.fielddata.BooleanScriptFieldData; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.script.BooleanFieldScript; import org.elasticsearch.script.DocReader; @@ -99,7 +99,7 @@ public ScoreMode scoreMode() { @Override public LeafCollector getLeafCollector(LeafReaderContext context) { - SortedNumericDocValues dv = ifd.load(context).getLongValues(); + SortedNumericLongValues dv = ifd.load(context).getLongValues(); return new LeafCollector() { @Override public void setScorer(Scorable scorer) {} diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java index a0501908a267f..2bc6d1a7786e6 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java @@ -17,8 +17,6 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.MultiReader; -import org.apache.lucene.index.SortedNumericDocValues; -import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexOrDocValuesQuery; import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery; import org.apache.lucene.search.Query; @@ -34,6 +32,7 @@ import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.fielddata.LeafNumericFieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData; import org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType; import org.elasticsearch.index.mapper.DateFieldMapper.Resolution; @@ -527,10 +526,9 @@ public void testDateNanoDocValues() throws IOException { DirectoryReader reader = DirectoryReader.open(w); assertTrue(reader.leaves().size() > 0); LeafNumericFieldData a = fieldData.load(reader.leaves().get(0).reader().getContext()); - SortedNumericDocValues docValues = a.getLongValues(); - assertEquals(0, docValues.nextDoc()); - assertEquals(1, docValues.nextDoc()); - assertEquals(DocIdSetIterator.NO_MORE_DOCS, docValues.nextDoc()); + SortedNumericLongValues docValues = a.getLongValues(); + assertTrue(docValues.advanceExact(0)); + assertTrue(docValues.advanceExact(1)); reader.close(); w.close(); dir.close(); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DateScriptFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DateScriptFieldTypeTests.java index 987a33636b24a..e28de22b819e6 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DateScriptFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DateScriptFieldTypeTests.java @@ -13,7 +13,6 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NoMergePolicy; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.Collector; import org.apache.lucene.search.Explanation; import org.apache.lucene.search.FieldDoc; @@ -40,6 +39,7 @@ import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.fielddata.DateScriptFieldData; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.script.DateFieldScript; import org.elasticsearch.script.DocReader; @@ -183,7 +183,7 @@ public ScoreMode scoreMode() { @Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { - SortedNumericDocValues dv = ifd.load(context).getLongValues(); + SortedNumericLongValues dv = ifd.load(context).getLongValues(); return new LeafCollector() { @Override public void setScorer(Scorable scorer) throws IOException {} diff --git a/server/src/test/java/org/elasticsearch/index/mapper/LongScriptFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/LongScriptFieldTypeTests.java index 9ba910909f5b1..7b84cf804f9a9 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/LongScriptFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/LongScriptFieldTypeTests.java @@ -13,7 +13,6 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NoMergePolicy; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.StoredFields; import org.apache.lucene.search.Collector; import org.apache.lucene.search.FieldDoc; @@ -35,6 +34,7 @@ import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.fielddata.LongScriptFieldData; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.script.DocReader; import org.elasticsearch.script.LongFieldScript; @@ -105,7 +105,7 @@ public ScoreMode scoreMode() { @Override public LeafCollector getLeafCollector(LeafReaderContext context) { - SortedNumericDocValues dv = ifd.load(context).getLongValues(); + SortedNumericLongValues dv = ifd.load(context).getLongValues(); return new LeafCollector() { @Override public void setScorer(Scorable scorer) {} diff --git a/server/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreTests.java b/server/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreTests.java index 2fdfbcc9fee06..2f3964b46f569 100644 --- a/server/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreTests.java @@ -16,7 +16,6 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.Term; import org.apache.lucene.search.Explanation; import org.apache.lucene.search.IndexSearcher; @@ -49,6 +48,7 @@ import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.field.DocValuesScriptFieldFactory; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.MultiValueMode; @@ -182,7 +182,7 @@ public ValuesSourceType getValuesSourceType() { public LeafNumericFieldData load(LeafReaderContext context) { return new LeafNumericFieldData() { @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { throw new UnsupportedOperationException(UNSUPPORTED); } diff --git a/server/src/test/java/org/elasticsearch/search/MultiValueModeTests.java b/server/src/test/java/org/elasticsearch/search/MultiValueModeTests.java index 663b39d116913..9027a50ca5b87 100644 --- a/server/src/test/java/org/elasticsearch/search/MultiValueModeTests.java +++ b/server/src/test/java/org/elasticsearch/search/MultiValueModeTests.java @@ -11,24 +11,22 @@ import org.apache.lucene.index.BinaryDocValues; import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.SortedDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.BitSetIterator; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.FixedBitSet; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.fielddata.AbstractBinaryDocValues; -import org.elasticsearch.index.fielddata.AbstractNumericDocValues; import org.elasticsearch.index.fielddata.AbstractSortedDocValues; -import org.elasticsearch.index.fielddata.AbstractSortedNumericDocValues; import org.elasticsearch.index.fielddata.AbstractSortedSetDocValues; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.test.ESTestCase; import java.io.IOException; @@ -80,7 +78,7 @@ public void testSingleValuedLongs() throws Exception { } } - final Supplier multiValues = () -> DocValues.singleton(new AbstractNumericDocValues() { + final Supplier multiValues = () -> SortedNumericLongValues.singleton(new LongValues() { int docId = -1; @Override @@ -89,11 +87,6 @@ public boolean advanceExact(int target) throws IOException { return docsWithValue == null ? true : docsWithValue.get(docId); } - @Override - public int docID() { - return docId; - } - @Override public long longValue() { return array[docId]; @@ -117,7 +110,7 @@ public void testMultiValuedLongs() throws Exception { Arrays.sort(values); array[i] = values; } - final Supplier multiValues = () -> new AbstractSortedNumericDocValues() { + final Supplier multiValues = () -> new SortedNumericLongValues() { int doc; int i; @@ -145,10 +138,10 @@ public int docValueCount() { verifySortedNumeric(multiValues, numDocs, rootDocs, innerDocs, randomIntBetween(1, numDocs)); } - private void verifySortedNumeric(Supplier supplier, int maxDoc) throws IOException { + private void verifySortedNumeric(Supplier supplier, int maxDoc) throws IOException { for (MultiValueMode mode : MultiValueMode.values()) { - SortedNumericDocValues values = supplier.get(); - final NumericDocValues selected = mode.select(values); + SortedNumericLongValues values = supplier.get(); + final LongValues selected = mode.select(values); for (int i = 0; i < maxDoc; ++i) { Long actual = null; if (selected.advanceExact(i)) { @@ -198,14 +191,14 @@ private void verifySortedNumeric(Supplier supplier, int } } - private void verifyLongValueCanCalledMoreThanOnce(NumericDocValues values, long expected) throws IOException { + private void verifyLongValueCanCalledMoreThanOnce(LongValues values, long expected) throws IOException { for (int j = 0, numCall = randomIntBetween(1, 10); j < numCall; j++) { assertEquals(expected, values.longValue()); } } private void verifySortedNumeric( - Supplier supplier, + Supplier supplier, int maxDoc, FixedBitSet rootDocs, FixedBitSet innerDocs, @@ -217,14 +210,8 @@ private void verifySortedNumeric( MultiValueMode.MAX, MultiValueMode.SUM, MultiValueMode.AVG }) { - SortedNumericDocValues values = supplier.get(); - final NumericDocValues selected = mode.select( - values, - missingValue, - rootDocs, - new BitSetIterator(innerDocs, 0L), - maxChildren - ); + SortedNumericLongValues values = supplier.get(); + final LongValues selected = mode.select(values, missingValue, rootDocs, new BitSetIterator(innerDocs, 0L), maxChildren); int prevRoot = -1; for (int root = rootDocs.nextSetBit(0); root != -1; root = root + 1 < maxDoc ? rootDocs.nextSetBit(root + 1) : -1) { assertTrue(selected.advanceExact(root)); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesCollectorQueueTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesCollectorQueueTests.java index 505e4c09aba1a..ef14ec100467d 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesCollectorQueueTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesCollectorQueueTests.java @@ -51,6 +51,7 @@ import org.apache.lucene.util.NumericUtils; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.index.fielddata.FieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.KeywordFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.NumberFieldMapper; @@ -275,7 +276,7 @@ private void testRandomCase(boolean forceMerge, boolean missingBucket, int index sources[i] = new LongValuesSource( bigArrays, fieldType, - context -> DocValues.getSortedNumeric(context.reader(), fieldType.name()), + context -> SortedNumericLongValues.wrap(DocValues.getSortedNumeric(context.reader(), fieldType.name())), value -> value, DocValueFormat.RAW, missingBucket, @@ -287,7 +288,9 @@ private void testRandomCase(boolean forceMerge, boolean missingBucket, int index sources[i] = new DoubleValuesSource( bigArrays, fieldType, - context -> FieldData.sortableLongBitsToDoubles(DocValues.getSortedNumeric(context.reader(), fieldType.name())), + context -> FieldData.sortableLongBitsToDoubles( + SortedNumericLongValues.wrap(DocValues.getSortedNumeric(context.reader(), fieldType.name())) + ), DocValueFormat.RAW, missingBucket, MissingOrder.DEFAULT, diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/support/MissingValuesTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/support/MissingValuesTests.java index 2a36887cc459a..c3165d2fd4f5b 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/support/MissingValuesTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/support/MissingValuesTests.java @@ -12,14 +12,13 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.carrotsearch.randomizedtesting.generators.RandomStrings; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.tests.util.TestUtil; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.index.fielddata.AbstractSortedNumericDocValues; import org.elasticsearch.index.fielddata.AbstractSortedSetDocValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.test.ESTestCase; import java.io.IOException; @@ -254,7 +253,7 @@ public void testMissingLongs() throws IOException { } Arrays.sort(values[i]); } - SortedNumericDocValues asNumericValues = new AbstractSortedNumericDocValues() { + SortedNumericLongValues asNumericValues = new SortedNumericLongValues() { int doc = -1; int i; @@ -277,7 +276,7 @@ public int docValueCount() { } }; final long missing = randomInt(); - SortedNumericDocValues withMissingReplaced = MissingValues.replaceMissing(asNumericValues, missing); + SortedNumericLongValues withMissingReplaced = MissingValues.replaceMissing(asNumericValues, missing); for (int i = 0; i < numDocs; ++i) { assertTrue(withMissingReplaced.advanceExact(i)); if (values[i].length > 0) { diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java index 65a41aade2494..b908431189833 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java @@ -10,9 +10,9 @@ package org.elasticsearch.search.aggregations.support; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.BytesRef; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MapperServiceTestCase; import org.elasticsearch.script.AggregationScript; @@ -281,7 +281,7 @@ public void testLong() throws Exception { config = ValuesSourceConfig.resolve(context, null, "field", null, null, null, null, CoreValuesSourceType.KEYWORD); ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = context.searcher().getIndexReader().leaves().get(0); - SortedNumericDocValues values = valuesSource.longValues(ctx); + SortedNumericLongValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); assertEquals(42, values.nextValue()); @@ -296,7 +296,7 @@ public void testEmptyLong() throws Exception { config = ValuesSourceConfig.resolve(context, null, "field", null, null, null, null, CoreValuesSourceType.KEYWORD); ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = context.searcher().getIndexReader().leaves().get(0); - SortedNumericDocValues values = valuesSource.longValues(ctx); + SortedNumericLongValues values = valuesSource.longValues(ctx); assertFalse(values.advanceExact(0)); assertTrue(config.alignsWithSearchIndex()); @@ -323,7 +323,7 @@ public void testUnmappedLong() throws Exception { config = ValuesSourceConfig.resolve(context, ValueType.NUMBER, "field", null, 42, null, null, CoreValuesSourceType.KEYWORD); valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = context.searcher().getIndexReader().leaves().get(0); - SortedNumericDocValues values = valuesSource.longValues(ctx); + SortedNumericLongValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); assertEquals(42, values.nextValue()); @@ -338,7 +338,7 @@ public void testBoolean() throws Exception { config = ValuesSourceConfig.resolve(context, null, "field", null, null, null, null, CoreValuesSourceType.KEYWORD); ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = context.searcher().getIndexReader().leaves().get(0); - SortedNumericDocValues values = valuesSource.longValues(ctx); + SortedNumericLongValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); assertEquals(1, values.nextValue()); @@ -353,7 +353,7 @@ public void testEmptyBoolean() throws Exception { config = ValuesSourceConfig.resolve(context, null, "field", null, null, null, null, CoreValuesSourceType.KEYWORD); ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = context.searcher().getIndexReader().leaves().get(0); - SortedNumericDocValues values = valuesSource.longValues(ctx); + SortedNumericLongValues values = valuesSource.longValues(ctx); assertFalse(values.advanceExact(0)); assertTrue(config.alignsWithSearchIndex()); @@ -380,7 +380,7 @@ public void testUnmappedBoolean() throws Exception { config = ValuesSourceConfig.resolve(context, ValueType.BOOLEAN, "field", null, true, null, null, CoreValuesSourceType.KEYWORD); valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = context.searcher().getIndexReader().leaves().get(0); - SortedNumericDocValues values = valuesSource.longValues(ctx); + SortedNumericLongValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); assertEquals(1, values.nextValue()); diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/multiterms/MultiTermsAggregator.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/multiterms/MultiTermsAggregator.java index e2d3e300da69b..ebcfeb0b40f74 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/multiterms/MultiTermsAggregator.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/multiterms/MultiTermsAggregator.java @@ -8,10 +8,8 @@ package org.elasticsearch.xpack.analytics.multiterms; import org.apache.lucene.index.BinaryDocValues; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; @@ -29,6 +27,7 @@ import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregationExecutionContext; import org.elasticsearch.search.aggregations.Aggregator; @@ -393,12 +392,12 @@ static class LongTermValuesSource implements TermValuesSource { @Override public TermValues getValues(LeafReaderContext ctx) throws IOException { - final SortedNumericDocValues values = source.longValues(ctx); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = source.longValues(ctx); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); return singleton != null ? getValues(singleton) : getValues(values); } - public TermValues getValues(SortedNumericDocValues values) { + public TermValues getValues(SortedNumericLongValues values) { return doc -> { if (values.advanceExact(doc)) { final List objects = new ArrayList<>(); @@ -418,7 +417,7 @@ public TermValues getValues(SortedNumericDocValues values) { }; } - public TermValues getValues(NumericDocValues values) { + public TermValues getValues(LongValues values) { return doc -> { if (values.advanceExact(doc)) { return List.of(values.longValue()); diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java index 69b6e311e23ee..e30266ab58131 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java @@ -8,8 +8,8 @@ package org.elasticsearch.xpack.analytics.topmetrics; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.SortedSetDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.Scorable; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.BytesRef; @@ -379,7 +379,7 @@ public void swap(long lhs, long rhs) { @Override public Loader loader(LeafReaderContext ctx) throws IOException { // TODO allow configuration of value mode - NumericDocValues metricValues = MultiValueMode.AVG.select(valuesSource.longValues(ctx)); + LongValues metricValues = MultiValueMode.AVG.select(valuesSource.longValues(ctx)); return (index, doc) -> { if (false == metricValues.advanceExact(doc)) { empty.markMissing(index); diff --git a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorMetricsTests.java b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorMetricsTests.java index 0ab41367b6d50..92b03c6a01218 100644 --- a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorMetricsTests.java +++ b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorMetricsTests.java @@ -7,13 +7,13 @@ package org.elasticsearch.xpack.analytics.topmetrics; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.core.CheckedConsumer; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; @@ -76,7 +76,7 @@ private void assertNoValues(ValuesSourceConfig config) throws IOException { } public void testEmptyLong() throws IOException { - SortedNumericDocValues values = mock(SortedNumericDocValues.class); + SortedNumericLongValues values = mock(SortedNumericLongValues.class); when(values.advanceExact(0)).thenReturn(false); ValuesSourceConfig config = toConfig(values); withMetric(config, m -> { @@ -97,7 +97,7 @@ public void testEmptyDouble() throws IOException { public void testLoadLong() throws IOException { long value = randomLong(); - SortedNumericDocValues values = mock(SortedNumericDocValues.class); + SortedNumericLongValues values = mock(SortedNumericLongValues.class); when(values.advanceExact(0)).thenReturn(true); when(values.docValueCount()).thenReturn(1); when(values.nextValue()).thenReturn(value); @@ -138,7 +138,7 @@ public void testLoadString() throws IOException { public void testLoadAndSwapLong() throws IOException { long firstValue = randomLong(); long secondValue = randomLong(); - SortedNumericDocValues values = mock(SortedNumericDocValues.class); + SortedNumericLongValues values = mock(SortedNumericLongValues.class); when(values.advanceExact(0)).thenReturn(true); when(values.advanceExact(1)).thenReturn(true); when(values.docValueCount()).thenReturn(1); @@ -177,7 +177,7 @@ public void testManyValues() throws IOException { long[] values = IntStream.range(0, between(2, 100)).mapToLong(i -> randomLong()).toArray(); List configs = Arrays.stream(values).mapToObj(v -> { try { - SortedNumericDocValues docValues = mock(SortedNumericDocValues.class); + SortedNumericLongValues docValues = mock(SortedNumericLongValues.class); when(docValues.advanceExact(0)).thenReturn(true); when(docValues.docValueCount()).thenReturn(1); when(docValues.nextValue()).thenReturn(v); @@ -198,7 +198,7 @@ public void testManyValues() throws IOException { }); } - private ValuesSourceConfig toConfig(SortedNumericDocValues values) throws IOException { + private ValuesSourceConfig toConfig(SortedNumericLongValues values) throws IOException { ValuesSource.Numeric source = mock(ValuesSource.Numeric.class); when(source.isFloatingPoint()).thenReturn(false); when(source.longValues(null)).thenReturn(values); diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMaxFactory.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMaxFactory.java index 7e0003efaf669..c9a30d6bfbd6b 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMaxFactory.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMaxFactory.java @@ -7,15 +7,16 @@ package org.elasticsearch.compute.lucene; -import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.PointValues; import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.compute.operator.SourceOperator; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.MultiValueMode; import java.io.IOException; @@ -93,8 +94,8 @@ long bytesToLong(byte[] bytes) { } }; - public final NumericDocValues multiValueMode(SortedNumericDocValues sortedNumericDocValues) { - return MultiValueMode.MAX.select(sortedNumericDocValues); + public final LongValues multiValueMode(SortedNumericDocValues sortedNumericDocValues) { + return MultiValueMode.MAX.select(SortedNumericLongValues.wrap(sortedNumericDocValues)); } public final long fromPointValues(PointValues pointValues) throws IOException { diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinFactory.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinFactory.java index 000ade1b19562..685cc334ae34e 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinFactory.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinFactory.java @@ -7,9 +7,9 @@ package org.elasticsearch.compute.lucene; -import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.PointValues; import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.compute.data.Block; @@ -17,6 +17,7 @@ import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.compute.operator.SourceOperator; import org.elasticsearch.core.RefCounted; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.MultiValueMode; import java.io.IOException; @@ -94,8 +95,8 @@ long bytesToLong(byte[] bytes) { } }; - public final NumericDocValues multiValueMode(SortedNumericDocValues sortedNumericDocValues) { - return MultiValueMode.MIN.select(sortedNumericDocValues); + public final LongValues multiValueMode(SortedNumericDocValues sortedNumericDocValues) { + return MultiValueMode.MIN.select(SortedNumericLongValues.wrap(sortedNumericDocValues)); } public final long fromPointValues(PointValues pointValues) throws IOException { diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinMaxOperator.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinMaxOperator.java index b9e05567411fc..a9af408199aec 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinMaxOperator.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinMaxOperator.java @@ -8,10 +8,10 @@ package org.elasticsearch.compute.lucene; import org.apache.lucene.index.LeafReader; -import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.PointValues; import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.LeafCollector; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.Scorable; @@ -44,7 +44,7 @@ sealed interface NumberType permits LuceneMinFactory.NumberType, LuceneMaxFactor long fromPointValues(PointValues pointValues) throws IOException; /** Wraps the provided {@link SortedNumericDocValues} with a {@link MultiValueMode} */ - NumericDocValues multiValueMode(SortedNumericDocValues sortedNumericDocValues); + LongValues multiValueMode(SortedNumericDocValues sortedNumericDocValues); /** Return the competitive value between {@code value1} and {@code value2} */ long evaluate(long value1, long value2); @@ -135,7 +135,7 @@ public Page getCheckedOutput() throws IOException { } if (scorer.isDone() == false) { // could not apply shortcut, trigger the search - final NumericDocValues values = numberType.multiValueMode(reader.getSortedNumericDocValues(fieldName)); + final LongValues values = numberType.multiValueMode(reader.getSortedNumericDocValues(fieldName)); final LeafCollector leafCollector = new LeafCollector() { @Override public void setScorer(Scorable scorer) {} diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/querydsl/query/SingleValueMatchQuery.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/querydsl/query/SingleValueMatchQuery.java index 6256260abd4d3..de587f7fadc69 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/querydsl/query/SingleValueMatchQuery.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/querydsl/query/SingleValueMatchQuery.java @@ -13,7 +13,6 @@ import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.PointValues; import org.apache.lucene.index.SortedDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.index.Terms; import org.apache.lucene.search.ConstantScoreScorer; @@ -35,6 +34,7 @@ import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.util.Objects; @@ -113,7 +113,7 @@ public boolean isCacheable(LeafReaderContext ctx) { final LeafFieldData lfd = fieldData.load(ctx); // If field is singleton, then it is safe to cache this query, because no warning will ever be emitted. if (lfd instanceof LeafNumericFieldData n) { - if (DocValues.unwrapSingleton(n.getLongValues()) != null) { + if (SortedNumericLongValues.unwrapSingleton(n.getLongValues()) != null) { return true; } } else if (lfd instanceof LeafOrdinalsFieldData o) { @@ -127,12 +127,12 @@ public boolean isCacheable(LeafReaderContext ctx) { private ScorerSupplier scorerSupplier( LeafReaderContext context, - SortedNumericDocValues sortedNumerics, + SortedNumericLongValues sortedNumerics, float boost, ScoreMode scoreMode ) throws IOException { final int maxDoc = context.reader().maxDoc(); - if (DocValues.unwrapSingleton(sortedNumerics) != null) { + if (SortedNumericLongValues.unwrapSingleton(sortedNumerics) != null) { // check for dense field // TODO: check doc values skippers final PointValues points = context.reader().getPointValues(fieldData.getFieldName()); diff --git a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/SourceValueFetcherSortedUnsignedLongIndexFieldData.java b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/SourceValueFetcherSortedUnsignedLongIndexFieldData.java index 8f5f1262c4d82..599a074ef4c27 100644 --- a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/SourceValueFetcherSortedUnsignedLongIndexFieldData.java +++ b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/SourceValueFetcherSortedUnsignedLongIndexFieldData.java @@ -10,6 +10,7 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.IndexFieldDataCache; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.SourceValueFetcherIndexFieldData; import org.elasticsearch.index.mapper.ValueFetcher; import org.elasticsearch.indices.breaker.CircuitBreakerService; @@ -33,16 +34,16 @@ * emulate unsigned long values pulled directly from a doc values data structure through a * {@link SortedNumericDocValues}. */ -public class SourceValueFetcherSortedUnsignedLongIndexFieldData extends SourceValueFetcherIndexFieldData { +public class SourceValueFetcherSortedUnsignedLongIndexFieldData extends SourceValueFetcherIndexFieldData { - public static class Builder extends SourceValueFetcherIndexFieldData.Builder { + public static class Builder extends SourceValueFetcherIndexFieldData.Builder { public Builder( String fieldName, ValuesSourceType valuesSourceType, ValueFetcher valueFetcher, SourceProvider sourceProvider, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, valueFetcher, sourceProvider, toScriptFieldFactory); } @@ -64,20 +65,21 @@ protected SourceValueFetcherSortedUnsignedLongIndexFieldData( ValuesSourceType valuesSourceType, ValueFetcher valueFetcher, SourceProvider sourceProvider, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, valueFetcher, sourceProvider, toScriptFieldFactory); } @Override - public SourceValueFetcherLeafFieldData loadDirect(LeafReaderContext context) { + public SourceValueFetcherLeafFieldData loadDirect(LeafReaderContext context) { return new SourceValueFetcherSortedUnsignedLongLeafFieldData(toScriptFieldFactory, context, valueFetcher, sourceProvider); } - private static class SourceValueFetcherSortedUnsignedLongLeafFieldData extends SourceValueFetcherLeafFieldData { + private static class SourceValueFetcherSortedUnsignedLongLeafFieldData extends SourceValueFetcherLeafFieldData< + SortedNumericLongValues> { private SourceValueFetcherSortedUnsignedLongLeafFieldData( - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, LeafReaderContext leafReaderContext, ValueFetcher valueFetcher, SourceProvider sourceProvider @@ -94,7 +96,7 @@ public DocValuesScriptFieldFactory getScriptFieldFactory(String name) { } } - private static class SourceValueFetcherSortedUnsignedLongDocValues extends SortedNumericDocValues implements ValueFetcherDocValues { + private static class SourceValueFetcherSortedUnsignedLongDocValues extends SortedNumericLongValues implements ValueFetcherDocValues { private final LeafReaderContext leafReaderContext; @@ -141,25 +143,5 @@ public long nextValue() throws IOException { assert iterator.hasNext(); return iterator.next(); } - - @Override - public int docID() { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public int nextDoc() throws IOException { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public int advance(int target) throws IOException { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public long cost() { - throw new UnsupportedOperationException("not supported for source fallback"); - } } } diff --git a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongDocValuesField.java b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongDocValuesField.java index b7c7cdcd67a4b..065188821da5e 100644 --- a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongDocValuesField.java +++ b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongDocValuesField.java @@ -7,8 +7,8 @@ package org.elasticsearch.xpack.unsignedlong; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.field.AbstractLongDocValuesField; import java.math.BigInteger; @@ -21,7 +21,7 @@ public class UnsignedLongDocValuesField extends AbstractLongDocValuesField { - public UnsignedLongDocValuesField(SortedNumericDocValues input, String name) { + public UnsignedLongDocValuesField(SortedNumericLongValues input, String name) { super(input, name); } diff --git a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongIndexFieldData.java b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongIndexFieldData.java index 2f936531f8c72..0a9cfc7b49a30 100644 --- a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongIndexFieldData.java +++ b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongIndexFieldData.java @@ -8,20 +8,20 @@ package org.elasticsearch.xpack.unsignedlong; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.fielddata.LeafNumericFieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.field.ToScriptFieldFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceType; public class UnsignedLongIndexFieldData extends IndexNumericFieldData { private final IndexNumericFieldData signedLongIFD; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; protected final boolean indexed; UnsignedLongIndexFieldData( IndexNumericFieldData signedLongFieldData, - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, boolean indexed ) { this.signedLongIFD = signedLongFieldData; diff --git a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongLeafFieldData.java b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongLeafFieldData.java index 00c60987f439d..472106a5fdfb8 100644 --- a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongLeafFieldData.java +++ b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongLeafFieldData.java @@ -7,15 +7,14 @@ package org.elasticsearch.xpack.unsignedlong; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.FormattedDocValues; import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.plain.FormattedSortedNumericDocValues; import org.elasticsearch.script.field.DocValuesScriptFieldFactory; import org.elasticsearch.script.field.ToScriptFieldFactory; @@ -27,22 +26,22 @@ public class UnsignedLongLeafFieldData implements LeafNumericFieldData { private final LeafNumericFieldData signedLongFD; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; - UnsignedLongLeafFieldData(LeafNumericFieldData signedLongFD, ToScriptFieldFactory toScriptFieldFactory) { + UnsignedLongLeafFieldData(LeafNumericFieldData signedLongFD, ToScriptFieldFactory toScriptFieldFactory) { this.signedLongFD = signedLongFD; this.toScriptFieldFactory = toScriptFieldFactory; } @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { return signedLongFD.getLongValues(); } @Override public SortedNumericDoubleValues getDoubleValues() { - final SortedNumericDocValues values = signedLongFD.getLongValues(); - final NumericDocValues singleValues = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = signedLongFD.getLongValues(); + final LongValues singleValues = SortedNumericLongValues.unwrapSingleton(values); if (singleValues != null) { return FieldData.singleton(new NumericDoubleValues() { @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/frequentitemsets/mr/ItemSetMapReduceValueSource.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/frequentitemsets/mr/ItemSetMapReduceValueSource.java index 08adecd3fbce5..133bbe8564dcf 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/frequentitemsets/mr/ItemSetMapReduceValueSource.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/frequentitemsets/mr/ItemSetMapReduceValueSource.java @@ -12,10 +12,9 @@ import org.apache.lucene.index.BinaryDocValues; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.SortedDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LongBitSet; import org.elasticsearch.common.Strings; @@ -25,6 +24,7 @@ import org.elasticsearch.core.Tuple; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude; import org.elasticsearch.search.aggregations.support.ValuesSource; @@ -405,14 +405,14 @@ public NumericValueSource( @Override ValueCollector getValueCollector(LeafReaderContext ctx) throws IOException { - final SortedNumericDocValues values = source.longValues(ctx); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = source.longValues(ctx); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); final Field field = getField(); final Tuple> empty = new Tuple<>(field, Collections.emptyList()); return singleton != null ? getValueCollector(singleton, empty, field) : getValueCollector(values, empty, field); } - private ValueCollector getValueCollector(SortedNumericDocValues values, Tuple> empty, Field field) { + private ValueCollector getValueCollector(SortedNumericLongValues values, Tuple> empty, Field field) { return doc -> { if (values.advanceExact(doc)) { final int valuesCount = values.docValueCount(); @@ -438,7 +438,7 @@ private ValueCollector getValueCollector(SortedNumericDocValues values, Tuple> empty, Field field) { + private ValueCollector getValueCollector(LongValues values, Tuple> empty, Field field) { return doc -> { if (values.advanceExact(doc)) { final long v = values.longValue(); diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/CartesianPointDVLeafFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/CartesianPointDVLeafFieldData.java index b8bd5e82fef3b..f41c961bf7d14 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/CartesianPointDVLeafFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/CartesianPointDVLeafFieldData.java @@ -9,7 +9,7 @@ import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReader; -import org.apache.lucene.index.SortedNumericDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.field.ToScriptFieldFactory; import org.elasticsearch.xpack.spatial.search.aggregations.support.CartesianPointValuesSource; @@ -35,9 +35,9 @@ public long ramBytesUsed() { } @Override - public SortedNumericDocValues getSortedNumericDocValues() { + public SortedNumericLongValues getSortedNumericLongValues() { try { - return DocValues.getSortedNumeric(reader, fieldName); + return SortedNumericLongValues.wrap(DocValues.getSortedNumeric(reader, fieldName)); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LeafCartesianPointFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LeafCartesianPointFieldData.java index d25101217c63a..c0c2b07114d21 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LeafCartesianPointFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LeafCartesianPointFieldData.java @@ -22,7 +22,7 @@ public LeafCartesianPointFieldData(ToScriptFieldFactory roundingPreparer(AggregationC * Return point values. */ public final MultiCartesianPointValues pointValues(LeafReaderContext context) { - return new MultiCartesianPointValues(sortedNumericDocValues(context)); + return new MultiCartesianPointValues(sortedNumericLongValues(context)); } public static final class MultiCartesianPointValues extends MultiPointValues { private final CartesianPoint point = new CartesianPoint(); - public MultiCartesianPointValues(SortedNumericDocValues numericValues) { + public MultiCartesianPointValues(SortedNumericLongValues numericValues) { super(numericValues); } @@ -74,7 +74,7 @@ public CartesianPoint nextValue() throws IOException { /** * Return the internal representation of point doc values as a {@link SortedNumericDocValues}. */ - public abstract SortedNumericDocValues sortedNumericDocValues(LeafReaderContext context); + public abstract SortedNumericLongValues sortedNumericLongValues(LeafReaderContext context); public static class Fielddata extends CartesianPointValuesSource { @@ -90,8 +90,8 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext context) { } @Override - public SortedNumericDocValues sortedNumericDocValues(LeafReaderContext context) { - return indexFieldData.load(context).getSortedNumericDocValues(); + public SortedNumericLongValues sortedNumericLongValues(LeafReaderContext context) { + return indexFieldData.load(context).getSortedNumericLongValues(); } } } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/CartesianPointValuesSourceType.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/CartesianPointValuesSourceType.java index 29fdaa3c0cfd2..fff42343f8d85 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/CartesianPointValuesSourceType.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/CartesianPointValuesSourceType.java @@ -9,11 +9,11 @@ import org.apache.lucene.geo.XYEncodingUtils; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.AggregationScript; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.support.FieldContext; @@ -68,11 +68,11 @@ public ValuesSource replaceMissing( final CartesianPoint missing = new CartesianPoint().resetFromString(rawMissing.toString(), false); return new CartesianPointValuesSource() { @Override - public SortedNumericDocValues sortedNumericDocValues(LeafReaderContext context) { + public SortedNumericLongValues sortedNumericLongValues(LeafReaderContext context) { final long xi = XYEncodingUtils.encode((float) missing.getX()); final long yi = XYEncodingUtils.encode((float) missing.getY()); long encoded = (yi & 0xFFFFFFFFL) | xi << 32; - return MissingValues.replaceMissing(pointValuesSource.sortedNumericDocValues(context), encoded); + return MissingValues.replaceMissing(pointValuesSource.sortedNumericLongValues(context), encoded); } @Override From 27e8f7ebea595b4c28f1d1222f3fe628ae2b70e7 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 10 Oct 2025 15:44:52 +0100 Subject: [PATCH 2/3] FieldData to use SortedNumericLongValues in place of SortedNumericDocValues We don't need doc-by-doc iteration in FieldData, so this simplifies several implementations and also doesn't make unimplemented APIs available. --- .../script/ScriptScoreBenchmark.java | 6 +- .../AutoDateHistogramAggregator.java | 21 ++- .../timeseries/TimeSeriesAggregator.java | 4 +- .../mapper/extras/ScaledFloatFieldMapper.java | 9 +- .../field/murmur3/Murmur3DocValueField.java | 4 +- .../AbstractSortingNumericDocValues.java | 53 -------- .../fielddata/BooleanScriptDocValues.java | 2 +- .../fielddata/BooleanScriptFieldData.java | 15 +-- .../index/fielddata/DateScriptFieldData.java | 15 +-- .../index/fielddata/FieldData.java | 69 +++++----- .../fielddata/GeoPointScriptDocValues.java | 2 +- .../fielddata/GeoPointScriptFieldData.java | 3 +- .../index/fielddata/GeoPointValues.java | 4 +- .../fielddata/IndexNumericFieldData.java | 10 +- .../index/fielddata/LeafNumericFieldData.java | 4 +- .../index/fielddata/LeafPointFieldData.java | 2 +- .../index/fielddata/LongScriptDocValues.java | 2 +- .../index/fielddata/LongScriptFieldData.java | 15 +-- .../index/fielddata/MultiGeoPointValues.java | 8 +- .../index/fielddata/MultiPointValues.java | 5 +- .../index/fielddata/PointValues.java | 6 +- .../SortableLongBitsNumericDocValues.java | 10 +- ...ortableLongBitsSortedNumericDocValues.java | 5 +- ...SortableLongBitsToNumericDoubleValues.java | 7 +- ...leLongBitsToSortedNumericDoubleValues.java | 9 +- .../fielddata/SortedNumericLongValues.java | 126 ++++++++++++++++++ ...ues.java => SortingNumericLongValues.java} | 9 +- ...lueFetcherSortedBooleanIndexFieldData.java | 37 ++--- ...lueFetcherSortedNumericIndexFieldData.java | 35 +---- .../IntValuesComparatorSource.java | 5 +- .../LongValuesComparatorSource.java | 53 ++++++-- .../FormattedSortedNumericDocValues.java | 6 +- .../plain/LatLonPointDVLeafFieldData.java | 6 +- .../fielddata/plain/LeafDoubleFieldData.java | 4 +- .../plain/LeafGeoPointFieldData.java | 2 +- .../plain/SortedDoublesIndexFieldData.java | 3 +- .../plain/SortedNumericIndexFieldData.java | 29 ++-- .../index/mapper/DateFieldMapper.java | 8 +- .../index/query/TermsSetQueryBuilder.java | 4 +- ...SortedNumericDocValuesLongFieldScript.java | 6 +- .../field/AbstractLongDocValuesField.java | 6 +- .../script/field/BooleanDocValuesField.java | 6 +- .../script/field/ByteDocValuesField.java | 6 +- .../field/DateMillisDocValuesField.java | 6 +- .../script/field/DateNanosDocValuesField.java | 6 +- .../script/field/IntegerDocValuesField.java | 6 +- .../script/field/LongDocValuesField.java | 4 +- .../script/field/SeqNoDocValuesField.java | 4 +- .../script/field/ShortDocValuesField.java | 6 +- .../script/field/VersionDocValuesField.java | 4 +- .../elasticsearch/search/MultiValueMode.java | 50 +++---- .../bucket/composite/GeoTileValuesSource.java | 4 +- .../composite/HistogramValuesSource.java | 4 +- .../bucket/composite/LongValuesSource.java | 17 ++- .../composite/RoundingValuesSource.java | 61 ++------- .../bucket/geogrid/CellIdSource.java | 33 ++--- .../bucket/geogrid/GeoGridAggregator.java | 13 +- .../bucket/geogrid/GeoHashCellIdSource.java | 12 +- .../bucket/geogrid/GeoTileCellIdSource.java | 12 +- .../histogram/DateHistogramAggregator.java | 13 +- .../GeoDistanceRangeAggregatorFactory.java | 4 +- .../DiversifiedNumericSamplerAggregator.java | 7 +- .../bucket/terms/LongRareTermsAggregator.java | 15 +-- .../bucket/terms/NumericTermsAggregator.java | 23 ++-- .../metrics/CardinalityAggregator.java | 21 ++- .../metrics/ValueCountAggregator.java | 4 +- .../aggregations/support/MissingValues.java | 13 +- .../aggregations/support/ValuesSource.java | 33 ++--- .../support/values/ScriptLongValues.java | 4 +- .../index/fielddata/FieldDataTests.java | 42 ++---- .../IntegralDocValuesFieldTests.java | 4 +- .../ScriptDocValuesGeoPointsTests.java | 2 +- .../fielddata/ScriptDocValuesLongsTests.java | 2 +- ...ava => SortingNumericLongValuesTests.java} | 24 +--- .../mapper/BooleanScriptFieldTypeTests.java | 4 +- .../index/mapper/DateFieldTypeTests.java | 10 +- .../mapper/DateScriptFieldTypeTests.java | 4 +- .../mapper/LongScriptFieldTypeTests.java | 4 +- .../functionscore/FunctionScoreTests.java | 4 +- .../search/MultiValueModeTests.java | 35 ++--- .../CompositeValuesCollectorQueueTests.java | 7 +- .../support/MissingValuesTests.java | 7 +- .../support/ValuesSourceConfigTests.java | 14 +- .../multiterms/MultiTermsAggregator.java | 13 +- .../topmetrics/TopMetricsAggregator.java | 4 +- .../TopMetricsAggregatorMetricsTests.java | 12 +- .../compute/lucene/LuceneMaxFactory.java | 7 +- .../compute/lucene/LuceneMinFactory.java | 7 +- .../compute/lucene/LuceneMinMaxOperator.java | 6 +- .../querydsl/query/SingleValueMatchQuery.java | 8 +- ...tcherSortedUnsignedLongIndexFieldData.java | 38 ++---- .../UnsignedLongDocValuesField.java | 4 +- .../UnsignedLongIndexFieldData.java | 6 +- .../UnsignedLongLeafFieldData.java | 15 +-- .../mr/ItemSetMapReduceValueSource.java | 12 +- .../plain/CartesianPointDVLeafFieldData.java | 6 +- .../plain/LeafCartesianPointFieldData.java | 2 +- .../bucket/geogrid/GeoHexCellIdSource.java | 12 +- .../bucket/geogrid/GeoShapeCellIdSource.java | 4 +- .../bucket/geogrid/GeoShapeCellValues.java | 4 +- .../support/CartesianPointValuesSource.java | 16 +-- .../CartesianPointValuesSourceType.java | 6 +- 102 files changed, 644 insertions(+), 721 deletions(-) delete mode 100644 server/src/main/java/org/elasticsearch/index/fielddata/AbstractSortingNumericDocValues.java create mode 100644 server/src/main/java/org/elasticsearch/index/fielddata/SortedNumericLongValues.java rename server/src/main/java/org/elasticsearch/index/fielddata/{SortingNumericDocValues.java => SortingNumericLongValues.java} (90%) rename server/src/test/java/org/elasticsearch/index/fielddata/{SortingNumericDocValuesTests.java => SortingNumericLongValuesTests.java} (77%) diff --git a/benchmarks/src/main/java/org/elasticsearch/benchmark/script/ScriptScoreBenchmark.java b/benchmarks/src/main/java/org/elasticsearch/benchmark/script/ScriptScoreBenchmark.java index f4edff01c901d..bb325e3683ae3 100644 --- a/benchmarks/src/main/java/org/elasticsearch/benchmark/script/ScriptScoreBenchmark.java +++ b/benchmarks/src/main/java/org/elasticsearch/benchmark/script/ScriptScoreBenchmark.java @@ -15,7 +15,6 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig.OpenMode; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; @@ -29,6 +28,7 @@ import org.elasticsearch.index.fielddata.FieldDataContext; import org.elasticsearch.index.fielddata.IndexFieldDataCache; import org.elasticsearch.index.fielddata.IndexNumericFieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.IndexType; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MappingLookup; @@ -179,14 +179,14 @@ private ScoreScript.Factory bareMetalScript() { return new ScoreScript.LeafFactory() { @Override public ScoreScript newInstance(DocReader docReader) throws IOException { - SortedNumericDocValues values = ifd.load(((DocValuesDocReader) docReader).getLeafReaderContext()).getLongValues(); + SortedNumericLongValues values = ifd.load(((DocValuesDocReader) docReader).getLeafReaderContext()).getLongValues(); return new ScoreScript(params, null, docReader) { private int docId; @Override public double execute(ExplanationHolder explanation) { try { - values.advance(docId); + values.advanceExact(docId); if (values.docValueCount() != 1) { throw new IllegalArgumentException("script only works when there is exactly one value"); } diff --git a/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregator.java b/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregator.java index abd482d8298ef..e84cbc674a80f 100644 --- a/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregator.java +++ b/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregator.java @@ -8,9 +8,7 @@ */ package org.elasticsearch.aggregations.bucket.histogram; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.aggregations.bucket.histogram.AutoDateHistogramAggregationBuilder.RoundingInfo; @@ -19,6 +17,7 @@ import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.LongArray; import org.elasticsearch.core.Releasables; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregationExecutionContext; import org.elasticsearch.search.aggregations.Aggregator; @@ -125,17 +124,17 @@ public final DeferringBucketCollector buildDeferringCollector() { return deferringCollector; } - protected abstract LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) throws IOException; + protected abstract LeafBucketCollector getLeafCollector(SortedNumericLongValues values, LeafBucketCollector sub) throws IOException; - protected abstract LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) throws IOException; + protected abstract LeafBucketCollector getLeafCollector(LongValues values, LeafBucketCollector sub) throws IOException; @Override public final LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx, LeafBucketCollector sub) throws IOException { if (valuesSource == null) { return LeafBucketCollector.NO_OP_COLLECTOR; } - final SortedNumericDocValues values = valuesSource.longValues(aggCtx.getLeafReaderContext()); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = valuesSource.longValues(aggCtx.getLeafReaderContext()); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); return singleton != null ? getLeafCollector(singleton, sub) : getLeafCollector(values, sub); } @@ -239,7 +238,7 @@ private static class FromSingle extends AutoDateHistogramAggregator { } @Override - protected LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) { + protected LeafBucketCollector getLeafCollector(SortedNumericLongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -265,7 +264,7 @@ public void collect(int doc, long owningBucketOrd) throws IOException { } @Override - protected LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) { + protected LeafBucketCollector getLeafCollector(LongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -461,7 +460,7 @@ private static class FromMany extends AutoDateHistogramAggregator { } @Override - protected LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) { + protected LeafBucketCollector getLeafCollector(SortedNumericLongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -487,7 +486,7 @@ public void collect(int doc, long owningBucketOrd) throws IOException { } @Override - protected LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) { + protected LeafBucketCollector getLeafCollector(LongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { diff --git a/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/timeseries/TimeSeriesAggregator.java b/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/timeseries/TimeSeriesAggregator.java index 63472bca1d9ac..b71f3377f3e34 100644 --- a/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/timeseries/TimeSeriesAggregator.java +++ b/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/timeseries/TimeSeriesAggregator.java @@ -9,12 +9,12 @@ package org.elasticsearch.aggregations.bucket.timeseries; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.ObjectArray; import org.elasticsearch.core.Releasables; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.RoutingPathFields; import org.elasticsearch.index.mapper.TimeSeriesIdFieldMapper; import org.elasticsearch.search.aggregations.AggregationExecutionContext; @@ -121,7 +121,7 @@ protected LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCt for (var entry : dimensionValueSources.entrySet()) { String fieldName = entry.getKey(); if (entry.getValue() instanceof ValuesSource.Numeric numericVS) { - SortedNumericDocValues docValues = numericVS.longValues(aggCtx.getLeafReaderContext()); + SortedNumericLongValues docValues = numericVS.longValues(aggCtx.getLeafReaderContext()); dimensionConsumers.put(entry.getKey(), (docId, tsidBuilder) -> { if (docValues.advanceExact(docId)) { assert docValues.docValueCount() == 1 : "Dimension field cannot be a multi-valued field"; diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldMapper.java index d2bae840b905d..d0bbf3059395d 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldMapper.java @@ -9,10 +9,8 @@ package org.elasticsearch.index.mapper.extras; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.Query; import org.elasticsearch.common.Explicit; import org.elasticsearch.common.settings.Setting; @@ -28,6 +26,7 @@ import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.SourceValueFetcherSortedDoubleIndexFieldData; import org.elasticsearch.index.fielddata.plain.LeafDoubleFieldData; import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData; @@ -831,8 +830,8 @@ public void close() { @Override public SortedNumericDoubleValues getDoubleValues() { - final SortedNumericDocValues values = scaledFieldData.getLongValues(); - final NumericDocValues singleValues = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = scaledFieldData.getLongValues(); + final LongValues singleValues = SortedNumericLongValues.unwrapSingleton(values); if (singleValues != null) { return FieldData.singleton(new NumericDoubleValues() { @Override diff --git a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/script/field/murmur3/Murmur3DocValueField.java b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/script/field/murmur3/Murmur3DocValueField.java index 324fe910d36bb..2d21452846880 100644 --- a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/script/field/murmur3/Murmur3DocValueField.java +++ b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/script/field/murmur3/Murmur3DocValueField.java @@ -9,12 +9,12 @@ package org.elasticsearch.script.field.murmur3; -import org.apache.lucene.index.SortedNumericDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.field.AbstractLongDocValuesField; public class Murmur3DocValueField extends AbstractLongDocValuesField { - public Murmur3DocValueField(SortedNumericDocValues input, String name) { + public Murmur3DocValueField(SortedNumericLongValues input, String name) { super(input, name); } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/AbstractSortingNumericDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/AbstractSortingNumericDocValues.java deleted file mode 100644 index 076b2fecf4bef..0000000000000 --- a/server/src/main/java/org/elasticsearch/index/fielddata/AbstractSortingNumericDocValues.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.index.fielddata; - -import org.apache.lucene.search.DocIdSetIterator; - -import java.io.IOException; -import java.util.function.LongConsumer; - -/** - * Base implementation that throws an {@link IOException} for the - * {@link DocIdSetIterator} APIs. This impl is safe to use for sorting and - * aggregations, which only use {@link #advanceExact(int)} and - * {@link #docValueCount()} and {@link #nextValue()}. - */ -public abstract class AbstractSortingNumericDocValues extends SortingNumericDocValues { - - public AbstractSortingNumericDocValues() { - super(); - } - - public AbstractSortingNumericDocValues(LongConsumer circuitBreakerConsumer) { - super(circuitBreakerConsumer); - } - - @Override - public int docID() { - throw new UnsupportedOperationException(); - } - - @Override - public int nextDoc() { - throw new UnsupportedOperationException(); - } - - @Override - public int advance(int target) { - throw new UnsupportedOperationException(); - } - - @Override - public long cost() { - throw new UnsupportedOperationException(); - } - -} diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptDocValues.java index 027bdfffe3d1e..2fa15ac786b7f 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptDocValues.java @@ -11,7 +11,7 @@ import org.elasticsearch.script.BooleanFieldScript; -public final class BooleanScriptDocValues extends AbstractSortedNumericDocValues { +public final class BooleanScriptDocValues extends SortedNumericLongValues { private final BooleanFieldScript script; private int cursor; diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptFieldData.java index 0f6db38e9e562..cdf04bd79706e 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/BooleanScriptFieldData.java @@ -10,7 +10,6 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.index.fielddata.plain.LeafLongFieldData; import org.elasticsearch.indices.breaker.CircuitBreakerService; @@ -25,12 +24,12 @@ public final class BooleanScriptFieldData extends IndexNumericFieldData { public static class Builder implements IndexFieldData.Builder { private final String name; private final BooleanFieldScript.LeafFactory leafFactory; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; public Builder( String name, BooleanFieldScript.LeafFactory leafFactory, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { this.name = name; this.leafFactory = leafFactory; @@ -45,12 +44,12 @@ public BooleanScriptFieldData build(IndexFieldDataCache cache, CircuitBreakerSer private final String fieldName; private final BooleanFieldScript.LeafFactory leafFactory; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; private BooleanScriptFieldData( String fieldName, BooleanFieldScript.LeafFactory leafFactory, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { this.fieldName = fieldName; this.leafFactory = leafFactory; @@ -98,11 +97,11 @@ protected boolean isIndexed() { public static class BooleanScriptLeafFieldData extends LeafLongFieldData { private final BooleanScriptDocValues booleanScriptDocValues; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; BooleanScriptLeafFieldData( BooleanScriptDocValues booleanScriptDocValues, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(0); this.booleanScriptDocValues = booleanScriptDocValues; @@ -110,7 +109,7 @@ public static class BooleanScriptLeafFieldData extends LeafLongFieldData { } @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { return booleanScriptDocValues; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/DateScriptFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/DateScriptFieldData.java index 45a550be5252a..b3fe59ae71c39 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/DateScriptFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/DateScriptFieldData.java @@ -10,7 +10,6 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.index.fielddata.plain.LeafLongFieldData; import org.elasticsearch.indices.breaker.CircuitBreakerService; @@ -25,12 +24,12 @@ public final class DateScriptFieldData extends IndexNumericFieldData { public static class Builder implements IndexFieldData.Builder { private final String name; private final DateFieldScript.LeafFactory leafFactory; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; public Builder( String name, DateFieldScript.LeafFactory leafFactory, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { this.name = name; this.leafFactory = leafFactory; @@ -45,12 +44,12 @@ public DateScriptFieldData build(IndexFieldDataCache cache, CircuitBreakerServic private final String fieldName; private final DateFieldScript.LeafFactory leafFactory; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; private DateScriptFieldData( String fieldName, DateFieldScript.LeafFactory leafFactory, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { this.fieldName = fieldName; this.leafFactory = leafFactory; @@ -98,11 +97,11 @@ protected boolean isIndexed() { public static class DateScriptLeafFieldData extends LeafLongFieldData { private final LongScriptDocValues longScriptDocValues; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; DateScriptLeafFieldData( LongScriptDocValues longScriptDocValues, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(0); this.longScriptDocValues = longScriptDocValues; @@ -110,7 +109,7 @@ public static class DateScriptLeafFieldData extends LeafLongFieldData { } @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { return longScriptDocValues; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/FieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/FieldData.java index 6c8d52ac18280..cc1c860635ece 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/FieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/FieldData.java @@ -15,6 +15,7 @@ import org.apache.lucene.index.SortedDocValues; import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; import org.elasticsearch.common.geo.SpatialPoint; @@ -115,7 +116,7 @@ public boolean advanceExact(int doc) throws IOException { * Returns a {@link DocValueBits} representing all documents from docValues that have * a value. */ - public static DocValueBits docsWithValue(final SortedNumericDocValues docValues) { + public static DocValueBits docsWithValue(final SortedNumericLongValues docValues) { return new DocValueBits() { @Override public boolean advanceExact(int doc) throws IOException { @@ -130,16 +131,16 @@ public boolean advanceExact(int doc) throws IOException { * to sortable long bits using * {@link org.apache.lucene.util.NumericUtils#doubleToSortableLong(double)}. */ - public static SortedNumericDocValues toSortableLongBits(SortedNumericDoubleValues values) { + public static SortedNumericLongValues toSortableLongBits(SortedNumericDoubleValues values) { final NumericDoubleValues singleton = unwrapSingleton(values); if (singleton != null) { - final NumericDocValues longBits; + final LongValues longBits; if (singleton instanceof SortableLongBitsToNumericDoubleValues) { longBits = ((SortableLongBitsToNumericDoubleValues) singleton).getLongValues(); } else { longBits = new SortableLongBitsNumericDocValues(singleton); } - return DocValues.singleton(longBits); + return SortedNumericLongValues.singleton(longBits); } else { if (values instanceof SortableLongBitsToSortedNumericDoubleValues) { return ((SortableLongBitsToSortedNumericDoubleValues) values).getLongValues(); @@ -150,12 +151,12 @@ public static SortedNumericDocValues toSortableLongBits(SortedNumericDoubleValue } /** - * Given a {@link SortedNumericDocValues}, return a {@link SortedNumericDoubleValues} + * Given a {@link SortedNumericLongValues}, return a {@link SortedNumericDoubleValues} * instance that will translate long values to doubles using * {@link org.apache.lucene.util.NumericUtils#sortableLongToDouble(long)}. */ - public static SortedNumericDoubleValues sortableLongBitsToDoubles(SortedNumericDocValues values) { - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + public static SortedNumericDoubleValues sortableLongBitsToDoubles(SortedNumericLongValues values) { + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); if (singleton != null) { final NumericDoubleValues doubles; if (singleton instanceof SortableLongBitsNumericDocValues) { @@ -176,8 +177,8 @@ public static SortedNumericDoubleValues sortableLongBitsToDoubles(SortedNumericD /** * Wrap the provided {@link SortedNumericDocValues} instance to cast all values to doubles. */ - public static SortedNumericDoubleValues castToDouble(final SortedNumericDocValues values) { - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + public static SortedNumericDoubleValues castToDouble(final SortedNumericLongValues values) { + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); if (singleton != null) { return singleton(new DoubleCastedValues(singleton)); } else { @@ -188,10 +189,10 @@ public static SortedNumericDoubleValues castToDouble(final SortedNumericDocValue /** * Wrap the provided {@link SortedNumericDoubleValues} instance to cast all values to longs. */ - public static SortedNumericDocValues castToLong(final SortedNumericDoubleValues values) { + public static SortedNumericLongValues castToLong(final SortedNumericDoubleValues values) { final NumericDoubleValues singleton = unwrapSingleton(values); if (singleton != null) { - return DocValues.singleton(new LongCastedValues(singleton)); + return SortedNumericLongValues.singleton(new LongCastedValues(singleton)); } else { return new SortedLongCastedValues(values); } @@ -248,9 +249,9 @@ public static BinaryDocValues unwrapSingleton(SortedBinaryDocValues values) { * typically used for scripts or for the `map` execution mode of terms aggs. * NOTE: this is very slow! */ - public static SortedBinaryDocValues toString(final SortedNumericDocValues values) { + public static SortedBinaryDocValues toString(final SortedNumericLongValues values) { { - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); if (singleton != null) { return FieldData.singleton(toString(singleton)); } @@ -275,7 +276,7 @@ public void get(List list) throws IOException { * typically used for scripts or for the `map` execution mode of terms aggs. * NOTE: this is very slow! */ - public static BinaryDocValues toString(final NumericDocValues values) { + public static BinaryDocValues toString(final LongValues values) { return toString(new ToStringValue() { @Override public boolean advanceExact(int doc) throws IOException { @@ -506,9 +507,9 @@ private interface ToStringValue { private static class DoubleCastedValues extends NumericDoubleValues { - private final NumericDocValues values; + private final LongValues values; - DoubleCastedValues(NumericDocValues values) { + DoubleCastedValues(LongValues values) { this.values = values; } @@ -526,9 +527,9 @@ public boolean advanceExact(int doc) throws IOException { private static class SortedDoubleCastedValues extends SortedNumericDoubleValues { - private final SortedNumericDocValues values; + private final SortedNumericLongValues values; - SortedDoubleCastedValues(SortedNumericDocValues in) { + SortedDoubleCastedValues(SortedNumericLongValues in) { this.values = in; } @@ -549,10 +550,9 @@ public int docValueCount() { } - private static class LongCastedValues extends AbstractNumericDocValues { + private static class LongCastedValues extends LongValues { private final NumericDoubleValues values; - private int docID = -1; LongCastedValues(NumericDoubleValues values) { this.values = values; @@ -560,7 +560,6 @@ private static class LongCastedValues extends AbstractNumericDocValues { @Override public boolean advanceExact(int target) throws IOException { - docID = target; return values.advanceExact(target); } @@ -568,14 +567,9 @@ public boolean advanceExact(int target) throws IOException { public long longValue() throws IOException { return (long) values.doubleValue(); } - - @Override - public int docID() { - return docID; - } } - private static class SortedLongCastedValues extends AbstractSortedNumericDocValues { + private static class SortedLongCastedValues extends SortedNumericLongValues { private final SortedNumericDoubleValues values; @@ -600,21 +594,28 @@ public long nextValue() throws IOException { } + public static LongValues EMPTY = new LongValues() { + @Override + public long longValue() throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public boolean advanceExact(int doc) throws IOException { + return false; + } + }; + /** * Return a {@link NumericDocValues} instance that has a value for every * document, returns the same value as {@code values} if there is a value * for the current document and {@code missing} otherwise. */ - public static NumericDocValues replaceMissing(NumericDocValues values, long missing) { - return new AbstractNumericDocValues() { + public static LongValues replaceMissing(LongValues values, long missing) { + return new LongValues() { private long value; - @Override - public int docID() { - return values.docID(); - } - @Override public boolean advanceExact(int target) throws IOException { if (values.advanceExact(target)) { diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptDocValues.java index c9aed46377c3f..9d15ae19def5a 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptDocValues.java @@ -13,7 +13,7 @@ import org.apache.lucene.util.IntroSorter; import org.elasticsearch.script.GeoPointFieldScript; -public final class GeoPointScriptDocValues extends AbstractSortedNumericDocValues { +public final class GeoPointScriptDocValues extends SortedNumericLongValues { private final GeoPointFieldScript script; private int cursor; diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptFieldData.java index e6bd6c3e59656..3b2d47586da08 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointScriptFieldData.java @@ -10,7 +10,6 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.SortField; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.index.fielddata.plain.LeafGeoPointFieldData; @@ -94,7 +93,7 @@ public LeafPointFieldData load(LeafReaderContext context) { GeoPointFieldScript script = leafFactory.newInstance(context); return new LeafGeoPointFieldData(toScriptFieldFactory) { @Override - public SortedNumericDocValues getSortedNumericDocValues() { + public SortedNumericLongValues getSortedNumericLongValues() { return new GeoPointScriptDocValues(script); } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointValues.java index 502d9a807b5f6..7fe0f3728cc36 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/GeoPointValues.java @@ -9,7 +9,7 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.NumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.geo.GeoPoint; import java.io.IOException; @@ -21,7 +21,7 @@ public final class GeoPointValues extends PointValues { private final GeoPoint point = new GeoPoint(); - GeoPointValues(NumericDocValues values) { + GeoPointValues(LongValues values) { super(values); } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/IndexNumericFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/IndexNumericFieldData.java index 4e7cf8ead2d7b..506cb1fc5086b 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/IndexNumericFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/IndexNumericFieldData.java @@ -9,7 +9,6 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortedNumericSelector; import org.apache.lucene.search.SortedNumericSortField; @@ -265,8 +264,8 @@ protected XFieldComparatorSource dateNanosComparatorSource(@Nullable Object miss /** * Convert the values in dvs using the provided converter. */ - protected static SortedNumericDocValues convertNumeric(SortedNumericDocValues values, LongUnaryOperator converter) { - return new AbstractSortedNumericDocValues() { + protected static SortedNumericLongValues convertNumeric(SortedNumericLongValues values, LongUnaryOperator converter) { + return new SortedNumericLongValues() { @Override public boolean advanceExact(int target) throws IOException { @@ -282,11 +281,6 @@ public long nextValue() throws IOException { public int docValueCount() { return values.docValueCount(); } - - @Override - public int nextDoc() throws IOException { - return values.nextDoc(); - } }; } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/LeafNumericFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/LeafNumericFieldData.java index 902f4c87d14fb..adf53d8a0cc18 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/LeafNumericFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/LeafNumericFieldData.java @@ -9,8 +9,6 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.SortedNumericDocValues; - /** * Specialization of {@link LeafFieldData} for numeric data. */ @@ -21,7 +19,7 @@ public interface LeafNumericFieldData extends LeafFieldData { * stores floating-point numbers then these values will return the same * values but casted to longs. */ - SortedNumericDocValues getLongValues(); + SortedNumericLongValues getLongValues(); /** * Return a floating-point view of the values in this segment. If the diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/LeafPointFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/LeafPointFieldData.java index 56c1797c1ca42..2d57a26774ade 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/LeafPointFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/LeafPointFieldData.java @@ -26,6 +26,6 @@ public abstract class LeafPointFieldData toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; public Builder( String name, LongFieldScript.LeafFactory leafFactory, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { this.name = name; this.leafFactory = leafFactory; @@ -45,12 +44,12 @@ public LongScriptFieldData build(IndexFieldDataCache cache, CircuitBreakerServic private final String fieldName; private final LongFieldScript.LeafFactory leafFactory; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; private LongScriptFieldData( String fieldName, LongFieldScript.LeafFactory leafFactory, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { this.fieldName = fieldName; this.leafFactory = leafFactory; @@ -98,11 +97,11 @@ protected boolean isIndexed() { public static class LongScriptLeafFieldData extends LeafLongFieldData { private final LongScriptDocValues longScriptDocValues; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; LongScriptLeafFieldData( LongScriptDocValues longScriptDocValues, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(0); this.longScriptDocValues = longScriptDocValues; @@ -110,7 +109,7 @@ public static class LongScriptLeafFieldData extends LeafLongFieldData { } @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { return longScriptDocValues; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/MultiGeoPointValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/MultiGeoPointValues.java index 06deda44dc364..d625439c5364e 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/MultiGeoPointValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/MultiGeoPointValues.java @@ -8,9 +8,7 @@ */ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.geo.GeoPoint; import java.io.IOException; @@ -33,7 +31,7 @@ public class MultiGeoPointValues extends MultiPointValues { private final GeoPoint point = new GeoPoint(); - public MultiGeoPointValues(SortedNumericDocValues numericValues) { + public MultiGeoPointValues(SortedNumericLongValues numericValues) { super(numericValues); } @@ -46,7 +44,7 @@ public GeoPoint nextValue() throws IOException { * Returns a single-valued view of the {@link MultiPointValues} if possible, otherwise null. */ protected GeoPointValues getPointValues() { - final NumericDocValues singleton = DocValues.unwrapSingleton(numericValues); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(numericValues); return singleton != null ? new GeoPointValues(singleton) : null; } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/MultiPointValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/MultiPointValues.java index 854f06d9b606a..1c18f9750b211 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/MultiPointValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/MultiPointValues.java @@ -8,7 +8,6 @@ */ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.SpatialPoint; @@ -19,12 +18,12 @@ */ public abstract class MultiPointValues { - protected final SortedNumericDocValues numericValues; + protected final SortedNumericLongValues numericValues; /** * Creates a new {@link MultiPointValues} instance */ - protected MultiPointValues(SortedNumericDocValues numericValues) { + protected MultiPointValues(SortedNumericLongValues numericValues) { this.numericValues = numericValues; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/PointValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/PointValues.java index 688217f086ae4..adcda6891304a 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/PointValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/PointValues.java @@ -9,7 +9,7 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.NumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.geo.SpatialPoint; import java.io.IOException; @@ -19,9 +19,9 @@ */ public abstract class PointValues { - protected final NumericDocValues values; + protected final LongValues values; - protected PointValues(NumericDocValues values) { + protected PointValues(LongValues values) { this.values = values; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsNumericDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsNumericDocValues.java index a4166c4dc2e1b..87e2e79ec12a4 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsNumericDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsNumericDocValues.java @@ -10,6 +10,7 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.NumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.NumericUtils; import java.io.IOException; @@ -19,9 +20,8 @@ * and converts the doubles to sortable long bits using * {@link NumericUtils#doubleToSortableLong(double)}. */ -final class SortableLongBitsNumericDocValues extends AbstractNumericDocValues { +final class SortableLongBitsNumericDocValues extends LongValues { - private int docID = -1; private final NumericDoubleValues values; SortableLongBitsNumericDocValues(NumericDoubleValues values) { @@ -35,15 +35,9 @@ public long longValue() throws IOException { @Override public boolean advanceExact(int target) throws IOException { - docID = target; return values.advanceExact(target); } - @Override - public int docID() { - return docID; - } - /** Return the wrapped values. */ public NumericDoubleValues getDoubleValues() { return values; diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsSortedNumericDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsSortedNumericDocValues.java index 9ea37f4afd4a5..1a9c4f5c95be7 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsSortedNumericDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsSortedNumericDocValues.java @@ -9,7 +9,6 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.Scorable; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.common.lucene.ScorerAware; @@ -17,11 +16,11 @@ import java.io.IOException; /** - * {@link SortedNumericDocValues} instance that wraps a {@link SortedNumericDoubleValues} + * {@link SortedNumericLongValues} instance that wraps a {@link SortedNumericDoubleValues} * and converts the doubles to sortable long bits using * {@link NumericUtils#doubleToSortableLong(double)}. */ -final class SortableLongBitsSortedNumericDocValues extends AbstractSortedNumericDocValues implements ScorerAware { +final class SortableLongBitsSortedNumericDocValues extends SortedNumericLongValues implements ScorerAware { private final SortedNumericDoubleValues values; diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToNumericDoubleValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToNumericDoubleValues.java index 5f674125b7c1b..8e210c1520b59 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToNumericDoubleValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToNumericDoubleValues.java @@ -10,6 +10,7 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.NumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.NumericUtils; import java.io.IOException; @@ -21,9 +22,9 @@ */ final class SortableLongBitsToNumericDoubleValues extends NumericDoubleValues { - private final NumericDocValues values; + private final LongValues values; - SortableLongBitsToNumericDoubleValues(NumericDocValues values) { + SortableLongBitsToNumericDoubleValues(LongValues values) { this.values = values; } @@ -38,7 +39,7 @@ public boolean advanceExact(int doc) throws IOException { } /** Return the wrapped values. */ - public NumericDocValues getLongValues() { + public LongValues getLongValues() { return values; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToSortedNumericDoubleValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToSortedNumericDoubleValues.java index ce95003985571..33519b4cb9fba 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToSortedNumericDoubleValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SortableLongBitsToSortedNumericDoubleValues.java @@ -9,21 +9,20 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.NumericUtils; import java.io.IOException; /** - * {@link SortedNumericDoubleValues} instance that wraps a {@link SortedNumericDocValues} + * {@link SortedNumericDoubleValues} instance that wraps a {@link SortedNumericLongValues} * and converts the doubles to sortable long bits using * {@link NumericUtils#sortableLongToDouble(long)}. */ final class SortableLongBitsToSortedNumericDoubleValues extends SortedNumericDoubleValues { - private final SortedNumericDocValues values; + private final SortedNumericLongValues values; - SortableLongBitsToSortedNumericDoubleValues(SortedNumericDocValues values) { + SortableLongBitsToSortedNumericDoubleValues(SortedNumericLongValues values) { this.values = values; } @@ -43,7 +42,7 @@ public int docValueCount() { } /** Return the wrapped values. */ - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { return values; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SortedNumericLongValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/SortedNumericLongValues.java new file mode 100644 index 0000000000000..622f2f8a647a1 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SortedNumericLongValues.java @@ -0,0 +1,126 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +package org.elasticsearch.index.fielddata; + +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.NumericDocValues; +import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; + +import java.io.IOException; + +public abstract class SortedNumericLongValues { + + public static SortedNumericLongValues EMPTY = new SortedNumericLongValues() { + @Override + public boolean advanceExact(int target) { + return false; + } + + @Override + public long nextValue() { + throw new UnsupportedOperationException(); + } + + @Override + public int docValueCount() { + throw new UnsupportedOperationException(); + } + }; + + /** Advance the iterator to exactly {@code target} and return whether + * {@code target} has a value. + * {@code target} must be greater than or equal to the current + * doc ID and must be a valid doc ID, ie. ≥ 0 and + * < {@code maxDoc}.*/ + public abstract boolean advanceExact(int target) throws IOException; + + /** + * Iterates to the next value in the current document. Do not call this more than + * {@link #docValueCount} times for the document. + */ + public abstract long nextValue() throws IOException; + + /** + * Retrieves the number of values for the current document. This must always + * be greater than zero. + * It is illegal to call this method after {@link #advanceExact(int)} + * returned {@code false}. + */ + public abstract int docValueCount(); + + public static LongValues unwrapSingleton(SortedNumericLongValues values) { + if (values instanceof SingletonSortedNumericLongValues sv) { + return sv.values; + } + return null; + } + + public static SortedNumericLongValues singleton(LongValues values) { + return new SingletonSortedNumericLongValues(values); + } + + private static class SingletonSortedNumericLongValues extends SortedNumericLongValues { + + private final LongValues values; + + private SingletonSortedNumericLongValues(LongValues values) { + this.values = values; + } + + @Override + public boolean advanceExact(int target) throws IOException { + return values.advanceExact(target); + } + + @Override + public long nextValue() throws IOException { + return values.longValue(); + } + + @Override + public int docValueCount() { + return 1; + } + } + + public static SortedNumericLongValues wrap(SortedNumericDocValues values) { + NumericDocValues singleton = DocValues.unwrapSingleton(values); + if (singleton != null) { + return new SingletonSortedNumericLongValues(new LongValues() { + @Override + public long longValue() throws IOException { + return singleton.longValue(); + } + + @Override + public boolean advanceExact(int doc) throws IOException { + return singleton.advanceExact(doc); + } + }); + } + return new SortedNumericLongValues() { + @Override + public boolean advanceExact(int target) throws IOException { + return values.advanceExact(target); + } + + @Override + public long nextValue() throws IOException { + return values.nextValue(); + } + + @Override + public int docValueCount() { + return values.docValueCount(); + } + }; + } +} diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SortingNumericDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/SortingNumericLongValues.java similarity index 90% rename from server/src/main/java/org/elasticsearch/index/fielddata/SortingNumericDocValues.java rename to server/src/main/java/org/elasticsearch/index/fielddata/SortingNumericLongValues.java index 02f5de7e3c8ca..595726bf6f215 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SortingNumericDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SortingNumericLongValues.java @@ -9,7 +9,6 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.InPlaceMergeSorter; import org.apache.lucene.util.Sorter; @@ -17,9 +16,9 @@ import java.util.function.LongConsumer; /** - * Base class for building {@link SortedNumericDocValues} instances based on unsorted content. + * Base class for building {@link SortedNumericLongValues} instances based on unsorted content. */ -public abstract class SortingNumericDocValues extends SortedNumericDocValues { +public abstract class SortingNumericLongValues extends SortedNumericLongValues { private int count; protected long[] values; @@ -27,11 +26,11 @@ public abstract class SortingNumericDocValues extends SortedNumericDocValues { private final Sorter sorter; private final LongConsumer circuitBreakerConsumer; - protected SortingNumericDocValues() { + protected SortingNumericLongValues() { this(l -> {}); } - protected SortingNumericDocValues(LongConsumer circuitBreakerConsumer) { + protected SortingNumericLongValues(LongConsumer circuitBreakerConsumer) { values = new long[1]; valuesCursor = 0; sorter = new InPlaceMergeSorter() { diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedBooleanIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedBooleanIndexFieldData.java index 56937d47b794d..757646c7b8ca9 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedBooleanIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedBooleanIndexFieldData.java @@ -10,7 +10,6 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.mapper.ValueFetcher; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.script.field.DocValuesScriptFieldFactory; @@ -22,16 +21,16 @@ import java.io.IOException; import java.util.Collections; -public class SourceValueFetcherSortedBooleanIndexFieldData extends SourceValueFetcherIndexFieldData { +public class SourceValueFetcherSortedBooleanIndexFieldData extends SourceValueFetcherIndexFieldData { - public static class Builder extends SourceValueFetcherIndexFieldData.Builder { + public static class Builder extends SourceValueFetcherIndexFieldData.Builder { public Builder( String fieldName, ValuesSourceType valuesSourceType, ValueFetcher valueFetcher, SourceProvider sourceProvider, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, valueFetcher, sourceProvider, toScriptFieldFactory); } @@ -53,20 +52,20 @@ protected SourceValueFetcherSortedBooleanIndexFieldData( ValuesSourceType valuesSourceType, ValueFetcher valueFetcher, SourceProvider sourceProvider, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, valueFetcher, sourceProvider, toScriptFieldFactory); } @Override - public SourceValueFetcherLeafFieldData loadDirect(LeafReaderContext context) { + public SourceValueFetcherLeafFieldData loadDirect(LeafReaderContext context) { return new SourceValueFetcherSortedBooleanLeafFieldData(toScriptFieldFactory, context, valueFetcher, sourceProvider); } - private static class SourceValueFetcherSortedBooleanLeafFieldData extends SourceValueFetcherLeafFieldData { + private static class SourceValueFetcherSortedBooleanLeafFieldData extends SourceValueFetcherLeafFieldData { private SourceValueFetcherSortedBooleanLeafFieldData( - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, LeafReaderContext leafReaderContext, ValueFetcher valueFetcher, SourceProvider sourceProvider @@ -83,7 +82,7 @@ public DocValuesScriptFieldFactory getScriptFieldFactory(String name) { } } - static class SourceValueFetcherSortedBooleanDocValues extends SortedNumericDocValues implements ValueFetcherDocValues { + static class SourceValueFetcherSortedBooleanDocValues extends SortedNumericLongValues implements ValueFetcherDocValues { private final LeafReaderContext leafReaderContext; @@ -133,25 +132,5 @@ public long nextValue() { assert iteratorIndex < trueCount + falseCount; return iteratorIndex++ < falseCount ? 0L : 1L; } - - @Override - public int docID() { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public int nextDoc() { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public int advance(int target) { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public long cost() { - throw new UnsupportedOperationException("not supported for source fallback"); - } } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedNumericIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedNumericIndexFieldData.java index ce1dff33e80ce..aab8cb26df8d4 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedNumericIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/SourceValueFetcherSortedNumericIndexFieldData.java @@ -10,7 +10,6 @@ package org.elasticsearch.index.fielddata; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.mapper.ValueFetcher; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.script.field.DocValuesScriptFieldFactory; @@ -25,16 +24,16 @@ import java.util.Iterator; import java.util.List; -public class SourceValueFetcherSortedNumericIndexFieldData extends SourceValueFetcherIndexFieldData { +public class SourceValueFetcherSortedNumericIndexFieldData extends SourceValueFetcherIndexFieldData { - public static class Builder extends SourceValueFetcherIndexFieldData.Builder { + public static class Builder extends SourceValueFetcherIndexFieldData.Builder { public Builder( String fieldName, ValuesSourceType valuesSourceType, ValueFetcher valueFetcher, SourceProvider sourceProvider, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, valueFetcher, sourceProvider, toScriptFieldFactory); } @@ -56,7 +55,7 @@ protected SourceValueFetcherSortedNumericIndexFieldData( ValuesSourceType valuesSourceType, ValueFetcher valueFetcher, SourceProvider sourceProvider, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, valueFetcher, sourceProvider, toScriptFieldFactory); } @@ -66,10 +65,10 @@ public SourceValueFetcherSortedNumericLeafFieldData loadDirect(LeafReaderContext return new SourceValueFetcherSortedNumericLeafFieldData(toScriptFieldFactory, context, valueFetcher, sourceProvider); } - public static class SourceValueFetcherSortedNumericLeafFieldData extends SourceValueFetcherLeafFieldData { + public static class SourceValueFetcherSortedNumericLeafFieldData extends SourceValueFetcherLeafFieldData { public SourceValueFetcherSortedNumericLeafFieldData( - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, LeafReaderContext leafReaderContext, ValueFetcher valueFetcher, SourceProvider sourceProvider @@ -86,7 +85,7 @@ public DocValuesScriptFieldFactory getScriptFieldFactory(String name) { } } - public static class SourceValueFetcherSortedNumericDocValues extends SortedNumericDocValues implements ValueFetcherDocValues { + public static class SourceValueFetcherSortedNumericDocValues extends SortedNumericLongValues implements ValueFetcherDocValues { protected final LeafReaderContext leafReaderContext; @@ -133,25 +132,5 @@ public long nextValue() { assert iterator.hasNext(); return iterator.next(); } - - @Override - public int docID() { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public int nextDoc() { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public int advance(int target) { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public long cost() { - throw new UnsupportedOperationException("not supported for source fallback"); - } } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/IntValuesComparatorSource.java b/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/IntValuesComparatorSource.java index 184288d0437b8..544b933772065 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/IntValuesComparatorSource.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/IntValuesComparatorSource.java @@ -12,6 +12,7 @@ import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.search.FieldComparator; import org.apache.lucene.search.LeafFieldComparator; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.Pruning; import org.apache.lucene.search.SortField; import org.apache.lucene.search.comparators.IntComparator; @@ -59,7 +60,7 @@ public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws I return new IntLeafComparator(context) { @Override protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException { - return IntValuesComparatorSource.this.getNumericDocValues(context, iMissingValue); + return wrap(getLongValues(context, iMissingValue)); } }; } @@ -80,7 +81,7 @@ public BucketedSort newBucketedSort( @Override public Leaf forLeaf(LeafReaderContext ctx) throws IOException { return new Leaf(ctx) { - private final NumericDocValues docValues = getNumericDocValues(ctx, iMissingValue); + private final LongValues docValues = getLongValues(ctx, iMissingValue); private int docValue; @Override diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/LongValuesComparatorSource.java b/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/LongValuesComparatorSource.java index 84ad27efe7778..d27c1b4784311 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/LongValuesComparatorSource.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/fieldcomparator/LongValuesComparatorSource.java @@ -10,10 +10,10 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.FieldComparator; import org.apache.lucene.search.LeafFieldComparator; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.Pruning; import org.apache.lucene.search.SortField; import org.apache.lucene.search.comparators.LongComparator; @@ -26,6 +26,7 @@ import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType; import org.elasticsearch.index.fielddata.LeafNumericFieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.MultiValueMode; @@ -41,7 +42,7 @@ public class LongValuesComparatorSource extends IndexFieldData.XFieldComparatorSource { final IndexNumericFieldData indexFieldData; - private final Function converter; + private final Function converter; private final NumericType targetNumericType; public LongValuesComparatorSource( @@ -59,7 +60,7 @@ public LongValuesComparatorSource( @Nullable Object missingValue, MultiValueMode sortMode, Nested nested, - Function converter, + Function converter, NumericType targetNumericType ) { super(missingValue, sortMode, nested); @@ -73,9 +74,9 @@ public SortField.Type reducedType() { return SortField.Type.LONG; } - private SortedNumericDocValues loadDocValues(LeafReaderContext context) { + private SortedNumericLongValues loadDocValues(LeafReaderContext context) { final LeafNumericFieldData data = indexFieldData.load(context); - SortedNumericDocValues values; + SortedNumericLongValues values; if (data instanceof SortedNumericIndexFieldData.NanoSecondFieldData) { values = ((SortedNumericIndexFieldData.NanoSecondFieldData) data).getLongValuesAsNanos(); } else { @@ -84,8 +85,8 @@ private SortedNumericDocValues loadDocValues(LeafReaderContext context) { return converter != null ? converter.apply(values) : values; } - NumericDocValues getNumericDocValues(LeafReaderContext context, long missingValue) throws IOException { - final SortedNumericDocValues values = loadDocValues(context); + LongValues getLongValues(LeafReaderContext context, long missingValue) throws IOException { + final SortedNumericLongValues values = loadDocValues(context); if (nested == null) { return FieldData.replaceMissing(sortMode.select(values), missingValue); } @@ -108,7 +109,7 @@ public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws I return new LongLeafComparator(context) { @Override protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException { - return LongValuesComparatorSource.this.getNumericDocValues(context, lMissingValue); + return wrap(getLongValues(context, lMissingValue)); } }; } @@ -129,7 +130,7 @@ public BucketedSort newBucketedSort( @Override public Leaf forLeaf(LeafReaderContext ctx) throws IOException { return new Leaf(ctx) { - private final NumericDocValues docValues = getNumericDocValues(ctx, lMissingValue); + private final LongValues docValues = getLongValues(ctx, lMissingValue); private long docValue; @Override @@ -161,4 +162,38 @@ public Object missingObject(Object missingValue, boolean reversed) { } return super.missingObject(missingValue, reversed); } + + protected static NumericDocValues wrap(LongValues longValues) { + return new NumericDocValues() { + @Override + public long longValue() throws IOException { + return longValues.longValue(); + } + + @Override + public boolean advanceExact(int target) throws IOException { + return longValues.advanceExact(target); + } + + @Override + public int docID() { + throw new UnsupportedOperationException(); + } + + @Override + public int nextDoc() throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public int advance(int target) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public long cost() { + throw new UnsupportedOperationException(); + } + }; + } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/FormattedSortedNumericDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/FormattedSortedNumericDocValues.java index da64520c7c86c..0599e2d336100 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/FormattedSortedNumericDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/FormattedSortedNumericDocValues.java @@ -8,17 +8,17 @@ */ package org.elasticsearch.index.fielddata.plain; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.FormattedDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import java.io.IOException; public final class FormattedSortedNumericDocValues implements FormattedDocValues { - private final SortedNumericDocValues values; + private final SortedNumericLongValues values; private final DocValueFormat format; - public FormattedSortedNumericDocValues(SortedNumericDocValues values, DocValueFormat format) { + public FormattedSortedNumericDocValues(SortedNumericLongValues values, DocValueFormat format) { this.values = values; this.format = format; } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/LatLonPointDVLeafFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/LatLonPointDVLeafFieldData.java index 64e6dd223caf4..2a998db041bf4 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/LatLonPointDVLeafFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/LatLonPointDVLeafFieldData.java @@ -10,8 +10,8 @@ import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReader; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.MultiGeoPointValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.field.ToScriptFieldFactory; import java.io.IOException; @@ -32,9 +32,9 @@ public long ramBytesUsed() { } @Override - public SortedNumericDocValues getSortedNumericDocValues() { + public SortedNumericLongValues getSortedNumericLongValues() { try { - return DocValues.getSortedNumeric(reader, fieldName); + return SortedNumericLongValues.wrap(DocValues.getSortedNumeric(reader, fieldName)); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafDoubleFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafDoubleFieldData.java index e870f7af22562..f3d4cad1aa65c 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafDoubleFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafDoubleFieldData.java @@ -9,12 +9,12 @@ package org.elasticsearch.index.fielddata.plain; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.FormattedDocValues; import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import java.io.IOException; @@ -35,7 +35,7 @@ public final SortedBinaryDocValues getBytesValues() { } @Override - public final SortedNumericDocValues getLongValues() { + public final SortedNumericLongValues getLongValues() { return FieldData.castToLong(getDoubleValues()); } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafGeoPointFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafGeoPointFieldData.java index 3d5e9846eab5f..35faf47d0cb0c 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafGeoPointFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/LeafGeoPointFieldData.java @@ -25,7 +25,7 @@ public LeafGeoPointFieldData(ToScriptFieldFactory toScriptF @Override public final MultiGeoPointValues getPointValues() { - return new MultiGeoPointValues(getSortedNumericDocValues()); + return new MultiGeoPointValues(getSortedNumericLongValues()); } @Override diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedDoublesIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedDoublesIndexFieldData.java index ae20100f4c1f7..51d0cfd5072a3 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedDoublesIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedDoublesIndexFieldData.java @@ -24,6 +24,7 @@ import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.script.field.DocValuesScriptFieldFactory; import org.elasticsearch.script.field.ToScriptFieldFactory; @@ -350,7 +351,7 @@ static final class SortedNumericDoubleFieldData extends LeafDoubleFieldData { public SortedNumericDoubleValues getDoubleValues() { try { SortedNumericDocValues raw = DocValues.getSortedNumeric(reader, field); - return FieldData.sortableLongBitsToDoubles(raw); + return FieldData.sortableLongBitsToDoubles(SortedNumericLongValues.wrap(raw)); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericIndexFieldData.java b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericIndexFieldData.java index 98fd4e27f9422..e40f71b344b74 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericIndexFieldData.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericIndexFieldData.java @@ -21,6 +21,7 @@ import org.elasticsearch.index.fielddata.IndexFieldDataCache; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.fielddata.LeafNumericFieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.script.field.DocValuesScriptFieldFactory; @@ -42,13 +43,13 @@ public static class Builder implements IndexFieldData.Builder { private final String name; private final NumericType numericType; private final ValuesSourceType valuesSourceType; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; private final boolean indexed; public Builder( String name, NumericType numericType, - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, boolean indexed ) { this(name, numericType, numericType.getValuesSourceType(), toScriptFieldFactory, indexed); @@ -58,7 +59,7 @@ public Builder( String name, NumericType numericType, ValuesSourceType valuesSourceType, - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, boolean indexed ) { this.name = name; @@ -77,14 +78,14 @@ public SortedNumericIndexFieldData build(IndexFieldDataCache cache, CircuitBreak private final NumericType numericType; protected final String fieldName; protected final ValuesSourceType valuesSourceType; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; protected final boolean indexed; public SortedNumericIndexFieldData( String fieldName, NumericType numericType, ValuesSourceType valuesSourceType, - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, boolean indexed ) { this.fieldName = fieldName; @@ -177,9 +178,9 @@ public static final class NanoSecondFieldData extends LeafLongFieldData { private final LeafReader reader; private final String fieldName; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; - NanoSecondFieldData(LeafReader reader, String fieldName, ToScriptFieldFactory toScriptFieldFactory) { + NanoSecondFieldData(LeafReader reader, String fieldName, ToScriptFieldFactory toScriptFieldFactory) { super(0L); this.reader = reader; this.fieldName = fieldName; @@ -187,13 +188,13 @@ public static final class NanoSecondFieldData extends LeafLongFieldData { } @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { return convertNumeric(getLongValuesAsNanos(), DateUtils::toMilliSeconds); } - public SortedNumericDocValues getLongValuesAsNanos() { + public SortedNumericLongValues getLongValuesAsNanos() { try { - return DocValues.getSortedNumeric(reader, fieldName); + return SortedNumericLongValues.wrap(DocValues.getSortedNumeric(reader, fieldName)); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } @@ -225,9 +226,9 @@ public FormattedDocValues getFormattedValues(DocValueFormat format) { static final class SortedNumericLongFieldData extends LeafLongFieldData { final LeafReader reader; final String field; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; - SortedNumericLongFieldData(LeafReader reader, String field, ToScriptFieldFactory toScriptFieldFactory) { + SortedNumericLongFieldData(LeafReader reader, String field, ToScriptFieldFactory toScriptFieldFactory) { super(0L); this.reader = reader; this.field = field; @@ -235,9 +236,9 @@ static final class SortedNumericLongFieldData extends LeafLongFieldData { } @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { try { - return DocValues.getSortedNumeric(reader, field); + return SortedNumericLongValues.wrap(DocValues.getSortedNumeric(reader, field)); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java index cc4ec0c2f8296..9991abba7ba6a 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java @@ -20,7 +20,6 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.PointValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.IndexOrDocValuesQuery; import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery; import org.apache.lucene.search.Query; @@ -45,6 +44,7 @@ import org.elasticsearch.index.fielddata.FieldDataContext; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.SourceValueFetcherSortedNumericIndexFieldData; import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData; import org.elasticsearch.index.query.DateRangeIncludingNowQuery; @@ -186,9 +186,9 @@ public long roundUpToMillis(long value) { private final String type; private final NumericType numericType; - private final ToScriptFieldFactory toScriptFieldFactory; + private final ToScriptFieldFactory toScriptFieldFactory; - Resolution(String type, NumericType numericType, ToScriptFieldFactory toScriptFieldFactory) { + Resolution(String type, NumericType numericType, ToScriptFieldFactory toScriptFieldFactory) { this.type = type; this.numericType = numericType; this.toScriptFieldFactory = toScriptFieldFactory; @@ -202,7 +202,7 @@ NumericType numericType() { return numericType; } - ToScriptFieldFactory getDefaultToScriptFieldFactory() { + ToScriptFieldFactory getDefaultToScriptFieldFactory() { return toScriptFieldFactory; } diff --git a/server/src/main/java/org/elasticsearch/index/query/TermsSetQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/TermsSetQueryBuilder.java index b12b417e24aa8..232423bed08ca 100644 --- a/server/src/main/java/org/elasticsearch/index/query/TermsSetQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/TermsSetQueryBuilder.java @@ -9,7 +9,6 @@ package org.elasticsearch.index.query; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.Term; import org.apache.lucene.sandbox.search.CoveringQuery; import org.apache.lucene.search.DoubleValues; @@ -26,6 +25,7 @@ import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.index.fielddata.IndexNumericFieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.script.Script; import org.elasticsearch.script.TermsSetQueryScript; @@ -438,7 +438,7 @@ public int hashCode() { @Override public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { - SortedNumericDocValues values = fieldData.load(ctx).getLongValues(); + SortedNumericLongValues values = fieldData.load(ctx).getLongValues(); return new LongValues() { long current = -1; diff --git a/server/src/main/java/org/elasticsearch/script/SortedNumericDocValuesLongFieldScript.java b/server/src/main/java/org/elasticsearch/script/SortedNumericDocValuesLongFieldScript.java index d4ede3827092a..6801a939754e6 100644 --- a/server/src/main/java/org/elasticsearch/script/SortedNumericDocValuesLongFieldScript.java +++ b/server/src/main/java/org/elasticsearch/script/SortedNumericDocValuesLongFieldScript.java @@ -11,6 +11,7 @@ import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.OnScriptError; import org.elasticsearch.script.field.LongDocValuesField; import org.elasticsearch.search.lookup.SearchLookup; @@ -25,7 +26,10 @@ public class SortedNumericDocValuesLongFieldScript extends AbstractLongFieldScri public SortedNumericDocValuesLongFieldScript(String fieldName, SearchLookup lookup, LeafReaderContext ctx) { super(fieldName, Map.of(), lookup, OnScriptError.FAIL, ctx); try { - longDocValuesField = new LongDocValuesField(DocValues.getSortedNumeric(ctx.reader(), fieldName), fieldName); + longDocValuesField = new LongDocValuesField( + SortedNumericLongValues.wrap(DocValues.getSortedNumeric(ctx.reader(), fieldName)), + fieldName + ); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } diff --git a/server/src/main/java/org/elasticsearch/script/field/AbstractLongDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/AbstractLongDocValuesField.java index 1d54bfb4e701b..e9f7e641f9c12 100644 --- a/server/src/main/java/org/elasticsearch/script/field/AbstractLongDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/AbstractLongDocValuesField.java @@ -9,9 +9,9 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.ArrayUtil; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.util.NoSuchElementException; @@ -28,11 +28,11 @@ public abstract class AbstractLongDocValuesField extends AbstractScriptFieldFact // as a delegate to this field class protected ScriptDocValues scriptDocValues = null; - protected final SortedNumericDocValues input; + protected final SortedNumericLongValues input; protected long[] values = new long[0]; protected int count; - public AbstractLongDocValuesField(SortedNumericDocValues input, String name) { + public AbstractLongDocValuesField(SortedNumericLongValues input, String name) { this.input = input; this.name = name; } diff --git a/server/src/main/java/org/elasticsearch/script/field/BooleanDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/BooleanDocValuesField.java index cd63f665a98db..5dfbb06a55f6f 100644 --- a/server/src/main/java/org/elasticsearch/script/field/BooleanDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/BooleanDocValuesField.java @@ -9,9 +9,9 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.ArrayUtil; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.util.Arrays; @@ -24,7 +24,7 @@ public class BooleanDocValuesField extends AbstractScriptFieldFactory DocValuesScriptFieldFactory, ScriptDocValues.Supplier { - private final SortedNumericDocValues input; + private final SortedNumericLongValues input; private final String name; private boolean[] values = new boolean[0]; @@ -34,7 +34,7 @@ public class BooleanDocValuesField extends AbstractScriptFieldFactory // as a delegate to this field class private ScriptDocValues.Booleans booleans = null; - public BooleanDocValuesField(SortedNumericDocValues input, String name) { + public BooleanDocValuesField(SortedNumericLongValues input, String name) { this.input = input; this.name = name; } diff --git a/server/src/main/java/org/elasticsearch/script/field/ByteDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/ByteDocValuesField.java index 4dfbb379601f9..972e3e5c080f2 100644 --- a/server/src/main/java/org/elasticsearch/script/field/ByteDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/ByteDocValuesField.java @@ -9,9 +9,9 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.ArrayUtil; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.util.Iterator; @@ -23,7 +23,7 @@ public class ByteDocValuesField extends AbstractScriptFieldFactory DocValuesScriptFieldFactory, ScriptDocValues.Supplier { - protected final SortedNumericDocValues input; + protected final SortedNumericLongValues input; protected final String name; protected byte[] values = new byte[0]; @@ -31,7 +31,7 @@ public class ByteDocValuesField extends AbstractScriptFieldFactory private ScriptDocValues.Longs longs = null; - public ByteDocValuesField(SortedNumericDocValues input, String name) { + public ByteDocValuesField(SortedNumericLongValues input, String name) { this.input = input; this.name = name; } diff --git a/server/src/main/java/org/elasticsearch/script/field/DateMillisDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/DateMillisDocValuesField.java index 366a8a9044bbe..648d364265425 100644 --- a/server/src/main/java/org/elasticsearch/script/field/DateMillisDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/DateMillisDocValuesField.java @@ -9,9 +9,9 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.ArrayUtil; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.time.Instant; @@ -26,7 +26,7 @@ public class DateMillisDocValuesField extends AbstractScriptFieldFactory { - protected final SortedNumericDocValues input; + protected final SortedNumericLongValues input; protected final String name; protected ZonedDateTime[] values = new ZonedDateTime[0]; @@ -34,7 +34,7 @@ public class DateMillisDocValuesField extends AbstractScriptFieldFactory { - protected final SortedNumericDocValues input; + protected final SortedNumericLongValues input; protected final String name; protected ZonedDateTime[] values = new ZonedDateTime[0]; @@ -34,7 +34,7 @@ public class DateNanosDocValuesField extends AbstractScriptFieldFactory DocValuesScriptFieldFactory, ScriptDocValues.Supplier { - protected final SortedNumericDocValues input; + protected final SortedNumericLongValues input; protected final String name; protected int[] values = new int[0]; @@ -31,7 +31,7 @@ public class IntegerDocValuesField extends AbstractScriptFieldFactory private ScriptDocValues.Longs longs = null; - public IntegerDocValuesField(SortedNumericDocValues input, String name) { + public IntegerDocValuesField(SortedNumericLongValues input, String name) { this.input = input; this.name = name; } diff --git a/server/src/main/java/org/elasticsearch/script/field/LongDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/LongDocValuesField.java index a2795aaa2f569..c770863aebf49 100644 --- a/server/src/main/java/org/elasticsearch/script/field/LongDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/LongDocValuesField.java @@ -9,11 +9,11 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; public class LongDocValuesField extends AbstractLongDocValuesField { - public LongDocValuesField(SortedNumericDocValues input, String name) { + public LongDocValuesField(SortedNumericLongValues input, String name) { super(input, name); } } diff --git a/server/src/main/java/org/elasticsearch/script/field/SeqNoDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/SeqNoDocValuesField.java index 5b26dcec6a2bc..a04c502c5359c 100644 --- a/server/src/main/java/org/elasticsearch/script/field/SeqNoDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/SeqNoDocValuesField.java @@ -9,10 +9,10 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; public class SeqNoDocValuesField extends AbstractLongDocValuesField { - public SeqNoDocValuesField(SortedNumericDocValues input, String name) { + public SeqNoDocValuesField(SortedNumericLongValues input, String name) { super(input, name); } } diff --git a/server/src/main/java/org/elasticsearch/script/field/ShortDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/ShortDocValuesField.java index f75e7f7c50316..b0fe12d62575e 100644 --- a/server/src/main/java/org/elasticsearch/script/field/ShortDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/ShortDocValuesField.java @@ -9,9 +9,9 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.ArrayUtil; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.util.Iterator; @@ -23,7 +23,7 @@ public class ShortDocValuesField extends AbstractScriptFieldFactory DocValuesScriptFieldFactory, ScriptDocValues.Supplier { - protected final SortedNumericDocValues input; + protected final SortedNumericLongValues input; protected final String name; protected short[] values = new short[0]; @@ -31,7 +31,7 @@ public class ShortDocValuesField extends AbstractScriptFieldFactory private ScriptDocValues.Longs longs = null; - public ShortDocValuesField(SortedNumericDocValues input, String name) { + public ShortDocValuesField(SortedNumericLongValues input, String name) { this.input = input; this.name = name; } diff --git a/server/src/main/java/org/elasticsearch/script/field/VersionDocValuesField.java b/server/src/main/java/org/elasticsearch/script/field/VersionDocValuesField.java index 80dffbb8ceb45..9b8e49d79ca73 100644 --- a/server/src/main/java/org/elasticsearch/script/field/VersionDocValuesField.java +++ b/server/src/main/java/org/elasticsearch/script/field/VersionDocValuesField.java @@ -9,10 +9,10 @@ package org.elasticsearch.script.field; -import org.apache.lucene.index.SortedNumericDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; public class VersionDocValuesField extends AbstractLongDocValuesField { - public VersionDocValuesField(SortedNumericDocValues input, String name) { + public VersionDocValuesField(SortedNumericLongValues input, String name) { super(input, name); } } diff --git a/server/src/main/java/org/elasticsearch/search/MultiValueMode.java b/server/src/main/java/org/elasticsearch/search/MultiValueMode.java index 5ac25fe0ff695..1126898341afb 100644 --- a/server/src/main/java/org/elasticsearch/search/MultiValueMode.java +++ b/server/src/main/java/org/elasticsearch/search/MultiValueMode.java @@ -13,9 +13,9 @@ import org.apache.lucene.index.DocValues; import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.SortedDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.search.DocIdSetIterator; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.BitSet; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; @@ -23,12 +23,12 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.index.fielddata.AbstractBinaryDocValues; -import org.elasticsearch.index.fielddata.AbstractNumericDocValues; import org.elasticsearch.index.fielddata.AbstractSortedDocValues; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.util.Locale; @@ -42,7 +42,7 @@ public enum MultiValueMode implements Writeable { */ SUM { @Override - protected long pick(SortedNumericDocValues values) throws IOException { + protected long pick(SortedNumericLongValues values) throws IOException { final int count = values.docValueCount(); long total = 0; for (int index = 0; index < count; ++index) { @@ -53,7 +53,7 @@ protected long pick(SortedNumericDocValues values) throws IOException { @Override protected long pick( - SortedNumericDocValues values, + SortedNumericLongValues values, long missingValue, DocIdSetIterator docItr, int startDoc, @@ -123,7 +123,7 @@ protected double pick( */ AVG { @Override - protected long pick(SortedNumericDocValues values) throws IOException { + protected long pick(SortedNumericLongValues values) throws IOException { final int count = values.docValueCount(); long total = 0; for (int index = 0; index < count; ++index) { @@ -134,7 +134,7 @@ protected long pick(SortedNumericDocValues values) throws IOException { @Override protected long pick( - SortedNumericDocValues values, + SortedNumericLongValues values, long missingValue, DocIdSetIterator docItr, int startDoc, @@ -208,7 +208,7 @@ protected double pick( */ MEDIAN { @Override - protected long pick(SortedNumericDocValues values) throws IOException { + protected long pick(SortedNumericLongValues values) throws IOException { int count = values.docValueCount(); for (int i = 0; i < (count - 1) / 2; ++i) { values.nextValue(); @@ -239,13 +239,13 @@ protected double pick(SortedNumericDoubleValues values) throws IOException { */ MIN { @Override - protected long pick(SortedNumericDocValues values) throws IOException { + protected long pick(SortedNumericLongValues values) throws IOException { return values.nextValue(); } @Override protected long pick( - SortedNumericDocValues values, + SortedNumericLongValues values, long missingValue, DocIdSetIterator docItr, int startDoc, @@ -362,7 +362,7 @@ protected int pick(SortedDocValues values, DocIdSetIterator docItr, int startDoc */ MAX { @Override - protected long pick(SortedNumericDocValues values) throws IOException { + protected long pick(SortedNumericLongValues values) throws IOException { final int count = values.docValueCount(); for (int i = 0; i < count - 1; ++i) { values.nextValue(); @@ -372,7 +372,7 @@ protected long pick(SortedNumericDocValues values) throws IOException { @Override protected long pick( - SortedNumericDocValues values, + SortedNumericLongValues values, long missingValue, DocIdSetIterator docItr, int startDoc, @@ -520,12 +520,12 @@ public static MultiValueMode fromString(String sortMode) { * * Allowed Modes: SUM, AVG, MEDIAN, MIN, MAX */ - public NumericDocValues select(final SortedNumericDocValues values) { - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + public LongValues select(final SortedNumericLongValues values) { + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); if (singleton != null) { return singleton; } else { - return new AbstractNumericDocValues() { + return new LongValues() { private long value; @@ -538,11 +538,6 @@ public boolean advanceExact(int target) throws IOException { return false; } - @Override - public int docID() { - return values.docID(); - } - @Override public long longValue() { return value; @@ -551,7 +546,7 @@ public long longValue() { } } - protected long pick(SortedNumericDocValues values) throws IOException { + protected long pick(SortedNumericLongValues values) throws IOException { throw new IllegalArgumentException("Unsupported sort mode: " + this); } @@ -567,18 +562,18 @@ protected long pick(SortedNumericDocValues values) throws IOException { * NOTE: Calling the returned instance on docs that are not root docs is illegal * The returned instance can only be evaluate the current and upcoming docs */ - public NumericDocValues select( - final SortedNumericDocValues values, + public LongValues select( + final SortedNumericLongValues values, final long missingValue, final BitSet parentDocs, final DocIdSetIterator childDocs, int maxChildren ) throws IOException { if (parentDocs == null || childDocs == null) { - return FieldData.replaceMissing(DocValues.emptyNumeric(), missingValue); + return FieldData.replaceMissing(FieldData.EMPTY, missingValue); } - return new AbstractNumericDocValues() { + return new LongValues() { int lastSeenParentDoc = -1; long lastEmittedValue = missingValue; @@ -600,11 +595,6 @@ public boolean advanceExact(int parentDoc) throws IOException { return true; } - @Override - public int docID() { - return lastSeenParentDoc; - } - @Override public long longValue() { return lastEmittedValue; @@ -613,7 +603,7 @@ public long longValue() { } protected long pick( - SortedNumericDocValues values, + SortedNumericLongValues values, long missingValue, DocIdSetIterator docItr, int startDoc, diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileValuesSource.java index 535e7c49beb6d..e499f62f93bbb 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/GeoTileValuesSource.java @@ -10,9 +10,9 @@ package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.core.CheckedFunction; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.search.DocValueFormat; @@ -29,7 +29,7 @@ class GeoTileValuesSource extends LongValuesSource { GeoTileValuesSource( BigArrays bigArrays, MappedFieldType fieldType, - CheckedFunction docValuesFunc, + CheckedFunction docValuesFunc, LongUnaryOperator rounding, DocValueFormat format, boolean missingBucket, diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSource.java index b24b453078960..50c8609224909 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/HistogramValuesSource.java @@ -10,10 +10,10 @@ package org.elasticsearch.search.aggregations.bucket.composite; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.aggregations.support.ValuesSource; import java.io.IOException; @@ -86,7 +86,7 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext context) throws IOExc } @Override - public SortedNumericDocValues longValues(LeafReaderContext context) throws IOException { + public SortedNumericLongValues longValues(LeafReaderContext context) throws IOException { throw new UnsupportedOperationException("not applicable"); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java index 0e30a4cec3fc4..aa7071708774e 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/LongValuesSource.java @@ -11,15 +11,13 @@ import org.apache.lucene.document.IntPoint; import org.apache.lucene.document.LongPoint; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.FieldExistsQuery; import org.apache.lucene.search.IndexOrDocValuesQuery; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.PointRangeQuery; import org.apache.lucene.search.Query; @@ -28,6 +26,7 @@ import org.elasticsearch.common.util.LongArray; import org.elasticsearch.core.CheckedFunction; import org.elasticsearch.core.Releasables; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.NumberFieldMapper; @@ -43,7 +42,7 @@ */ class LongValuesSource extends SingleDimensionValuesSource { private final BigArrays bigArrays; - private final CheckedFunction docValuesFunc; + private final CheckedFunction docValuesFunc; private final LongUnaryOperator rounding; private final BitArray bits; @@ -54,7 +53,7 @@ class LongValuesSource extends SingleDimensionValuesSource { LongValuesSource( BigArrays bigArrays, MappedFieldType fieldType, - CheckedFunction docValuesFunc, + CheckedFunction docValuesFunc, LongUnaryOperator rounding, DocValueFormat format, boolean missingBucket, @@ -172,12 +171,12 @@ Long toComparable(int slot) { @Override LeafBucketCollector getLeafCollector(LeafReaderContext context, LeafBucketCollector next) throws IOException { - final SortedNumericDocValues dvs = docValuesFunc.apply(context); - final NumericDocValues singleton = DocValues.unwrapSingleton(dvs); + final SortedNumericLongValues dvs = docValuesFunc.apply(context); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(dvs); return singleton != null ? getLeafCollector(singleton, next) : getLeafCollector(dvs, next); } - private LeafBucketCollector getLeafCollector(SortedNumericDocValues dvs, LeafBucketCollector next) { + private LeafBucketCollector getLeafCollector(SortedNumericLongValues dvs, LeafBucketCollector next) { return new LeafBucketCollector() { @Override public void collect(int doc, long bucket) throws IOException { @@ -200,7 +199,7 @@ public void collect(int doc, long bucket) throws IOException { }; } - private LeafBucketCollector getLeafCollector(NumericDocValues dvs, LeafBucketCollector next) { + private LeafBucketCollector getLeafCollector(LongValues dvs, LeafBucketCollector next) { return new LeafBucketCollector() { @Override public void collect(int doc, long bucket) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/RoundingValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/RoundingValuesSource.java index ff6900b4d2fc5..4208a7aca8e92 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/RoundingValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/RoundingValuesSource.java @@ -9,13 +9,12 @@ package org.elasticsearch.search.aggregations.bucket.composite; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.Rounding; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.aggregations.support.ValuesSource; import java.io.IOException; @@ -56,14 +55,14 @@ public double roundingSize(Rounding.DateTimeUnit unit) { } @Override - public SortedNumericDocValues longValues(LeafReaderContext context) throws IOException { - final SortedNumericDocValues values = vs.longValues(context); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); - return singleton != null ? DocValues.singleton(longSingleValues(singleton)) : longMultiValues(values); + public SortedNumericLongValues longValues(LeafReaderContext context) throws IOException { + final SortedNumericLongValues values = vs.longValues(context); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); + return singleton != null ? SortedNumericLongValues.singleton(longSingleValues(singleton)) : longMultiValues(values); } - private SortedNumericDocValues longMultiValues(SortedNumericDocValues values) { - return new SortedNumericDocValues() { + private SortedNumericLongValues longMultiValues(SortedNumericLongValues values) { + return new SortedNumericLongValues() { @Override public long nextValue() throws IOException { return round(values.nextValue()); @@ -78,31 +77,11 @@ public int docValueCount() { public boolean advanceExact(int target) throws IOException { return values.advanceExact(target); } - - @Override - public int docID() { - return values.docID(); - } - - @Override - public int nextDoc() throws IOException { - return values.nextDoc(); - } - - @Override - public int advance(int target) throws IOException { - return values.advance(target); - } - - @Override - public long cost() { - return values.cost(); - } }; } - private NumericDocValues longSingleValues(NumericDocValues values) { - return new NumericDocValues() { + private LongValues longSingleValues(LongValues values) { + return new LongValues() { @Override public long longValue() throws IOException { return round(values.longValue()); @@ -112,26 +91,6 @@ public long longValue() throws IOException { public boolean advanceExact(int target) throws IOException { return values.advanceExact(target); } - - @Override - public int docID() { - return values.docID(); - } - - @Override - public int nextDoc() throws IOException { - return values.nextDoc(); - } - - @Override - public int advance(int target) throws IOException { - return values.advance(target); - } - - @Override - public long cost() { - return values.cost(); - } }; } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/CellIdSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/CellIdSource.java index 9a1256a0c1f58..9fc8c2df42760 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/CellIdSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/CellIdSource.java @@ -9,17 +9,15 @@ package org.elasticsearch.search.aggregations.bucket.geogrid; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.geo.GeoBoundingBox; -import org.elasticsearch.index.fielddata.AbstractNumericDocValues; -import org.elasticsearch.index.fielddata.AbstractSortingNumericDocValues; import org.elasticsearch.index.fielddata.GeoPointValues; import org.elasticsearch.index.fielddata.MultiGeoPointValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; +import org.elasticsearch.index.fielddata.SortingNumericLongValues; import org.elasticsearch.search.aggregations.support.ValuesSource; import java.io.IOException; @@ -56,37 +54,39 @@ public final boolean isFloatingPoint() { } @Override - public final SortedNumericDocValues longValues(LeafReaderContext ctx) { + public final SortedNumericLongValues longValues(LeafReaderContext ctx) { final MultiGeoPointValues multiGeoPointValues = valuesSource.geoPointValues(ctx); final GeoPointValues values = org.elasticsearch.index.fielddata.FieldData.unwrapSingleton(multiGeoPointValues); if (geoBoundingBox.isUnbounded()) { - return values == null ? unboundedCellMultiValues(multiGeoPointValues) : DocValues.singleton(unboundedCellSingleValue(values)); + return values == null + ? unboundedCellMultiValues(multiGeoPointValues) + : SortedNumericLongValues.singleton(unboundedCellSingleValue(values)); } else { return values == null ? boundedCellMultiValues(multiGeoPointValues, geoBoundingBox) - : DocValues.singleton(boundedCellSingleValue(values, geoBoundingBox)); + : SortedNumericLongValues.singleton(boundedCellSingleValue(values, geoBoundingBox)); } } /** * Generate an unbounded iterator of grid-cells for singleton case. */ - protected abstract NumericDocValues unboundedCellSingleValue(GeoPointValues values); + protected abstract LongValues unboundedCellSingleValue(GeoPointValues values); /** * Generate a bounded iterator of grid-cells for singleton case. */ - protected abstract NumericDocValues boundedCellSingleValue(GeoPointValues values, GeoBoundingBox boundingBox); + protected abstract LongValues boundedCellSingleValue(GeoPointValues values, GeoBoundingBox boundingBox); /** * Generate an unbounded iterator of grid-cells for multi-value case. */ - protected abstract SortedNumericDocValues unboundedCellMultiValues(MultiGeoPointValues values); + protected abstract SortedNumericLongValues unboundedCellMultiValues(MultiGeoPointValues values); /** * Generate a bounded iterator of grid-cells for multi-value case. */ - protected abstract SortedNumericDocValues boundedCellMultiValues(MultiGeoPointValues values, GeoBoundingBox boundingBox); + protected abstract SortedNumericLongValues boundedCellMultiValues(MultiGeoPointValues values, GeoBoundingBox boundingBox); @Override public final SortedNumericDoubleValues doubleValues(LeafReaderContext ctx) { @@ -120,7 +120,7 @@ protected boolean pointInBounds(double lon, double lat) { * the multi-value geo-doc-values. Class must encode the values and then * sort them in order to account for the cells correctly. */ - protected abstract static class CellMultiValues extends AbstractSortingNumericDocValues { + protected abstract static class CellMultiValues extends SortingNumericLongValues { private final MultiGeoPointValues geoValues; protected final int precision; @@ -162,7 +162,7 @@ public boolean advanceExact(int docId) throws IOException { * Class representing the long-encoded grid-cells belonging to * the singleton geo-doc-values. */ - protected abstract static class CellSingleValue extends AbstractNumericDocValues { + protected abstract static class CellSingleValue extends LongValues { private final GeoPointValues geoValues; protected final int precision; protected long value; @@ -191,10 +191,5 @@ public long longValue() throws IOException { * @return true if the value needs to be added, otherwise false. */ protected abstract boolean advance(org.elasticsearch.common.geo.GeoPoint target); - - @Override - public int docID() { - return -1; - } } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregator.java index b84dff6e73e0b..8259aa40c0346 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregator.java @@ -8,14 +8,13 @@ */ package org.elasticsearch.search.aggregations.bucket.geogrid; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.elasticsearch.common.util.IntArray; import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.ObjectArray; import org.elasticsearch.core.Releasables; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.aggregations.AggregationExecutionContext; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; @@ -77,12 +76,12 @@ public ScoreMode scoreMode() { @Override public LeafBucketCollector getLeafCollector(final AggregationExecutionContext aggCtx, final LeafBucketCollector sub) throws IOException { - final SortedNumericDocValues values = valuesSource.longValues(aggCtx.getLeafReaderContext()); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = valuesSource.longValues(aggCtx.getLeafReaderContext()); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); return singleton != null ? getLeafCollector(singleton, sub) : getLeafCollector(values, sub); } - private LeafBucketCollector getLeafCollector(final NumericDocValues values, final LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(final LongValues values, final LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, null) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -100,7 +99,7 @@ public void collect(int doc, long owningBucketOrd) throws IOException { }; } - private LeafBucketCollector getLeafCollector(final SortedNumericDocValues values, final LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(final SortedNumericLongValues values, final LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, null) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashCellIdSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashCellIdSource.java index ddb6e5671f013..6c4cbd356703f 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashCellIdSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashCellIdSource.java @@ -8,12 +8,12 @@ */ package org.elasticsearch.search.aggregations.bucket.geogrid; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.geo.GeoBoundingBox; import org.elasticsearch.geometry.utils.Geohash; import org.elasticsearch.index.fielddata.GeoPointValues; import org.elasticsearch.index.fielddata.MultiGeoPointValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.aggregations.support.ValuesSource; import java.util.function.LongConsumer; @@ -33,7 +33,7 @@ public GeoHashCellIdSource( } @Override - protected NumericDocValues unboundedCellSingleValue(GeoPointValues values) { + protected LongValues unboundedCellSingleValue(GeoPointValues values) { return new CellSingleValue(values, precision()) { @Override protected boolean advance(org.elasticsearch.common.geo.GeoPoint target) { @@ -44,7 +44,7 @@ protected boolean advance(org.elasticsearch.common.geo.GeoPoint target) { } @Override - protected NumericDocValues boundedCellSingleValue(GeoPointValues values, GeoBoundingBox boundingBox) { + protected LongValues boundedCellSingleValue(GeoPointValues values, GeoBoundingBox boundingBox) { final GeoHashBoundedPredicate predicate = new GeoHashBoundedPredicate(precision(), boundingBox); return new CellSingleValue(values, precision()) { @Override @@ -60,7 +60,7 @@ protected boolean advance(org.elasticsearch.common.geo.GeoPoint target) { } @Override - protected SortedNumericDocValues unboundedCellMultiValues(MultiGeoPointValues values) { + protected SortedNumericLongValues unboundedCellMultiValues(MultiGeoPointValues values) { return new CellMultiValues(values, precision(), circuitBreakerConsumer) { @Override protected int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx) { @@ -71,7 +71,7 @@ protected int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int val } @Override - protected SortedNumericDocValues boundedCellMultiValues(MultiGeoPointValues values, GeoBoundingBox boundingBox) { + protected SortedNumericLongValues boundedCellMultiValues(MultiGeoPointValues values, GeoBoundingBox boundingBox) { final GeoHashBoundedPredicate predicate = new GeoHashBoundedPredicate(precision(), boundingBox); return new CellMultiValues(values, precision(), circuitBreakerConsumer) { @Override diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileCellIdSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileCellIdSource.java index 5b63841a5b286..214c9acde6903 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileCellIdSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileCellIdSource.java @@ -8,11 +8,11 @@ */ package org.elasticsearch.search.aggregations.bucket.geogrid; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.geo.GeoBoundingBox; import org.elasticsearch.index.fielddata.GeoPointValues; import org.elasticsearch.index.fielddata.MultiGeoPointValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.util.function.LongConsumer; @@ -26,7 +26,7 @@ public GeoTileCellIdSource(GeoPoint valuesSource, int precision, GeoBoundingBox } @Override - protected NumericDocValues unboundedCellSingleValue(GeoPointValues values) { + protected LongValues unboundedCellSingleValue(GeoPointValues values) { return new CellSingleValue(values, precision()) { @Override protected boolean advance(org.elasticsearch.common.geo.GeoPoint target) { @@ -37,7 +37,7 @@ protected boolean advance(org.elasticsearch.common.geo.GeoPoint target) { } @Override - protected NumericDocValues boundedCellSingleValue(GeoPointValues values, GeoBoundingBox boundingBox) { + protected LongValues boundedCellSingleValue(GeoPointValues values, GeoBoundingBox boundingBox) { final GeoTileBoundedPredicate predicate = new GeoTileBoundedPredicate(precision(), boundingBox); final int tiles = 1 << precision(); return new CellSingleValue(values, precision()) { @@ -55,7 +55,7 @@ protected boolean advance(org.elasticsearch.common.geo.GeoPoint target) { } @Override - protected SortedNumericDocValues unboundedCellMultiValues(MultiGeoPointValues values) { + protected SortedNumericLongValues unboundedCellMultiValues(MultiGeoPointValues values) { return new CellMultiValues(values, precision(), circuitBreakerConsumer) { @Override protected int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx) { @@ -66,7 +66,7 @@ protected int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int val } @Override - protected SortedNumericDocValues boundedCellMultiValues(MultiGeoPointValues values, GeoBoundingBox boundingBox) { + protected SortedNumericLongValues boundedCellMultiValues(MultiGeoPointValues values, GeoBoundingBox boundingBox) { final GeoTileBoundedPredicate predicate = new GeoTileBoundedPredicate(precision(), boundingBox); final int tiles = 1 << precision(); return new CellMultiValues(values, precision(), circuitBreakerConsumer) { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java index 1eb0226ad8c8c..5b9febac9a452 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregator.java @@ -10,9 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.common.Rounding; @@ -21,6 +19,7 @@ import org.elasticsearch.core.CheckedFunction; import org.elasticsearch.core.Nullable; import org.elasticsearch.core.Releasables; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AdaptingAggregator; import org.elasticsearch.search.aggregations.AggregationExecutionContext; @@ -289,12 +288,12 @@ public LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx, if (valuesSource == null) { return LeafBucketCollector.NO_OP_COLLECTOR; } - final SortedNumericDocValues values = valuesSource.longValues(aggCtx.getLeafReaderContext()); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = valuesSource.longValues(aggCtx.getLeafReaderContext()); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); return singleton != null ? getLeafCollector(singleton, sub) : getLeafCollector(values, sub); } - private LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(SortedNumericLongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -314,7 +313,7 @@ public void collect(int doc, long owningBucketOrd) throws IOException { }; } - private LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(LongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java index 4972fd19688c4..ac66e6e19adfb 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/GeoDistanceRangeAggregatorFactory.java @@ -10,7 +10,6 @@ package org.elasticsearch.search.aggregations.bucket.range; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoUtils; @@ -18,6 +17,7 @@ import org.elasticsearch.index.fielddata.MultiGeoPointValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.AggregatorFactory; @@ -159,7 +159,7 @@ public boolean isFloatingPoint() { } @Override - public SortedNumericDocValues longValues(LeafReaderContext ctx) { + public SortedNumericLongValues longValues(LeafReaderContext ctx) { throw new UnsupportedOperationException(); } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedNumericSamplerAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedNumericSamplerAggregator.java index c8805452b7334..c1b3b893fe4bf 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedNumericSamplerAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedNumericSamplerAggregator.java @@ -11,11 +11,11 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.misc.search.DiversifiedTopDocsCollector; import org.apache.lucene.search.TopDocsCollector; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.index.fielddata.AbstractNumericDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.bucket.DeferringBucketCollector; @@ -82,7 +82,7 @@ protected long getPriorityQueueSlotSize() { // a lookup from elasticsearch's ValuesSource class ValuesDiversifiedTopDocsCollector extends DiversifiedTopDocsCollector { - private SortedNumericDocValues values; + private SortedNumericLongValues values; ValuesDiversifiedTopDocsCollector(int numHits, int maxHitsPerKey) { super(numHits, maxHitsPerKey); @@ -111,7 +111,8 @@ public boolean advanceExact(int target) throws IOException { @Override public int docID() { - return values.docID(); + // TODO this can actually be a LongValues in the lucene class + throw new UnsupportedOperationException(); } @Override diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongRareTermsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongRareTermsAggregator.java index 45ea1245ec38d..eaa7ed5955b69 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongRareTermsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongRareTermsAggregator.java @@ -8,15 +8,14 @@ */ package org.elasticsearch.search.aggregations.bucket.terms; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.common.util.LongArray; import org.elasticsearch.common.util.LongHash; import org.elasticsearch.common.util.ObjectArray; import org.elasticsearch.common.util.SetBackedScalingCuckooFilter; import org.elasticsearch.core.Releasables; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregationExecutionContext; import org.elasticsearch.search.aggregations.Aggregator; @@ -65,18 +64,18 @@ public class LongRareTermsAggregator extends AbstractRareTermsAggregator { this.bucketOrds = LongKeyedBucketOrds.build(bigArrays(), cardinality); } - protected static SortedNumericDocValues getValues(ValuesSource.Numeric valuesSource, LeafReaderContext ctx) throws IOException { + protected static SortedNumericLongValues getValues(ValuesSource.Numeric valuesSource, LeafReaderContext ctx) throws IOException { return valuesSource.longValues(ctx); } @Override public LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx, LeafBucketCollector sub) throws IOException { - final SortedNumericDocValues values = getValues(valuesSource, aggCtx.getLeafReaderContext()); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = getValues(valuesSource, aggCtx.getLeafReaderContext()); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); return singleton != null ? getLeafCollector(singleton, sub) : getLeafCollector(values, sub); } - private LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(SortedNumericLongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int docId, long owningBucketOrd) throws IOException { @@ -95,7 +94,7 @@ public void collect(int docId, long owningBucketOrd) throws IOException { }; } - private LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(LongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int docId, long owningBucketOrd) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/NumericTermsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/NumericTermsAggregator.java index a54053f712f8d..3bee48b6ede3a 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/NumericTermsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/NumericTermsAggregator.java @@ -8,10 +8,8 @@ */ package org.elasticsearch.search.aggregations.bucket.terms; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.common.util.IntArray; @@ -21,6 +19,7 @@ import org.elasticsearch.core.Releasable; import org.elasticsearch.core.Releasables; import org.elasticsearch.index.fielddata.FieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregationExecutionContext; import org.elasticsearch.search.aggregations.Aggregator; @@ -90,12 +89,12 @@ public ScoreMode scoreMode() { @Override public LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx, LeafBucketCollector sub) throws IOException { - final SortedNumericDocValues values = resultStrategy.getValues(aggCtx.getLeafReaderContext()); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = resultStrategy.getValues(aggCtx.getLeafReaderContext()); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); return resultStrategy.wrapCollector(singleton != null ? getLeafCollector(singleton, sub) : getLeafCollector(values, sub)); } - private LeafBucketCollector getLeafCollector(SortedNumericDocValues values, LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(SortedNumericLongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -113,7 +112,7 @@ public void collect(int doc, long owningBucketOrd) throws IOException { }; } - private LeafBucketCollector getLeafCollector(NumericDocValues values, LeafBucketCollector sub) { + private LeafBucketCollector getLeafCollector(LongValues values, LeafBucketCollector sub) { return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long owningBucketOrd) throws IOException { @@ -235,7 +234,7 @@ private InternalAggregation[] buildAggregations(LongArray owningBucketOrds) thro /** * Resolve the doc values to collect results of this type. */ - abstract SortedNumericDocValues getValues(LeafReaderContext ctx) throws IOException; + abstract SortedNumericLongValues getValues(LeafReaderContext ctx) throws IOException; /** * Wrap the "standard" numeric terms collector to collect any more @@ -335,7 +334,7 @@ final void collectZeroDocEntriesIfNeeded(long owningBucketOrd, boolean excludeDe } // we need to fill-in the blanks for (LeafReaderContext ctx : searcher().getTopReaderContext().leaves()) { - SortedNumericDocValues values = getValues(ctx); + SortedNumericLongValues values = getValues(ctx); for (int docId = 0; docId < ctx.reader().maxDoc(); ++docId) { if (excludeDeletedDocs && ctx.reader().getLiveDocs() != null && ctx.reader().getLiveDocs().get(docId) == false) { continue; @@ -368,7 +367,7 @@ String describe() { } @Override - SortedNumericDocValues getValues(LeafReaderContext ctx) throws IOException { + SortedNumericLongValues getValues(LeafReaderContext ctx) throws IOException { return valuesSource.longValues(ctx); } @@ -451,7 +450,7 @@ String describe() { } @Override - SortedNumericDocValues getValues(LeafReaderContext ctx) throws IOException { + SortedNumericLongValues getValues(LeafReaderContext ctx) throws IOException { return FieldData.toSortableLongBits(valuesSource.doubleValues(ctx)); } @@ -548,7 +547,7 @@ class SignificantLongTermsResults extends ResultStrategy"narrowed" * but they'll accurately represent values up to {@link Long#MAX_VALUE}. */ - public abstract SortedNumericDocValues longValues(LeafReaderContext context) throws IOException; + public abstract SortedNumericLongValues longValues(LeafReaderContext context) throws IOException; /** * Get a double precision floating point view into the values in this leaf. @@ -482,7 +483,7 @@ public DocValueBits docsWithValue(LeafReaderContext context) throws IOException final SortedNumericDoubleValues values = doubleValues(context); return org.elasticsearch.index.fielddata.FieldData.docsWithValue(values); } else { - final SortedNumericDocValues values = longValues(context); + final SortedNumericLongValues values = longValues(context); return org.elasticsearch.index.fielddata.FieldData.docsWithValue(values); } } @@ -521,7 +522,7 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext context) throws IOExc } @Override - public SortedNumericDocValues longValues(LeafReaderContext context) throws IOException { + public SortedNumericLongValues longValues(LeafReaderContext context) throws IOException { return new LongValues(delegate.longValues(context), script.newInstance(context)); } @@ -530,12 +531,12 @@ public SortedNumericDoubleValues doubleValues(LeafReaderContext context) throws return new DoubleValues(delegate.doubleValues(context), script.newInstance(context)); } - static class LongValues extends AbstractSortingNumericDocValues implements ScorerAware { + static class LongValues extends SortingNumericLongValues implements ScorerAware { - private final SortedNumericDocValues longValues; + private final SortedNumericLongValues longValues; private final AggregationScript script; - LongValues(SortedNumericDocValues values, AggregationScript script) { + LongValues(SortedNumericLongValues values, AggregationScript script) { this.longValues = values; this.script = script; } @@ -612,7 +613,7 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext context) { } @Override - public SortedNumericDocValues longValues(LeafReaderContext context) { + public SortedNumericLongValues longValues(LeafReaderContext context) { return indexFieldData.load(context).getLongValues(); } @@ -640,7 +641,7 @@ public boolean isFloatingPoint() { } @Override - public SortedNumericDocValues longValues(LeafReaderContext context) throws IOException { + public SortedNumericLongValues longValues(LeafReaderContext context) throws IOException { return new ScriptLongValues(script.newInstance(context)); } @@ -705,8 +706,8 @@ public abstract static class GeoPoint extends ValuesSource { public static final GeoPoint EMPTY = new GeoPoint() { @Override - public SortedNumericDocValues geoSortedNumericDocValues(LeafReaderContext context) { - return DocValues.emptySortedNumeric(); + public SortedNumericLongValues geoSortedNumericDocValues(LeafReaderContext context) { + return SortedNumericLongValues.EMPTY; } @Override @@ -739,7 +740,7 @@ public final MultiGeoPointValues geoPointValues(LeafReaderContext context) { * A point is encoded as a long that can be decoded by using * {@link org.elasticsearch.common.geo.GeoPoint#resetFromEncoded(long)} */ - public abstract SortedNumericDocValues geoSortedNumericDocValues(LeafReaderContext context); + public abstract SortedNumericLongValues geoSortedNumericDocValues(LeafReaderContext context); public static class Fielddata extends GeoPoint { @@ -755,8 +756,8 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext context) { } @Override - public SortedNumericDocValues geoSortedNumericDocValues(LeafReaderContext context) { - return indexFieldData.load(context).getSortedNumericDocValues(); + public SortedNumericLongValues geoSortedNumericDocValues(LeafReaderContext context) { + return indexFieldData.load(context).getSortedNumericLongValues(); } } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java index 38891365dfdc2..b9b8d81d38469 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java @@ -11,7 +11,7 @@ import org.apache.lucene.search.Scorable; import org.apache.lucene.util.LongValues; import org.elasticsearch.common.lucene.ScorerAware; -import org.elasticsearch.index.fielddata.AbstractSortingNumericDocValues; +import org.elasticsearch.index.fielddata.SortingNumericLongValues; import org.elasticsearch.script.AggregationScript; import org.elasticsearch.search.aggregations.AggregationErrors; @@ -24,7 +24,7 @@ /** * {@link LongValues} implementation which is based on a script */ -public class ScriptLongValues extends AbstractSortingNumericDocValues implements ScorerAware { +public class ScriptLongValues extends SortingNumericLongValues implements ScorerAware { final AggregationScript script; diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/FieldDataTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/FieldDataTests.java index 94b5f2b054f48..fba9003709d98 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/FieldDataTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/FieldDataTests.java @@ -9,9 +9,7 @@ package org.elasticsearch.index.fielddata; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.test.ESTestCase; @@ -19,10 +17,9 @@ public class FieldDataTests extends ESTestCase { - private static class DummyValues extends AbstractNumericDocValues { + private static class DummyValues extends LongValues { private final long value; - private int docID = -1; DummyValues(long value) { this.value = value; @@ -30,15 +27,9 @@ private static class DummyValues extends AbstractNumericDocValues { @Override public boolean advanceExact(int target) throws IOException { - docID = target; return true; } - @Override - public int docID() { - return docID; - } - @Override public long longValue() throws IOException { return value; @@ -49,23 +40,23 @@ public void testSortableLongBitsToDoubles() throws IOException { final double value = randomDouble(); final long valueBits = NumericUtils.doubleToSortableLong(value); - NumericDocValues values = new DummyValues(valueBits); + LongValues values = new DummyValues(valueBits); - SortedNumericDoubleValues asMultiDoubles = FieldData.sortableLongBitsToDoubles(DocValues.singleton(values)); + SortedNumericDoubleValues asMultiDoubles = FieldData.sortableLongBitsToDoubles(SortedNumericLongValues.singleton(values)); NumericDoubleValues asDoubles = FieldData.unwrapSingleton(asMultiDoubles); assertNotNull(asDoubles); assertTrue(asDoubles.advanceExact(0)); assertEquals(value, asDoubles.doubleValue(), 0); values = new DummyValues(valueBits); - asMultiDoubles = FieldData.sortableLongBitsToDoubles(DocValues.singleton(values)); - NumericDocValues backToLongs = DocValues.unwrapSingleton(FieldData.toSortableLongBits(asMultiDoubles)); + asMultiDoubles = FieldData.sortableLongBitsToDoubles(SortedNumericLongValues.singleton(values)); + LongValues backToLongs = SortedNumericLongValues.unwrapSingleton(FieldData.toSortableLongBits(asMultiDoubles)); assertSame(values, backToLongs); - SortedNumericDocValues multiValues = new AbstractSortedNumericDocValues() { + SortedNumericLongValues multiValues = new SortedNumericLongValues() { @Override - public boolean advanceExact(int target) throws IOException { + public boolean advanceExact(int target) { return true; } @@ -101,8 +92,8 @@ public double doubleValue() { } }; - SortedNumericDocValues asMultiLongs = FieldData.toSortableLongBits(FieldData.singleton(values)); - NumericDocValues asLongs = DocValues.unwrapSingleton(asMultiLongs); + SortedNumericLongValues asMultiLongs = FieldData.toSortableLongBits(FieldData.singleton(values)); + LongValues asLongs = SortedNumericLongValues.unwrapSingleton(asMultiLongs); assertNotNull(asLongs); assertTrue(asLongs.advanceExact(0)); assertEquals(valueBits, asLongs.longValue()); @@ -129,16 +120,11 @@ public int docValueCount() { assertSame(multiValues, FieldData.sortableLongBitsToDoubles(asMultiLongs)); } - private static NumericDocValues asNumericDocValues(Long... values) { - return new AbstractNumericDocValues() { + private static LongValues asNumericDocValues(Long... values) { + return new LongValues() { int docID = -1; - @Override - public int docID() { - return docID; - } - @Override public boolean advanceExact(int target) throws IOException { docID = target; @@ -153,8 +139,8 @@ public long longValue() throws IOException { } public void testReplaceMissingLongs() throws IOException { - final NumericDocValues values = asNumericDocValues(null, 3L, 2L, null, 5L, null); - final NumericDocValues replaced = FieldData.replaceMissing(values, 4); + final LongValues values = asNumericDocValues(null, 3L, 2L, null, 5L, null); + final LongValues replaced = FieldData.replaceMissing(values, 4); assertTrue(replaced.advanceExact(0)); assertEquals(4L, replaced.longValue()); diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/IntegralDocValuesFieldTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/IntegralDocValuesFieldTests.java index 45a9146a454e1..50b14361f184f 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/IntegralDocValuesFieldTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/IntegralDocValuesFieldTests.java @@ -92,8 +92,8 @@ protected long[][] generate(LongSupplier supplier) { return values; } - protected AbstractSortedNumericDocValues wrap(long[][] values) { - return new AbstractSortedNumericDocValues() { + protected SortedNumericLongValues wrap(long[][] values) { + return new SortedNumericLongValues() { long[] current; int i; diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesGeoPointsTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesGeoPointsTests.java index 32289eb86b935..4f8c428c84252 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesGeoPointsTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesGeoPointsTests.java @@ -22,7 +22,7 @@ public class ScriptDocValuesGeoPointsTests extends ESTestCase { private static MultiGeoPointValues wrap(GeoPoint[][] points) { - return new MultiGeoPointValues(new AbstractSortedNumericDocValues() { + return new MultiGeoPointValues(new SortedNumericLongValues() { GeoPoint[] current; int i; diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesLongsTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesLongsTests.java index fbb8e8740da1a..1ff51cd2102e3 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesLongsTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesLongsTests.java @@ -65,7 +65,7 @@ public void testLongs() throws IOException { } private LongDocValuesField wrap(long[][] values) { - return new LongDocValuesField(new AbstractSortedNumericDocValues() { + return new LongDocValuesField(new SortedNumericLongValues() { long[] current; int i; diff --git a/server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericDocValuesTests.java b/server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericLongValuesTests.java similarity index 77% rename from server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericDocValuesTests.java rename to server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericLongValuesTests.java index 86a17d00d644f..90a09768bb750 100644 --- a/server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericDocValuesTests.java +++ b/server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericLongValuesTests.java @@ -16,7 +16,7 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.function.LongConsumer; -public class SortingNumericDocValuesTests extends ESTestCase { +public class SortingNumericLongValuesTests extends ESTestCase { public void testResize() { final int oldSize = Integer.MAX_VALUE - 200; @@ -28,7 +28,7 @@ public void testResize() { long total = counter.addAndGet(value); assertThat(total, Matchers.greaterThanOrEqualTo(0L)); }; - SortingNumericDocValues docValues = new SortingNumericDocValues(consumer) { + SortingNumericLongValues docValues = new SortingNumericLongValues(consumer) { @Override protected void growExact(int newValuesLength) { @@ -44,26 +44,6 @@ protected int getArrayLength() { public boolean advanceExact(int target) { return false; } - - @Override - public int docID() { - return 0; - } - - @Override - public int nextDoc() { - return 0; - } - - @Override - public int advance(int target) { - return 0; - } - - @Override - public long cost() { - return 0; - } }; docValues.resize(newSize); final long diff = ArrayUtil.oversize(newSize, Long.BYTES) - oldSize; diff --git a/server/src/test/java/org/elasticsearch/index/mapper/BooleanScriptFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/BooleanScriptFieldTypeTests.java index 97cc3a5aa4ae1..a077767166ae8 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/BooleanScriptFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/BooleanScriptFieldTypeTests.java @@ -13,7 +13,6 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NoMergePolicy; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.StoredFields; import org.apache.lucene.search.Collector; import org.apache.lucene.search.IndexSearcher; @@ -36,6 +35,7 @@ import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.fielddata.BooleanScriptFieldData; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.script.BooleanFieldScript; import org.elasticsearch.script.DocReader; @@ -99,7 +99,7 @@ public ScoreMode scoreMode() { @Override public LeafCollector getLeafCollector(LeafReaderContext context) { - SortedNumericDocValues dv = ifd.load(context).getLongValues(); + SortedNumericLongValues dv = ifd.load(context).getLongValues(); return new LeafCollector() { @Override public void setScorer(Scorable scorer) {} diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java index a0501908a267f..2bc6d1a7786e6 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java @@ -17,8 +17,6 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.MultiReader; -import org.apache.lucene.index.SortedNumericDocValues; -import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexOrDocValuesQuery; import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery; import org.apache.lucene.search.Query; @@ -34,6 +32,7 @@ import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.fielddata.LeafNumericFieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData; import org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType; import org.elasticsearch.index.mapper.DateFieldMapper.Resolution; @@ -527,10 +526,9 @@ public void testDateNanoDocValues() throws IOException { DirectoryReader reader = DirectoryReader.open(w); assertTrue(reader.leaves().size() > 0); LeafNumericFieldData a = fieldData.load(reader.leaves().get(0).reader().getContext()); - SortedNumericDocValues docValues = a.getLongValues(); - assertEquals(0, docValues.nextDoc()); - assertEquals(1, docValues.nextDoc()); - assertEquals(DocIdSetIterator.NO_MORE_DOCS, docValues.nextDoc()); + SortedNumericLongValues docValues = a.getLongValues(); + assertTrue(docValues.advanceExact(0)); + assertTrue(docValues.advanceExact(1)); reader.close(); w.close(); dir.close(); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DateScriptFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DateScriptFieldTypeTests.java index 987a33636b24a..e28de22b819e6 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DateScriptFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DateScriptFieldTypeTests.java @@ -13,7 +13,6 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NoMergePolicy; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.Collector; import org.apache.lucene.search.Explanation; import org.apache.lucene.search.FieldDoc; @@ -40,6 +39,7 @@ import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.fielddata.DateScriptFieldData; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.script.DateFieldScript; import org.elasticsearch.script.DocReader; @@ -183,7 +183,7 @@ public ScoreMode scoreMode() { @Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { - SortedNumericDocValues dv = ifd.load(context).getLongValues(); + SortedNumericLongValues dv = ifd.load(context).getLongValues(); return new LeafCollector() { @Override public void setScorer(Scorable scorer) throws IOException {} diff --git a/server/src/test/java/org/elasticsearch/index/mapper/LongScriptFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/LongScriptFieldTypeTests.java index 9ba910909f5b1..7b84cf804f9a9 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/LongScriptFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/LongScriptFieldTypeTests.java @@ -13,7 +13,6 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NoMergePolicy; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.StoredFields; import org.apache.lucene.search.Collector; import org.apache.lucene.search.FieldDoc; @@ -35,6 +34,7 @@ import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.fielddata.LongScriptFieldData; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.script.DocReader; import org.elasticsearch.script.LongFieldScript; @@ -105,7 +105,7 @@ public ScoreMode scoreMode() { @Override public LeafCollector getLeafCollector(LeafReaderContext context) { - SortedNumericDocValues dv = ifd.load(context).getLongValues(); + SortedNumericLongValues dv = ifd.load(context).getLongValues(); return new LeafCollector() { @Override public void setScorer(Scorable scorer) {} diff --git a/server/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreTests.java b/server/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreTests.java index 2fdfbcc9fee06..2f3964b46f569 100644 --- a/server/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreTests.java @@ -16,7 +16,6 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.Term; import org.apache.lucene.search.Explanation; import org.apache.lucene.search.IndexSearcher; @@ -49,6 +48,7 @@ import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.field.DocValuesScriptFieldFactory; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.MultiValueMode; @@ -182,7 +182,7 @@ public ValuesSourceType getValuesSourceType() { public LeafNumericFieldData load(LeafReaderContext context) { return new LeafNumericFieldData() { @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { throw new UnsupportedOperationException(UNSUPPORTED); } diff --git a/server/src/test/java/org/elasticsearch/search/MultiValueModeTests.java b/server/src/test/java/org/elasticsearch/search/MultiValueModeTests.java index 663b39d116913..9027a50ca5b87 100644 --- a/server/src/test/java/org/elasticsearch/search/MultiValueModeTests.java +++ b/server/src/test/java/org/elasticsearch/search/MultiValueModeTests.java @@ -11,24 +11,22 @@ import org.apache.lucene.index.BinaryDocValues; import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.SortedDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.BitSetIterator; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.FixedBitSet; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.fielddata.AbstractBinaryDocValues; -import org.elasticsearch.index.fielddata.AbstractNumericDocValues; import org.elasticsearch.index.fielddata.AbstractSortedDocValues; -import org.elasticsearch.index.fielddata.AbstractSortedNumericDocValues; import org.elasticsearch.index.fielddata.AbstractSortedSetDocValues; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.test.ESTestCase; import java.io.IOException; @@ -80,7 +78,7 @@ public void testSingleValuedLongs() throws Exception { } } - final Supplier multiValues = () -> DocValues.singleton(new AbstractNumericDocValues() { + final Supplier multiValues = () -> SortedNumericLongValues.singleton(new LongValues() { int docId = -1; @Override @@ -89,11 +87,6 @@ public boolean advanceExact(int target) throws IOException { return docsWithValue == null ? true : docsWithValue.get(docId); } - @Override - public int docID() { - return docId; - } - @Override public long longValue() { return array[docId]; @@ -117,7 +110,7 @@ public void testMultiValuedLongs() throws Exception { Arrays.sort(values); array[i] = values; } - final Supplier multiValues = () -> new AbstractSortedNumericDocValues() { + final Supplier multiValues = () -> new SortedNumericLongValues() { int doc; int i; @@ -145,10 +138,10 @@ public int docValueCount() { verifySortedNumeric(multiValues, numDocs, rootDocs, innerDocs, randomIntBetween(1, numDocs)); } - private void verifySortedNumeric(Supplier supplier, int maxDoc) throws IOException { + private void verifySortedNumeric(Supplier supplier, int maxDoc) throws IOException { for (MultiValueMode mode : MultiValueMode.values()) { - SortedNumericDocValues values = supplier.get(); - final NumericDocValues selected = mode.select(values); + SortedNumericLongValues values = supplier.get(); + final LongValues selected = mode.select(values); for (int i = 0; i < maxDoc; ++i) { Long actual = null; if (selected.advanceExact(i)) { @@ -198,14 +191,14 @@ private void verifySortedNumeric(Supplier supplier, int } } - private void verifyLongValueCanCalledMoreThanOnce(NumericDocValues values, long expected) throws IOException { + private void verifyLongValueCanCalledMoreThanOnce(LongValues values, long expected) throws IOException { for (int j = 0, numCall = randomIntBetween(1, 10); j < numCall; j++) { assertEquals(expected, values.longValue()); } } private void verifySortedNumeric( - Supplier supplier, + Supplier supplier, int maxDoc, FixedBitSet rootDocs, FixedBitSet innerDocs, @@ -217,14 +210,8 @@ private void verifySortedNumeric( MultiValueMode.MAX, MultiValueMode.SUM, MultiValueMode.AVG }) { - SortedNumericDocValues values = supplier.get(); - final NumericDocValues selected = mode.select( - values, - missingValue, - rootDocs, - new BitSetIterator(innerDocs, 0L), - maxChildren - ); + SortedNumericLongValues values = supplier.get(); + final LongValues selected = mode.select(values, missingValue, rootDocs, new BitSetIterator(innerDocs, 0L), maxChildren); int prevRoot = -1; for (int root = rootDocs.nextSetBit(0); root != -1; root = root + 1 < maxDoc ? rootDocs.nextSetBit(root + 1) : -1) { assertTrue(selected.advanceExact(root)); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesCollectorQueueTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesCollectorQueueTests.java index 505e4c09aba1a..ef14ec100467d 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesCollectorQueueTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesCollectorQueueTests.java @@ -51,6 +51,7 @@ import org.apache.lucene.util.NumericUtils; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.index.fielddata.FieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.KeywordFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.NumberFieldMapper; @@ -275,7 +276,7 @@ private void testRandomCase(boolean forceMerge, boolean missingBucket, int index sources[i] = new LongValuesSource( bigArrays, fieldType, - context -> DocValues.getSortedNumeric(context.reader(), fieldType.name()), + context -> SortedNumericLongValues.wrap(DocValues.getSortedNumeric(context.reader(), fieldType.name())), value -> value, DocValueFormat.RAW, missingBucket, @@ -287,7 +288,9 @@ private void testRandomCase(boolean forceMerge, boolean missingBucket, int index sources[i] = new DoubleValuesSource( bigArrays, fieldType, - context -> FieldData.sortableLongBitsToDoubles(DocValues.getSortedNumeric(context.reader(), fieldType.name())), + context -> FieldData.sortableLongBitsToDoubles( + SortedNumericLongValues.wrap(DocValues.getSortedNumeric(context.reader(), fieldType.name())) + ), DocValueFormat.RAW, missingBucket, MissingOrder.DEFAULT, diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/support/MissingValuesTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/support/MissingValuesTests.java index 2a36887cc459a..c3165d2fd4f5b 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/support/MissingValuesTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/support/MissingValuesTests.java @@ -12,14 +12,13 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.carrotsearch.randomizedtesting.generators.RandomStrings; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.tests.util.TestUtil; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.index.fielddata.AbstractSortedNumericDocValues; import org.elasticsearch.index.fielddata.AbstractSortedSetDocValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.test.ESTestCase; import java.io.IOException; @@ -254,7 +253,7 @@ public void testMissingLongs() throws IOException { } Arrays.sort(values[i]); } - SortedNumericDocValues asNumericValues = new AbstractSortedNumericDocValues() { + SortedNumericLongValues asNumericValues = new SortedNumericLongValues() { int doc = -1; int i; @@ -277,7 +276,7 @@ public int docValueCount() { } }; final long missing = randomInt(); - SortedNumericDocValues withMissingReplaced = MissingValues.replaceMissing(asNumericValues, missing); + SortedNumericLongValues withMissingReplaced = MissingValues.replaceMissing(asNumericValues, missing); for (int i = 0; i < numDocs; ++i) { assertTrue(withMissingReplaced.advanceExact(i)); if (values[i].length > 0) { diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java index 65a41aade2494..b908431189833 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfigTests.java @@ -10,9 +10,9 @@ package org.elasticsearch.search.aggregations.support; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.BytesRef; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MapperServiceTestCase; import org.elasticsearch.script.AggregationScript; @@ -281,7 +281,7 @@ public void testLong() throws Exception { config = ValuesSourceConfig.resolve(context, null, "field", null, null, null, null, CoreValuesSourceType.KEYWORD); ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = context.searcher().getIndexReader().leaves().get(0); - SortedNumericDocValues values = valuesSource.longValues(ctx); + SortedNumericLongValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); assertEquals(42, values.nextValue()); @@ -296,7 +296,7 @@ public void testEmptyLong() throws Exception { config = ValuesSourceConfig.resolve(context, null, "field", null, null, null, null, CoreValuesSourceType.KEYWORD); ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = context.searcher().getIndexReader().leaves().get(0); - SortedNumericDocValues values = valuesSource.longValues(ctx); + SortedNumericLongValues values = valuesSource.longValues(ctx); assertFalse(values.advanceExact(0)); assertTrue(config.alignsWithSearchIndex()); @@ -323,7 +323,7 @@ public void testUnmappedLong() throws Exception { config = ValuesSourceConfig.resolve(context, ValueType.NUMBER, "field", null, 42, null, null, CoreValuesSourceType.KEYWORD); valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = context.searcher().getIndexReader().leaves().get(0); - SortedNumericDocValues values = valuesSource.longValues(ctx); + SortedNumericLongValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); assertEquals(42, values.nextValue()); @@ -338,7 +338,7 @@ public void testBoolean() throws Exception { config = ValuesSourceConfig.resolve(context, null, "field", null, null, null, null, CoreValuesSourceType.KEYWORD); ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = context.searcher().getIndexReader().leaves().get(0); - SortedNumericDocValues values = valuesSource.longValues(ctx); + SortedNumericLongValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); assertEquals(1, values.nextValue()); @@ -353,7 +353,7 @@ public void testEmptyBoolean() throws Exception { config = ValuesSourceConfig.resolve(context, null, "field", null, null, null, null, CoreValuesSourceType.KEYWORD); ValuesSource.Numeric valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = context.searcher().getIndexReader().leaves().get(0); - SortedNumericDocValues values = valuesSource.longValues(ctx); + SortedNumericLongValues values = valuesSource.longValues(ctx); assertFalse(values.advanceExact(0)); assertTrue(config.alignsWithSearchIndex()); @@ -380,7 +380,7 @@ public void testUnmappedBoolean() throws Exception { config = ValuesSourceConfig.resolve(context, ValueType.BOOLEAN, "field", null, true, null, null, CoreValuesSourceType.KEYWORD); valuesSource = (ValuesSource.Numeric) config.getValuesSource(); LeafReaderContext ctx = context.searcher().getIndexReader().leaves().get(0); - SortedNumericDocValues values = valuesSource.longValues(ctx); + SortedNumericLongValues values = valuesSource.longValues(ctx); assertTrue(values.advanceExact(0)); assertEquals(1, values.docValueCount()); assertEquals(1, values.nextValue()); diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/multiterms/MultiTermsAggregator.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/multiterms/MultiTermsAggregator.java index e2d3e300da69b..ebcfeb0b40f74 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/multiterms/MultiTermsAggregator.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/multiterms/MultiTermsAggregator.java @@ -8,10 +8,8 @@ package org.elasticsearch.xpack.analytics.multiterms; import org.apache.lucene.index.BinaryDocValues; -import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; @@ -29,6 +27,7 @@ import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregationExecutionContext; import org.elasticsearch.search.aggregations.Aggregator; @@ -393,12 +392,12 @@ static class LongTermValuesSource implements TermValuesSource { @Override public TermValues getValues(LeafReaderContext ctx) throws IOException { - final SortedNumericDocValues values = source.longValues(ctx); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = source.longValues(ctx); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); return singleton != null ? getValues(singleton) : getValues(values); } - public TermValues getValues(SortedNumericDocValues values) { + public TermValues getValues(SortedNumericLongValues values) { return doc -> { if (values.advanceExact(doc)) { final List objects = new ArrayList<>(); @@ -418,7 +417,7 @@ public TermValues getValues(SortedNumericDocValues values) { }; } - public TermValues getValues(NumericDocValues values) { + public TermValues getValues(LongValues values) { return doc -> { if (values.advanceExact(doc)) { return List.of(values.longValue()); diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java index 69b6e311e23ee..e30266ab58131 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java @@ -8,8 +8,8 @@ package org.elasticsearch.xpack.analytics.topmetrics; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.SortedSetDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.Scorable; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.BytesRef; @@ -379,7 +379,7 @@ public void swap(long lhs, long rhs) { @Override public Loader loader(LeafReaderContext ctx) throws IOException { // TODO allow configuration of value mode - NumericDocValues metricValues = MultiValueMode.AVG.select(valuesSource.longValues(ctx)); + LongValues metricValues = MultiValueMode.AVG.select(valuesSource.longValues(ctx)); return (index, doc) -> { if (false == metricValues.advanceExact(doc)) { empty.markMissing(index); diff --git a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorMetricsTests.java b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorMetricsTests.java index 0ab41367b6d50..92b03c6a01218 100644 --- a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorMetricsTests.java +++ b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregatorMetricsTests.java @@ -7,13 +7,13 @@ package org.elasticsearch.xpack.analytics.topmetrics; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.core.CheckedConsumer; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; @@ -76,7 +76,7 @@ private void assertNoValues(ValuesSourceConfig config) throws IOException { } public void testEmptyLong() throws IOException { - SortedNumericDocValues values = mock(SortedNumericDocValues.class); + SortedNumericLongValues values = mock(SortedNumericLongValues.class); when(values.advanceExact(0)).thenReturn(false); ValuesSourceConfig config = toConfig(values); withMetric(config, m -> { @@ -97,7 +97,7 @@ public void testEmptyDouble() throws IOException { public void testLoadLong() throws IOException { long value = randomLong(); - SortedNumericDocValues values = mock(SortedNumericDocValues.class); + SortedNumericLongValues values = mock(SortedNumericLongValues.class); when(values.advanceExact(0)).thenReturn(true); when(values.docValueCount()).thenReturn(1); when(values.nextValue()).thenReturn(value); @@ -138,7 +138,7 @@ public void testLoadString() throws IOException { public void testLoadAndSwapLong() throws IOException { long firstValue = randomLong(); long secondValue = randomLong(); - SortedNumericDocValues values = mock(SortedNumericDocValues.class); + SortedNumericLongValues values = mock(SortedNumericLongValues.class); when(values.advanceExact(0)).thenReturn(true); when(values.advanceExact(1)).thenReturn(true); when(values.docValueCount()).thenReturn(1); @@ -177,7 +177,7 @@ public void testManyValues() throws IOException { long[] values = IntStream.range(0, between(2, 100)).mapToLong(i -> randomLong()).toArray(); List configs = Arrays.stream(values).mapToObj(v -> { try { - SortedNumericDocValues docValues = mock(SortedNumericDocValues.class); + SortedNumericLongValues docValues = mock(SortedNumericLongValues.class); when(docValues.advanceExact(0)).thenReturn(true); when(docValues.docValueCount()).thenReturn(1); when(docValues.nextValue()).thenReturn(v); @@ -198,7 +198,7 @@ public void testManyValues() throws IOException { }); } - private ValuesSourceConfig toConfig(SortedNumericDocValues values) throws IOException { + private ValuesSourceConfig toConfig(SortedNumericLongValues values) throws IOException { ValuesSource.Numeric source = mock(ValuesSource.Numeric.class); when(source.isFloatingPoint()).thenReturn(false); when(source.longValues(null)).thenReturn(values); diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMaxFactory.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMaxFactory.java index 7e0003efaf669..c9a30d6bfbd6b 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMaxFactory.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMaxFactory.java @@ -7,15 +7,16 @@ package org.elasticsearch.compute.lucene; -import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.PointValues; import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.compute.data.Block; import org.elasticsearch.compute.data.BlockFactory; import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.compute.operator.SourceOperator; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.MultiValueMode; import java.io.IOException; @@ -93,8 +94,8 @@ long bytesToLong(byte[] bytes) { } }; - public final NumericDocValues multiValueMode(SortedNumericDocValues sortedNumericDocValues) { - return MultiValueMode.MAX.select(sortedNumericDocValues); + public final LongValues multiValueMode(SortedNumericDocValues sortedNumericDocValues) { + return MultiValueMode.MAX.select(SortedNumericLongValues.wrap(sortedNumericDocValues)); } public final long fromPointValues(PointValues pointValues) throws IOException { diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinFactory.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinFactory.java index 000ade1b19562..685cc334ae34e 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinFactory.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinFactory.java @@ -7,9 +7,9 @@ package org.elasticsearch.compute.lucene; -import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.PointValues; import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.compute.data.Block; @@ -17,6 +17,7 @@ import org.elasticsearch.compute.operator.DriverContext; import org.elasticsearch.compute.operator.SourceOperator; import org.elasticsearch.core.RefCounted; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.MultiValueMode; import java.io.IOException; @@ -94,8 +95,8 @@ long bytesToLong(byte[] bytes) { } }; - public final NumericDocValues multiValueMode(SortedNumericDocValues sortedNumericDocValues) { - return MultiValueMode.MIN.select(sortedNumericDocValues); + public final LongValues multiValueMode(SortedNumericDocValues sortedNumericDocValues) { + return MultiValueMode.MIN.select(SortedNumericLongValues.wrap(sortedNumericDocValues)); } public final long fromPointValues(PointValues pointValues) throws IOException { diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinMaxOperator.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinMaxOperator.java index b9e05567411fc..a9af408199aec 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinMaxOperator.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinMaxOperator.java @@ -8,10 +8,10 @@ package org.elasticsearch.compute.lucene; import org.apache.lucene.index.LeafReader; -import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.PointValues; import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.LeafCollector; +import org.apache.lucene.search.LongValues; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.Scorable; @@ -44,7 +44,7 @@ sealed interface NumberType permits LuceneMinFactory.NumberType, LuceneMaxFactor long fromPointValues(PointValues pointValues) throws IOException; /** Wraps the provided {@link SortedNumericDocValues} with a {@link MultiValueMode} */ - NumericDocValues multiValueMode(SortedNumericDocValues sortedNumericDocValues); + LongValues multiValueMode(SortedNumericDocValues sortedNumericDocValues); /** Return the competitive value between {@code value1} and {@code value2} */ long evaluate(long value1, long value2); @@ -135,7 +135,7 @@ public Page getCheckedOutput() throws IOException { } if (scorer.isDone() == false) { // could not apply shortcut, trigger the search - final NumericDocValues values = numberType.multiValueMode(reader.getSortedNumericDocValues(fieldName)); + final LongValues values = numberType.multiValueMode(reader.getSortedNumericDocValues(fieldName)); final LeafCollector leafCollector = new LeafCollector() { @Override public void setScorer(Scorable scorer) {} diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/querydsl/query/SingleValueMatchQuery.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/querydsl/query/SingleValueMatchQuery.java index 6256260abd4d3..de587f7fadc69 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/querydsl/query/SingleValueMatchQuery.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/querydsl/query/SingleValueMatchQuery.java @@ -13,7 +13,6 @@ import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.PointValues; import org.apache.lucene.index.SortedDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.index.Terms; import org.apache.lucene.search.ConstantScoreScorer; @@ -35,6 +34,7 @@ import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import java.io.IOException; import java.util.Objects; @@ -113,7 +113,7 @@ public boolean isCacheable(LeafReaderContext ctx) { final LeafFieldData lfd = fieldData.load(ctx); // If field is singleton, then it is safe to cache this query, because no warning will ever be emitted. if (lfd instanceof LeafNumericFieldData n) { - if (DocValues.unwrapSingleton(n.getLongValues()) != null) { + if (SortedNumericLongValues.unwrapSingleton(n.getLongValues()) != null) { return true; } } else if (lfd instanceof LeafOrdinalsFieldData o) { @@ -127,12 +127,12 @@ public boolean isCacheable(LeafReaderContext ctx) { private ScorerSupplier scorerSupplier( LeafReaderContext context, - SortedNumericDocValues sortedNumerics, + SortedNumericLongValues sortedNumerics, float boost, ScoreMode scoreMode ) throws IOException { final int maxDoc = context.reader().maxDoc(); - if (DocValues.unwrapSingleton(sortedNumerics) != null) { + if (SortedNumericLongValues.unwrapSingleton(sortedNumerics) != null) { // check for dense field // TODO: check doc values skippers final PointValues points = context.reader().getPointValues(fieldData.getFieldName()); diff --git a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/SourceValueFetcherSortedUnsignedLongIndexFieldData.java b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/SourceValueFetcherSortedUnsignedLongIndexFieldData.java index 8f5f1262c4d82..599a074ef4c27 100644 --- a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/SourceValueFetcherSortedUnsignedLongIndexFieldData.java +++ b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/SourceValueFetcherSortedUnsignedLongIndexFieldData.java @@ -10,6 +10,7 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.IndexFieldDataCache; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.SourceValueFetcherIndexFieldData; import org.elasticsearch.index.mapper.ValueFetcher; import org.elasticsearch.indices.breaker.CircuitBreakerService; @@ -33,16 +34,16 @@ * emulate unsigned long values pulled directly from a doc values data structure through a * {@link SortedNumericDocValues}. */ -public class SourceValueFetcherSortedUnsignedLongIndexFieldData extends SourceValueFetcherIndexFieldData { +public class SourceValueFetcherSortedUnsignedLongIndexFieldData extends SourceValueFetcherIndexFieldData { - public static class Builder extends SourceValueFetcherIndexFieldData.Builder { + public static class Builder extends SourceValueFetcherIndexFieldData.Builder { public Builder( String fieldName, ValuesSourceType valuesSourceType, ValueFetcher valueFetcher, SourceProvider sourceProvider, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, valueFetcher, sourceProvider, toScriptFieldFactory); } @@ -64,20 +65,21 @@ protected SourceValueFetcherSortedUnsignedLongIndexFieldData( ValuesSourceType valuesSourceType, ValueFetcher valueFetcher, SourceProvider sourceProvider, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, valueFetcher, sourceProvider, toScriptFieldFactory); } @Override - public SourceValueFetcherLeafFieldData loadDirect(LeafReaderContext context) { + public SourceValueFetcherLeafFieldData loadDirect(LeafReaderContext context) { return new SourceValueFetcherSortedUnsignedLongLeafFieldData(toScriptFieldFactory, context, valueFetcher, sourceProvider); } - private static class SourceValueFetcherSortedUnsignedLongLeafFieldData extends SourceValueFetcherLeafFieldData { + private static class SourceValueFetcherSortedUnsignedLongLeafFieldData extends SourceValueFetcherLeafFieldData< + SortedNumericLongValues> { private SourceValueFetcherSortedUnsignedLongLeafFieldData( - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, LeafReaderContext leafReaderContext, ValueFetcher valueFetcher, SourceProvider sourceProvider @@ -94,7 +96,7 @@ public DocValuesScriptFieldFactory getScriptFieldFactory(String name) { } } - private static class SourceValueFetcherSortedUnsignedLongDocValues extends SortedNumericDocValues implements ValueFetcherDocValues { + private static class SourceValueFetcherSortedUnsignedLongDocValues extends SortedNumericLongValues implements ValueFetcherDocValues { private final LeafReaderContext leafReaderContext; @@ -141,25 +143,5 @@ public long nextValue() throws IOException { assert iterator.hasNext(); return iterator.next(); } - - @Override - public int docID() { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public int nextDoc() throws IOException { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public int advance(int target) throws IOException { - throw new UnsupportedOperationException("not supported for source fallback"); - } - - @Override - public long cost() { - throw new UnsupportedOperationException("not supported for source fallback"); - } } } diff --git a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongDocValuesField.java b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongDocValuesField.java index b7c7cdcd67a4b..065188821da5e 100644 --- a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongDocValuesField.java +++ b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongDocValuesField.java @@ -7,8 +7,8 @@ package org.elasticsearch.xpack.unsignedlong; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.field.AbstractLongDocValuesField; import java.math.BigInteger; @@ -21,7 +21,7 @@ public class UnsignedLongDocValuesField extends AbstractLongDocValuesField { - public UnsignedLongDocValuesField(SortedNumericDocValues input, String name) { + public UnsignedLongDocValuesField(SortedNumericLongValues input, String name) { super(input, name); } diff --git a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongIndexFieldData.java b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongIndexFieldData.java index 2f936531f8c72..0a9cfc7b49a30 100644 --- a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongIndexFieldData.java +++ b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongIndexFieldData.java @@ -8,20 +8,20 @@ package org.elasticsearch.xpack.unsignedlong; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.fielddata.LeafNumericFieldData; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.field.ToScriptFieldFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceType; public class UnsignedLongIndexFieldData extends IndexNumericFieldData { private final IndexNumericFieldData signedLongIFD; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; protected final boolean indexed; UnsignedLongIndexFieldData( IndexNumericFieldData signedLongFieldData, - ToScriptFieldFactory toScriptFieldFactory, + ToScriptFieldFactory toScriptFieldFactory, boolean indexed ) { this.signedLongIFD = signedLongFieldData; diff --git a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongLeafFieldData.java b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongLeafFieldData.java index 00c60987f439d..472106a5fdfb8 100644 --- a/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongLeafFieldData.java +++ b/x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongLeafFieldData.java @@ -7,15 +7,14 @@ package org.elasticsearch.xpack.unsignedlong; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.search.LongValues; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.FormattedDocValues; import org.elasticsearch.index.fielddata.LeafNumericFieldData; import org.elasticsearch.index.fielddata.NumericDoubleValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.index.fielddata.plain.FormattedSortedNumericDocValues; import org.elasticsearch.script.field.DocValuesScriptFieldFactory; import org.elasticsearch.script.field.ToScriptFieldFactory; @@ -27,22 +26,22 @@ public class UnsignedLongLeafFieldData implements LeafNumericFieldData { private final LeafNumericFieldData signedLongFD; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; - UnsignedLongLeafFieldData(LeafNumericFieldData signedLongFD, ToScriptFieldFactory toScriptFieldFactory) { + UnsignedLongLeafFieldData(LeafNumericFieldData signedLongFD, ToScriptFieldFactory toScriptFieldFactory) { this.signedLongFD = signedLongFD; this.toScriptFieldFactory = toScriptFieldFactory; } @Override - public SortedNumericDocValues getLongValues() { + public SortedNumericLongValues getLongValues() { return signedLongFD.getLongValues(); } @Override public SortedNumericDoubleValues getDoubleValues() { - final SortedNumericDocValues values = signedLongFD.getLongValues(); - final NumericDocValues singleValues = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = signedLongFD.getLongValues(); + final LongValues singleValues = SortedNumericLongValues.unwrapSingleton(values); if (singleValues != null) { return FieldData.singleton(new NumericDoubleValues() { @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/frequentitemsets/mr/ItemSetMapReduceValueSource.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/frequentitemsets/mr/ItemSetMapReduceValueSource.java index 08adecd3fbce5..133bbe8564dcf 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/frequentitemsets/mr/ItemSetMapReduceValueSource.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/frequentitemsets/mr/ItemSetMapReduceValueSource.java @@ -12,10 +12,9 @@ import org.apache.lucene.index.BinaryDocValues; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.SortedDocValues; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; +import org.apache.lucene.search.LongValues; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LongBitSet; import org.elasticsearch.common.Strings; @@ -25,6 +24,7 @@ import org.elasticsearch.core.Tuple; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude; import org.elasticsearch.search.aggregations.support.ValuesSource; @@ -405,14 +405,14 @@ public NumericValueSource( @Override ValueCollector getValueCollector(LeafReaderContext ctx) throws IOException { - final SortedNumericDocValues values = source.longValues(ctx); - final NumericDocValues singleton = DocValues.unwrapSingleton(values); + final SortedNumericLongValues values = source.longValues(ctx); + final LongValues singleton = SortedNumericLongValues.unwrapSingleton(values); final Field field = getField(); final Tuple> empty = new Tuple<>(field, Collections.emptyList()); return singleton != null ? getValueCollector(singleton, empty, field) : getValueCollector(values, empty, field); } - private ValueCollector getValueCollector(SortedNumericDocValues values, Tuple> empty, Field field) { + private ValueCollector getValueCollector(SortedNumericLongValues values, Tuple> empty, Field field) { return doc -> { if (values.advanceExact(doc)) { final int valuesCount = values.docValueCount(); @@ -438,7 +438,7 @@ private ValueCollector getValueCollector(SortedNumericDocValues values, Tuple> empty, Field field) { + private ValueCollector getValueCollector(LongValues values, Tuple> empty, Field field) { return doc -> { if (values.advanceExact(doc)) { final long v = values.longValue(); diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/CartesianPointDVLeafFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/CartesianPointDVLeafFieldData.java index b8bd5e82fef3b..f41c961bf7d14 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/CartesianPointDVLeafFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/CartesianPointDVLeafFieldData.java @@ -9,7 +9,7 @@ import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReader; -import org.apache.lucene.index.SortedNumericDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.field.ToScriptFieldFactory; import org.elasticsearch.xpack.spatial.search.aggregations.support.CartesianPointValuesSource; @@ -35,9 +35,9 @@ public long ramBytesUsed() { } @Override - public SortedNumericDocValues getSortedNumericDocValues() { + public SortedNumericLongValues getSortedNumericLongValues() { try { - return DocValues.getSortedNumeric(reader, fieldName); + return SortedNumericLongValues.wrap(DocValues.getSortedNumeric(reader, fieldName)); } catch (IOException e) { throw new IllegalStateException("Cannot load doc values", e); } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LeafCartesianPointFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LeafCartesianPointFieldData.java index d25101217c63a..c0c2b07114d21 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LeafCartesianPointFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LeafCartesianPointFieldData.java @@ -22,7 +22,7 @@ public LeafCartesianPointFieldData(ToScriptFieldFactory roundingPreparer(AggregationC * Return point values. */ public final MultiCartesianPointValues pointValues(LeafReaderContext context) { - return new MultiCartesianPointValues(sortedNumericDocValues(context)); + return new MultiCartesianPointValues(sortedNumericLongValues(context)); } public static final class MultiCartesianPointValues extends MultiPointValues { private final CartesianPoint point = new CartesianPoint(); - public MultiCartesianPointValues(SortedNumericDocValues numericValues) { + public MultiCartesianPointValues(SortedNumericLongValues numericValues) { super(numericValues); } @@ -74,7 +74,7 @@ public CartesianPoint nextValue() throws IOException { /** * Return the internal representation of point doc values as a {@link SortedNumericDocValues}. */ - public abstract SortedNumericDocValues sortedNumericDocValues(LeafReaderContext context); + public abstract SortedNumericLongValues sortedNumericLongValues(LeafReaderContext context); public static class Fielddata extends CartesianPointValuesSource { @@ -90,8 +90,8 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext context) { } @Override - public SortedNumericDocValues sortedNumericDocValues(LeafReaderContext context) { - return indexFieldData.load(context).getSortedNumericDocValues(); + public SortedNumericLongValues sortedNumericLongValues(LeafReaderContext context) { + return indexFieldData.load(context).getSortedNumericLongValues(); } } } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/CartesianPointValuesSourceType.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/CartesianPointValuesSourceType.java index 29fdaa3c0cfd2..fff42343f8d85 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/CartesianPointValuesSourceType.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/CartesianPointValuesSourceType.java @@ -9,11 +9,11 @@ import org.apache.lucene.geo.XYEncodingUtils; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; +import org.elasticsearch.index.fielddata.SortedNumericLongValues; import org.elasticsearch.script.AggregationScript; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.support.FieldContext; @@ -68,11 +68,11 @@ public ValuesSource replaceMissing( final CartesianPoint missing = new CartesianPoint().resetFromString(rawMissing.toString(), false); return new CartesianPointValuesSource() { @Override - public SortedNumericDocValues sortedNumericDocValues(LeafReaderContext context) { + public SortedNumericLongValues sortedNumericLongValues(LeafReaderContext context) { final long xi = XYEncodingUtils.encode((float) missing.getX()); final long yi = XYEncodingUtils.encode((float) missing.getY()); long encoded = (yi & 0xFFFFFFFFL) | xi << 32; - return MissingValues.replaceMissing(pointValuesSource.sortedNumericDocValues(context), encoded); + return MissingValues.replaceMissing(pointValuesSource.sortedNumericLongValues(context), encoded); } @Override From 4a0d41f62fe1d9f73e52d3d15e1cffa6216e61b7 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Mon, 13 Oct 2025 13:16:28 +0100 Subject: [PATCH 3/3] Seal some classes --- .../elasticsearch/search/aggregations/support/ValuesSource.java | 2 +- .../search/aggregations/support/values/ScriptLongValues.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSource.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSource.java index aa03cb2cd659b..4eef2c43d9d35 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSource.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSource.java @@ -531,7 +531,7 @@ public SortedNumericDoubleValues doubleValues(LeafReaderContext context) throws return new DoubleValues(delegate.doubleValues(context), script.newInstance(context)); } - static class LongValues extends SortingNumericLongValues implements ScorerAware { + static final class LongValues extends SortingNumericLongValues implements ScorerAware { private final SortedNumericLongValues longValues; private final AggregationScript script; diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java index b9b8d81d38469..3f215c4e7a3d4 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java @@ -24,7 +24,7 @@ /** * {@link LongValues} implementation which is based on a script */ -public class ScriptLongValues extends SortingNumericLongValues implements ScorerAware { +public final class ScriptLongValues extends SortingNumericLongValues implements ScorerAware { final AggregationScript script;