Skip to content

Commit

Permalink
Misc cleanup fieldata package (elastic#113331)
Browse files Browse the repository at this point in the history
Just some obvious cleanup and deduplication.
  • Loading branch information
original-brownbear committed Sep 21, 2024
1 parent 3843d2a commit 3dcab9c
Show file tree
Hide file tree
Showing 63 changed files with 140 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public SortedNumericDocValues getSortedNumeric(FieldInfo field) throws IOExcepti
int i, docValueCount;

@Override
public long nextValue() throws IOException {
public long nextValue() {
return ords[i++];
}

Expand All @@ -543,7 +543,7 @@ public int docValueCount() {
}

@Override
public boolean advanceExact(int target) throws IOException {
public boolean advanceExact(int target) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@
package org.elasticsearch.index.fielddata;

import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.search.DocIdSetIterator;

import java.io.IOException;

/**
* Base implementation that throws an {@link IOException} for the
* {@link DocIdSetIterator} APIs. This impl is safe to use for sorting and
* Base implementation. This impl is safe to use for sorting and
* aggregations, which only use {@link #advanceExact(int)} and
* {@link #binaryValue()}.
*/
Expand All @@ -28,12 +24,12 @@ public int docID() {
}

@Override
public int nextDoc() throws IOException {
public int nextDoc() {
throw new UnsupportedOperationException();
}

@Override
public int advance(int target) throws IOException {
public int advance(int target) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
public abstract class AbstractNumericDocValues extends NumericDocValues {

@Override
public int nextDoc() throws IOException {
public int nextDoc() {
throw new UnsupportedOperationException();
}

@Override
public int advance(int target) throws IOException {
public int advance(int target) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
public abstract class AbstractSortedDocValues extends SortedDocValues {

@Override
public int nextDoc() throws IOException {
public int nextDoc() {
throw new UnsupportedOperationException();
}

@Override
public int advance(int target) throws IOException {
public int advance(int target) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public int nextDoc() throws IOException {
}

@Override
public int advance(int target) throws IOException {
public int advance(int target) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public int docID() {
}

@Override
public int nextDoc() throws IOException {
public int nextDoc() {
throw new UnsupportedOperationException();
}

@Override
public int advance(int target) throws IOException {
public int advance(int target) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public int docID() {
}

@Override
public int nextDoc() throws IOException {
public int nextDoc() {
throw new UnsupportedOperationException();
}

@Override
public int advance(int target) throws IOException {
public int advance(int target) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,5 @@ public long ramBytesUsed() {
return 0;
}

@Override
public void close() {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public DoubleScriptFieldData build(IndexFieldDataCache cache, CircuitBreakerServ
}

private final String fieldName;
DoubleFieldScript.LeafFactory leafFactory;
final DoubleFieldScript.LeafFactory leafFactory;
private final ToScriptFieldFactory<SortedNumericDoubleValues> toScriptFieldFactory;

private DoubleScriptFieldData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public static SortedBinaryDocValues emptySortedBinary() {
public static NumericDoubleValues emptyNumericDouble() {
return new NumericDoubleValues() {
@Override
public boolean advanceExact(int doc) throws IOException {
public boolean advanceExact(int doc) {
return false;
}

@Override
public double doubleValue() throws IOException {
public double doubleValue() {
throw new UnsupportedOperationException();
}

Expand Down Expand Up @@ -243,14 +243,6 @@ public static BinaryDocValues unwrapSingleton(SortedBinaryDocValues values) {
return null;
}

/**
* Returns whether the provided values *might* be multi-valued. There is no
* guarantee that this method will return {@code false} in the single-valued case.
*/
public static boolean isMultiValued(SortedSetDocValues values) {
return DocValues.unwrapSingleton(values) == null;
}

/**
* Return a {@link String} representation of the provided values. That is
* typically used for scripts or for the `map` execution mode of terms aggs.
Expand Down Expand Up @@ -634,7 +626,7 @@ public boolean advanceExact(int target) throws IOException {
}

@Override
public long longValue() throws IOException {
public long longValue() {
return value;
}
};
Expand All @@ -661,7 +653,7 @@ public boolean advanceExact(int target) throws IOException {
}

@Override
public double doubleValue() throws IOException {
public double doubleValue() {
return value;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ public int docValueCount() {
public long nextValue() {
int lat = GeoEncodingUtils.encodeLatitude(script.lats()[cursor]);
int lon = GeoEncodingUtils.encodeLongitude(script.lons()[cursor++]);
return Long.valueOf((((long) lat) << 32) | (lon & 0xFFFFFFFFL));
return (((long) lat) << 32) | (lon & 0xFFFFFFFFL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ public long ramBytesUsed() {
return 0;
}

@Override
public void close() {

}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.elasticsearch.search.lookup.SearchLookup;

import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -90,7 +89,6 @@ public synchronized void clearField(final String fieldName) {
* Returns fielddata for the provided field type, given the provided fully qualified index name, while also making
* a {@link SearchLookup} supplier available that is required for runtime fields.
*/
@SuppressWarnings("unchecked")
public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType, FieldDataContext fieldDataContext) {
return getFromBuilder(fieldType, fieldType.fielddataBuilder(fieldDataContext));
}
Expand Down Expand Up @@ -134,7 +132,7 @@ public void setListener(IndexFieldDataCache.Listener listener) {
}

@Override
public void close() throws IOException {
public void close() {
clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,16 @@ private XFieldComparatorSource comparatorSource(
MultiValueMode sortMode,
Nested nested
) {
switch (targetNumericType) {
case HALF_FLOAT:
case FLOAT:
return new FloatValuesComparatorSource(this, missingValue, sortMode, nested);
case DOUBLE:
return new DoubleValuesComparatorSource(this, missingValue, sortMode, nested);
case DATE:
return dateComparatorSource(missingValue, sortMode, nested);
case DATE_NANOSECONDS:
return dateNanosComparatorSource(missingValue, sortMode, nested);
default:
return switch (targetNumericType) {
case HALF_FLOAT, FLOAT -> new FloatValuesComparatorSource(this, missingValue, sortMode, nested);
case DOUBLE -> new DoubleValuesComparatorSource(this, missingValue, sortMode, nested);
case DATE -> dateComparatorSource(missingValue, sortMode, nested);
case DATE_NANOSECONDS -> dateNanosComparatorSource(missingValue, sortMode, nested);
default -> {
assert targetNumericType.isFloatingPoint() == false;
return new LongValuesComparatorSource(this, missingValue, sortMode, nested, targetNumericType);
}
yield new LongValuesComparatorSource(this, missingValue, sortMode, nested, targetNumericType);
}
};
}

protected XFieldComparatorSource dateComparatorSource(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public interface LeafFieldData extends Accountable, Releasable {
*/
SortedBinaryDocValues getBytesValues();

@Override
default void close() {}

/**
* Return a formatted representation of the values
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;

import java.io.IOException;

public final class LongScriptFieldData extends IndexNumericFieldData {

public static class Builder implements IndexFieldData.Builder {
Expand Down Expand Up @@ -79,7 +77,7 @@ public LongScriptLeafFieldData load(LeafReaderContext context) {
}

@Override
public LongScriptLeafFieldData loadDirect(LeafReaderContext context) throws IOException {
public LongScriptLeafFieldData loadDirect(LeafReaderContext context) {
return new LongScriptLeafFieldData(new LongScriptDocValues(leafFactory.newInstance(context)), toScriptFieldFactory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public GeoPoint nextValue() throws IOException {
/**
* Returns a single-valued view of the {@link MultiPointValues} if possible, otherwise null.
*/
@Override
protected GeoPointValues getPointValues() {
final NumericDocValues singleton = DocValues.unwrapSingleton(numericValues);
return singleton != null ? new GeoPointValues(singleton) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,4 @@ public int docValueCount() {
*/
public abstract T nextValue() throws IOException;

/**
* Returns a single-valued view of the {@link MultiPointValues} if possible, otherwise null.
*/
protected abstract PointValues<T> getPointValues();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public RamAccountingTermsEnum(
* Always accept the term.
*/
@Override
protected AcceptStatus accept(BytesRef term) throws IOException {
protected AcceptStatus accept(BytesRef term) {
return AcceptStatus.YES;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class SortingNumericDocValues extends SortedNumericDocValues {
protected long[] values;
protected int valuesCursor;
private final Sorter sorter;
private LongConsumer circuitBreakerConsumer;
private final LongConsumer circuitBreakerConsumer;

protected SortingNumericDocValues() {
this(l -> {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ public long ramBytesUsed() {
return 0;
}

@Override
public void close() {

}

@Override
public SortedBinaryDocValues getBytesValues() {
throw new IllegalArgumentException("not supported for source fallback");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected SourceValueFetcherMultiGeoPointIndexFieldData(
}

@Override
public SourceValueFetcherMultiGeoPointLeafFieldData loadDirect(LeafReaderContext context) throws Exception {
public SourceValueFetcherMultiGeoPointLeafFieldData loadDirect(LeafReaderContext context) {
return new SourceValueFetcherMultiGeoPointLeafFieldData(toScriptFieldFactory, context, valueFetcher, sourceProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected SourceValueFetcherSortedBinaryIndexFieldData(
}

@Override
public SourceValueFetcherSortedBinaryLeafFieldData loadDirect(LeafReaderContext context) throws Exception {
public SourceValueFetcherSortedBinaryLeafFieldData loadDirect(LeafReaderContext context) {
return new SourceValueFetcherSortedBinaryLeafFieldData(toScriptFieldFactory, context, valueFetcher, sourceProvider);
}

Expand Down Expand Up @@ -127,7 +127,7 @@ public int docValueCount() {
}

@Override
public BytesRef nextValue() throws IOException {
public BytesRef nextValue() {
assert iterator.hasNext();
return iterator.next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected SourceValueFetcherSortedBooleanIndexFieldData(
}

@Override
public SourceValueFetcherLeafFieldData<SortedNumericDocValues> loadDirect(LeafReaderContext context) throws Exception {
public SourceValueFetcherLeafFieldData<SortedNumericDocValues> loadDirect(LeafReaderContext context) {
return new SourceValueFetcherSortedBooleanLeafFieldData(toScriptFieldFactory, context, valueFetcher, sourceProvider);
}

Expand Down Expand Up @@ -129,7 +129,7 @@ public int docValueCount() {
}

@Override
public long nextValue() throws IOException {
public long nextValue() {
assert iteratorIndex < trueCount + falseCount;
return iteratorIndex++ < falseCount ? 0L : 1L;
}
Expand All @@ -140,12 +140,12 @@ public int docID() {
}

@Override
public int nextDoc() throws IOException {
public int nextDoc() {
throw new UnsupportedOperationException("not supported for source fallback");
}

@Override
public int advance(int target) throws IOException {
public int advance(int target) {
throw new UnsupportedOperationException("not supported for source fallback");
}

Expand Down
Loading

0 comments on commit 3dcab9c

Please sign in to comment.