Minor cleanup of runtime fields classes (#62531)

This commit addresses some compiler warnings in the runtime fields classes
This commit is contained in:
Luca Cavanna 2020-09-17 14:45:55 +02:00
parent 567510da40
commit 3cf559bf9c
9 changed files with 20 additions and 35 deletions

View File

@ -59,7 +59,7 @@ public abstract class BinaryScriptFieldData implements IndexFieldData<BinaryScri
throw new IllegalArgumentException("only supported on numeric fields");
}
public abstract class BinaryScriptLeafFieldData implements LeafFieldData {
public abstract static class BinaryScriptLeafFieldData implements LeafFieldData {
@Override
public long ramBytesUsed() {
return 0;

View File

@ -9,8 +9,6 @@ package org.elasticsearch.xpack.runtimefields.fielddata;
import org.elasticsearch.index.fielddata.AbstractSortedNumericDocValues;
import org.elasticsearch.xpack.runtimefields.mapper.BooleanFieldScript;
import java.io.IOException;
public final class BooleanScriptDocValues extends AbstractSortedNumericDocValues {
private final BooleanFieldScript script;
private int cursor;
@ -27,7 +25,7 @@ public final class BooleanScriptDocValues extends AbstractSortedNumericDocValues
}
@Override
public long nextValue() throws IOException {
public long nextValue() {
// Emit all false values before all true values
return cursor++ < script.falses() ? 0 : 1;
}

View File

@ -19,8 +19,6 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.xpack.runtimefields.mapper.BooleanFieldScript;
import java.io.IOException;
public final class BooleanScriptFieldData extends IndexNumericFieldData {
public static class Builder implements IndexFieldData.Builder {
@ -66,7 +64,7 @@ public final class BooleanScriptFieldData extends IndexNumericFieldData {
}
@Override
public BooleanScriptLeafFieldData loadDirect(LeafReaderContext context) throws IOException {
public BooleanScriptLeafFieldData loadDirect(LeafReaderContext context) {
return new BooleanScriptLeafFieldData(new BooleanScriptDocValues(leafFactory.newInstance(context)));
}

View File

@ -19,8 +19,6 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.xpack.runtimefields.mapper.DateFieldScript;
import java.io.IOException;
public final class DateScriptFieldData extends IndexNumericFieldData {
public static class Builder implements IndexFieldData.Builder {
@ -66,7 +64,7 @@ public final class DateScriptFieldData extends IndexNumericFieldData {
}
@Override
public DateScriptLeafFieldData loadDirect(LeafReaderContext context) throws IOException {
public DateScriptLeafFieldData loadDirect(LeafReaderContext context) {
return new DateScriptLeafFieldData(new LongScriptDocValues(leafFactory.newInstance(context)));
}

View File

@ -9,7 +9,6 @@ package org.elasticsearch.xpack.runtimefields.fielddata;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import org.elasticsearch.xpack.runtimefields.mapper.DoubleFieldScript;
import java.io.IOException;
import java.util.Arrays;
public final class DoubleScriptDocValues extends SortedNumericDoubleValues {
@ -32,7 +31,7 @@ public final class DoubleScriptDocValues extends SortedNumericDoubleValues {
}
@Override
public double nextValue() throws IOException {
public double nextValue() {
return script.values()[cursor++];
}

View File

@ -19,8 +19,6 @@ import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.xpack.runtimefields.mapper.DoubleFieldScript;
import java.io.IOException;
public final class DoubleScriptFieldData extends IndexNumericFieldData {
public static class Builder implements IndexFieldData.Builder {
@ -66,7 +64,7 @@ public final class DoubleScriptFieldData extends IndexNumericFieldData {
}
@Override
public DoubleScriptLeafFieldData loadDirect(LeafReaderContext context) throws IOException {
public DoubleScriptLeafFieldData loadDirect(LeafReaderContext context) {
return new DoubleScriptLeafFieldData(new DoubleScriptDocValues(leafFactory.newInstance(context)));
}

View File

@ -34,7 +34,7 @@ public abstract class AbstractFieldScript {
static final int MAX_VALUES = 100;
public static <F> ScriptContext<F> newContext(String name, Class<F> factoryClass) {
return new ScriptContext<F>(
return new ScriptContext<>(
name + "_script_field",
factoryClass,
/*

View File

@ -86,15 +86,15 @@ abstract class AbstractScriptMappedFieldTypeTestCase extends ESTestCase {
return context;
}
public void testExistsQueryIsExpensive() throws IOException {
public void testExistsQueryIsExpensive() {
checkExpensiveQuery(MappedFieldType::existsQuery);
}
public void testExistsQueryInLoop() throws IOException {
public void testExistsQueryInLoop() {
checkLoop(MappedFieldType::existsQuery);
}
public void testRangeQueryWithShapeRelationIsError() throws IOException {
public void testRangeQueryWithShapeRelationIsError() {
Exception e = expectThrows(
IllegalArgumentException.class,
() -> simpleMappedFieldType().rangeQuery(1, 2, true, true, ShapeRelation.DISJOINT, null, null, null)
@ -105,27 +105,27 @@ abstract class AbstractScriptMappedFieldTypeTestCase extends ESTestCase {
);
}
public void testRangeQueryIsExpensive() throws IOException {
public void testRangeQueryIsExpensive() {
checkExpensiveQuery(this::randomRangeQuery);
}
public void testRangeQueryInLoop() throws IOException {
public void testRangeQueryInLoop() {
checkLoop(this::randomRangeQuery);
}
public void testTermQueryIsExpensive() throws IOException {
public void testTermQueryIsExpensive() {
checkExpensiveQuery(this::randomTermQuery);
}
public void testTermQueryInLoop() throws IOException {
public void testTermQueryInLoop() {
checkLoop(this::randomTermQuery);
}
public void testTermsQueryIsExpensive() throws IOException {
public void testTermsQueryIsExpensive() {
checkExpensiveQuery(this::randomTermsQuery);
}
public void testTermsQueryInLoop() throws IOException {
public void testTermsQueryInLoop() {
checkLoop(this::randomTermsQuery);
}
@ -163,7 +163,7 @@ abstract class AbstractScriptMappedFieldTypeTestCase extends ESTestCase {
return reader.document(docId).getBinaryValue("_source").utf8ToString();
}
protected final void checkExpensiveQuery(BiConsumer<MappedFieldType, QueryShardContext> queryBuilder) throws IOException {
protected final void checkExpensiveQuery(BiConsumer<MappedFieldType, QueryShardContext> queryBuilder) {
Exception e = expectThrows(ElasticsearchException.class, () -> queryBuilder.accept(simpleMappedFieldType(), mockContext(false)));
assertThat(
e.getMessage(),
@ -171,7 +171,7 @@ abstract class AbstractScriptMappedFieldTypeTestCase extends ESTestCase {
);
}
protected final void checkLoop(BiConsumer<MappedFieldType, QueryShardContext> queryBuilder) throws IOException {
protected final void checkLoop(BiConsumer<MappedFieldType, QueryShardContext> queryBuilder) {
Exception e = expectThrows(IllegalArgumentException.class, () -> queryBuilder.accept(loopFieldType(), mockContext()));
assertThat(e.getMessage(), equalTo("Cyclic dependency detected while resolving runtime fields: test -> test"));
}

View File

@ -35,6 +35,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import static org.hamcrest.Matchers.equalTo;
@ -381,14 +382,7 @@ public class RuntimeFieldMapperTests extends MapperTestCase {
};
public Set<ScriptContext<?>> getSupportedContexts() {
return org.elasticsearch.common.collect.Set.of(
BooleanFieldScript.CONTEXT,
DateFieldScript.CONTEXT,
DoubleFieldScript.CONTEXT,
IpFieldScript.CONTEXT,
StringFieldScript.CONTEXT,
LongFieldScript.CONTEXT
);
return new HashSet<>(new RuntimeFields().getContexts());
}
};
}