diff --git a/server/src/main/java/org/opensearch/index/fielddata/FieldData.java b/server/src/main/java/org/opensearch/index/fielddata/FieldData.java index 61e48d05a6263..6db6bbccacae5 100644 --- a/server/src/main/java/org/opensearch/index/fielddata/FieldData.java +++ b/server/src/main/java/org/opensearch/index/fielddata/FieldData.java @@ -292,13 +292,6 @@ public static SortedNumericDocValues castToLong(final SortedNumericDoubleValues } } - /** - * Returns a multi-valued view over the provided {@link NumericDoubleValues}. - */ - public static SortedNumericUnsignedLongValues singleton(SortedNumericDocValues values) { - return new SingletonSortedNumericUnsignedLongValues(values); - } - /** * Returns a multi-valued view over the provided {@link NumericDoubleValues}. */ @@ -318,18 +311,6 @@ public static NumericDoubleValues unwrapSingleton(SortedNumericDoubleValues valu return null; } - /** - * Returns a single-valued view of the {@link SortedNumericDoubleValues}, - * if it was previously wrapped with {@link DocValues#singleton(NumericDocValues)}, - * or null. - */ - public static SortedNumericDocValues unwrapSingleton(SortedNumericUnsignedLongValues values) { - if (values instanceof SingletonSortedNumericUnsignedLongValues) { - return ((SingletonSortedNumericUnsignedLongValues) values).getNumericUnsignedLongValues(); - } - return null; - } - /** * Returns a multi-valued view over the provided {@link GeoPointValues}. */ diff --git a/server/src/main/java/org/opensearch/index/fielddata/SingletonSortedNumericUnsignedLongValues.java b/server/src/main/java/org/opensearch/index/fielddata/LongToSortedNumericUnsignedLongValues.java similarity index 74% rename from server/src/main/java/org/opensearch/index/fielddata/SingletonSortedNumericUnsignedLongValues.java rename to server/src/main/java/org/opensearch/index/fielddata/LongToSortedNumericUnsignedLongValues.java index f2ec4d7589b64..eb8d8f1667218 100644 --- a/server/src/main/java/org/opensearch/index/fielddata/SingletonSortedNumericUnsignedLongValues.java +++ b/server/src/main/java/org/opensearch/index/fielddata/LongToSortedNumericUnsignedLongValues.java @@ -13,18 +13,15 @@ import java.io.IOException; /** - * Exposes multi-valued view over a single-valued instance. - *
- * This can be used if you want to have one multi-valued implementation - * that works for single or multi-valued types. + * Wraps long-based {@link SortedNumericDocValues} as unsigned long ones + * (primarily used by {@link org.opensearch.search.MultiValueMode} * * @opensearch.internal */ - -final class SingletonSortedNumericUnsignedLongValues extends SortedNumericUnsignedLongValues { +public final class LongToSortedNumericUnsignedLongValues extends SortedNumericUnsignedLongValues { private final SortedNumericDocValues values; - SingletonSortedNumericUnsignedLongValues(SortedNumericDocValues values) { + public LongToSortedNumericUnsignedLongValues(SortedNumericDocValues values) { this.values = values; } diff --git a/server/src/main/java/org/opensearch/index/fielddata/fieldcomparator/UnsignedLongValuesComparatorSource.java b/server/src/main/java/org/opensearch/index/fielddata/fieldcomparator/UnsignedLongValuesComparatorSource.java index fe3270d09c422..6fc85bd0b2689 100644 --- a/server/src/main/java/org/opensearch/index/fielddata/fieldcomparator/UnsignedLongValuesComparatorSource.java +++ b/server/src/main/java/org/opensearch/index/fielddata/fieldcomparator/UnsignedLongValuesComparatorSource.java @@ -23,6 +23,7 @@ import org.opensearch.index.fielddata.IndexFieldData; import org.opensearch.index.fielddata.IndexNumericFieldData; import org.opensearch.index.fielddata.LeafNumericFieldData; +import org.opensearch.index.fielddata.LongToSortedNumericUnsignedLongValues; import org.opensearch.index.fielddata.SortedNumericUnsignedLongValues; import org.opensearch.index.search.comparators.UnsignedLongComparator; import org.opensearch.search.DocValueFormat; @@ -59,7 +60,7 @@ public SortField.Type reducedType() { private SortedNumericUnsignedLongValues loadDocValues(LeafReaderContext context) { final LeafNumericFieldData data = indexFieldData.load(context); - return FieldData.singleton(data.getLongValues()); + return new LongToSortedNumericUnsignedLongValues(data.getLongValues()); } private NumericDocValues getNumericDocValues(LeafReaderContext context, BigInteger missingValue) throws IOException { diff --git a/server/src/main/java/org/opensearch/search/MultiValueMode.java b/server/src/main/java/org/opensearch/search/MultiValueMode.java index b9df357016788..fa2e776eca67a 100644 --- a/server/src/main/java/org/opensearch/search/MultiValueMode.java +++ b/server/src/main/java/org/opensearch/search/MultiValueMode.java @@ -51,6 +51,7 @@ import org.opensearch.index.fielddata.AbstractNumericDocValues; import org.opensearch.index.fielddata.AbstractSortedDocValues; import org.opensearch.index.fielddata.FieldData; +import org.opensearch.index.fielddata.LongToSortedNumericUnsignedLongValues; import org.opensearch.index.fielddata.NumericDoubleValues; import org.opensearch.index.fielddata.SortedBinaryDocValues; import org.opensearch.index.fielddata.SortedNumericDoubleValues; @@ -1240,7 +1241,11 @@ protected int pick(SortedDocValues values, DocIdSetIterator docItr, int startDoc * Allowed Modes: SUM, AVG, MEDIAN, MIN, MAX */ public NumericDocValues select(final SortedNumericUnsignedLongValues values) { - final SortedNumericDocValues sortedNumericDocValues = FieldData.unwrapSingleton(values); + SortedNumericDocValues sortedNumericDocValues = null; + if (values instanceof LongToSortedNumericUnsignedLongValues) { + sortedNumericDocValues = ((LongToSortedNumericUnsignedLongValues) values).getNumericUnsignedLongValues(); + } + final NumericDocValues singleton = DocValues.unwrapSingleton(sortedNumericDocValues); if (singleton != null) { return singleton;