Shorten runtime field type class names (#63123)

In the codebase there is the non-written convention that classes that extend `MappedFieldType` are generally called `*FieldType`. With this commit we adopt the same convention for runtime field types which allows us to shorten their names by removing the `Mapped` portion which is implicit.
This commit is contained in:
Luca Cavanna 2020-10-01 17:31:24 +02:00
parent e91f66e22f
commit a42a516b67
17 changed files with 74 additions and 97 deletions

View File

@ -32,11 +32,11 @@ import static org.elasticsearch.search.SearchService.ALLOW_EXPENSIVE_QUERIES;
/** /**
* Abstract base {@linkplain MappedFieldType} for scripted fields. * Abstract base {@linkplain MappedFieldType} for scripted fields.
*/ */
abstract class AbstractScriptMappedFieldType<LeafFactory> extends MappedFieldType { abstract class AbstractScriptFieldType<LeafFactory> extends MappedFieldType {
protected final Script script; protected final Script script;
private final TriFunction<String, Map<String, Object>, SearchLookup, LeafFactory> factory; private final TriFunction<String, Map<String, Object>, SearchLookup, LeafFactory> factory;
AbstractScriptMappedFieldType( AbstractScriptFieldType(
String name, String name,
Script script, Script script,
TriFunction<String, Map<String, Object>, SearchLookup, LeafFactory> factory, TriFunction<String, Map<String, Object>, SearchLookup, LeafFactory> factory,

View File

@ -27,8 +27,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BooleanScriptMappedFieldType extends AbstractScriptMappedFieldType<BooleanFieldScript.LeafFactory> { public class BooleanScriptFieldType extends AbstractScriptFieldType<BooleanFieldScript.LeafFactory> {
BooleanScriptMappedFieldType(String name, Script script, BooleanFieldScript.Factory scriptFactory, Map<String, String> meta) { BooleanScriptFieldType(String name, Script script, BooleanFieldScript.Factory scriptFactory, Map<String, String> meta) {
super(name, script, scriptFactory::newFactory, meta); super(name, script, scriptFactory::newFactory, meta);
} }

View File

@ -35,10 +35,10 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
public class DateScriptMappedFieldType extends AbstractScriptMappedFieldType<DateFieldScript.LeafFactory> { public class DateScriptFieldType extends AbstractScriptFieldType<DateFieldScript.LeafFactory> {
private final DateFormatter dateTimeFormatter; private final DateFormatter dateTimeFormatter;
DateScriptMappedFieldType( DateScriptFieldType(
String name, String name,
Script script, Script script,
DateFieldScript.Factory scriptFactory, DateFieldScript.Factory scriptFactory,

View File

@ -27,8 +27,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
public class DoubleScriptMappedFieldType extends AbstractScriptMappedFieldType<DoubleFieldScript.LeafFactory> { public class DoubleScriptFieldType extends AbstractScriptFieldType<DoubleFieldScript.LeafFactory> {
DoubleScriptMappedFieldType(String name, Script script, DoubleFieldScript.Factory scriptFactory, Map<String, String> meta) { DoubleScriptFieldType(String name, Script script, DoubleFieldScript.Factory scriptFactory, Map<String, String> meta) {
super(name, script, scriptFactory::newFactory, meta); super(name, script, scriptFactory::newFactory, meta);
} }

View File

@ -36,8 +36,8 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
public final class IpScriptMappedFieldType extends AbstractScriptMappedFieldType<IpFieldScript.LeafFactory> { public final class IpScriptFieldType extends AbstractScriptFieldType<IpFieldScript.LeafFactory> {
IpScriptMappedFieldType(String name, Script script, IpFieldScript.Factory scriptFactory, Map<String, String> meta) { IpScriptFieldType(String name, Script script, IpFieldScript.Factory scriptFactory, Map<String, String> meta) {
super(name, script, scriptFactory::newFactory, meta); super(name, script, scriptFactory::newFactory, meta);
} }

View File

@ -35,8 +35,8 @@ import java.util.function.Supplier;
import static java.util.stream.Collectors.toSet; import static java.util.stream.Collectors.toSet;
public final class KeywordScriptMappedFieldType extends AbstractScriptMappedFieldType<StringFieldScript.LeafFactory> { public final class KeywordScriptFieldType extends AbstractScriptFieldType<StringFieldScript.LeafFactory> {
KeywordScriptMappedFieldType(String name, Script script, StringFieldScript.Factory scriptFactory, Map<String, String> meta) { KeywordScriptFieldType(String name, Script script, StringFieldScript.Factory scriptFactory, Map<String, String> meta) {
super(name, script, scriptFactory::newFactory, meta); super(name, script, scriptFactory::newFactory, meta);
} }

View File

@ -27,8 +27,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
public class LongScriptMappedFieldType extends AbstractScriptMappedFieldType<LongFieldScript.LeafFactory> { public class LongScriptFieldType extends AbstractScriptFieldType<LongFieldScript.LeafFactory> {
LongScriptMappedFieldType(String name, Script script, LongFieldScript.Factory scriptFactory, Map<String, String> meta) { LongScriptFieldType(String name, Script script, LongFieldScript.Factory scriptFactory, Map<String, String> meta) {
super(name, script, scriptFactory::newFactory, meta); super(name, script, scriptFactory::newFactory, meta);
} }

View File

@ -47,7 +47,7 @@ public final class RuntimeFieldMapper extends ParametrizedFieldMapper {
protected RuntimeFieldMapper( protected RuntimeFieldMapper(
String simpleName, String simpleName,
AbstractScriptMappedFieldType<?> mappedFieldType, AbstractScriptFieldType<?> mappedFieldType,
MultiFields multiFields, MultiFields multiFields,
CopyTo copyTo, CopyTo copyTo,
String runtimeType, String runtimeType,
@ -60,14 +60,6 @@ public final class RuntimeFieldMapper extends ParametrizedFieldMapper {
this.scriptCompiler = scriptCompiler; this.scriptCompiler = scriptCompiler;
} }
String runtimeType() {
return runtimeType;
}
Script script() {
return script;
}
@Override @Override
public ParametrizedFieldMapper.Builder getMergeBuilder() { public ParametrizedFieldMapper.Builder getMergeBuilder() {
return new RuntimeFieldMapper.Builder(simpleName(), scriptCompiler).init(this); return new RuntimeFieldMapper.Builder(simpleName(), scriptCompiler).init(this);
@ -90,11 +82,11 @@ public final class RuntimeFieldMapper extends ParametrizedFieldMapper {
public static class Builder extends ParametrizedFieldMapper.Builder { public static class Builder extends ParametrizedFieldMapper.Builder {
static final Map<String, BiFunction<Builder, BuilderContext, AbstractScriptMappedFieldType<?>>> FIELD_TYPE_RESOLVER = static final Map<String, BiFunction<Builder, BuilderContext, AbstractScriptFieldType<?>>> FIELD_TYPE_RESOLVER =
org.elasticsearch.common.collect.Map.of(BooleanFieldMapper.CONTENT_TYPE, (builder, context) -> { org.elasticsearch.common.collect.Map.of(BooleanFieldMapper.CONTENT_TYPE, (builder, context) -> {
builder.formatAndLocaleNotSupported(); builder.formatAndLocaleNotSupported();
BooleanFieldScript.Factory factory = builder.scriptCompiler.compile(builder.script.getValue(), BooleanFieldScript.CONTEXT); BooleanFieldScript.Factory factory = builder.scriptCompiler.compile(builder.script.getValue(), BooleanFieldScript.CONTEXT);
return new BooleanScriptMappedFieldType( return new BooleanScriptFieldType(
builder.buildFullName(context), builder.buildFullName(context),
builder.script.getValue(), builder.script.getValue(),
factory, factory,
@ -111,7 +103,7 @@ public final class RuntimeFieldMapper extends ParametrizedFieldMapper {
locale = Locale.ROOT; locale = Locale.ROOT;
} }
DateFormatter dateTimeFormatter = DateFormatter.forPattern(format).withLocale(locale); DateFormatter dateTimeFormatter = DateFormatter.forPattern(format).withLocale(locale);
return new DateScriptMappedFieldType( return new DateScriptFieldType(
builder.buildFullName(context), builder.buildFullName(context),
builder.script.getValue(), builder.script.getValue(),
factory, factory,
@ -121,7 +113,7 @@ public final class RuntimeFieldMapper extends ParametrizedFieldMapper {
}, NumberType.DOUBLE.typeName(), (builder, context) -> { }, NumberType.DOUBLE.typeName(), (builder, context) -> {
builder.formatAndLocaleNotSupported(); builder.formatAndLocaleNotSupported();
DoubleFieldScript.Factory factory = builder.scriptCompiler.compile(builder.script.getValue(), DoubleFieldScript.CONTEXT); DoubleFieldScript.Factory factory = builder.scriptCompiler.compile(builder.script.getValue(), DoubleFieldScript.CONTEXT);
return new DoubleScriptMappedFieldType( return new DoubleScriptFieldType(
builder.buildFullName(context), builder.buildFullName(context),
builder.script.getValue(), builder.script.getValue(),
factory, factory,
@ -130,16 +122,11 @@ public final class RuntimeFieldMapper extends ParametrizedFieldMapper {
}, IpFieldMapper.CONTENT_TYPE, (builder, context) -> { }, IpFieldMapper.CONTENT_TYPE, (builder, context) -> {
builder.formatAndLocaleNotSupported(); builder.formatAndLocaleNotSupported();
IpFieldScript.Factory factory = builder.scriptCompiler.compile(builder.script.getValue(), IpFieldScript.CONTEXT); IpFieldScript.Factory factory = builder.scriptCompiler.compile(builder.script.getValue(), IpFieldScript.CONTEXT);
return new IpScriptMappedFieldType( return new IpScriptFieldType(builder.buildFullName(context), builder.script.getValue(), factory, builder.meta.getValue());
builder.buildFullName(context),
builder.script.getValue(),
factory,
builder.meta.getValue()
);
}, KeywordFieldMapper.CONTENT_TYPE, (builder, context) -> { }, KeywordFieldMapper.CONTENT_TYPE, (builder, context) -> {
builder.formatAndLocaleNotSupported(); builder.formatAndLocaleNotSupported();
StringFieldScript.Factory factory = builder.scriptCompiler.compile(builder.script.getValue(), StringFieldScript.CONTEXT); StringFieldScript.Factory factory = builder.scriptCompiler.compile(builder.script.getValue(), StringFieldScript.CONTEXT);
return new KeywordScriptMappedFieldType( return new KeywordScriptFieldType(
builder.buildFullName(context), builder.buildFullName(context),
builder.script.getValue(), builder.script.getValue(),
factory, factory,
@ -148,12 +135,7 @@ public final class RuntimeFieldMapper extends ParametrizedFieldMapper {
}, NumberType.LONG.typeName(), (builder, context) -> { }, NumberType.LONG.typeName(), (builder, context) -> {
builder.formatAndLocaleNotSupported(); builder.formatAndLocaleNotSupported();
LongFieldScript.Factory factory = builder.scriptCompiler.compile(builder.script.getValue(), LongFieldScript.CONTEXT); LongFieldScript.Factory factory = builder.scriptCompiler.compile(builder.script.getValue(), LongFieldScript.CONTEXT);
return new LongScriptMappedFieldType( return new LongScriptFieldType(builder.buildFullName(context), builder.script.getValue(), factory, builder.meta.getValue());
builder.buildFullName(context),
builder.script.getValue(),
factory,
builder.meta.getValue()
);
}); });
private static RuntimeFieldMapper toType(FieldMapper in) { private static RuntimeFieldMapper toType(FieldMapper in) {
@ -185,7 +167,7 @@ public final class RuntimeFieldMapper extends ParametrizedFieldMapper {
private final Parameter<String> format = Parameter.stringParam( private final Parameter<String> format = Parameter.stringParam(
"format", "format",
true, true,
mapper -> ((AbstractScriptMappedFieldType<?>) mapper.fieldType()).format(), mapper -> ((AbstractScriptFieldType<?>) mapper.fieldType()).format(),
null null
).setSerializer((b, n, v) -> { ).setSerializer((b, n, v) -> {
if (v != null && false == v.equals(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.pattern())) { if (v != null && false == v.equals(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.pattern())) {
@ -197,7 +179,7 @@ public final class RuntimeFieldMapper extends ParametrizedFieldMapper {
true, true,
() -> null, () -> null,
(n, c, o) -> o == null ? null : LocaleUtils.parse(o.toString()), (n, c, o) -> o == null ? null : LocaleUtils.parse(o.toString()),
mapper -> ((AbstractScriptMappedFieldType<?>) mapper.fieldType()).formatLocale() mapper -> ((AbstractScriptFieldType<?>) mapper.fieldType()).formatLocale()
).setSerializer((b, n, v) -> { ).setSerializer((b, n, v) -> {
if (v != null && false == v.equals(Locale.ROOT)) { if (v != null && false == v.equals(Locale.ROOT)) {
b.field(n, v.toString()); b.field(n, v.toString());
@ -218,7 +200,7 @@ public final class RuntimeFieldMapper extends ParametrizedFieldMapper {
@Override @Override
public RuntimeFieldMapper build(BuilderContext context) { public RuntimeFieldMapper build(BuilderContext context) {
BiFunction<Builder, BuilderContext, AbstractScriptMappedFieldType<?>> fieldTypeResolver = Builder.FIELD_TYPE_RESOLVER.get( BiFunction<Builder, BuilderContext, AbstractScriptFieldType<?>> fieldTypeResolver = Builder.FIELD_TYPE_RESOLVER.get(
runtimeType.getValue() runtimeType.getValue()
); );
if (fieldTypeResolver == null) { if (fieldTypeResolver == null) {

View File

@ -13,7 +13,7 @@ import java.io.IOException;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
abstract class AbstractNonTextScriptMappedFieldTypeTestCase extends AbstractScriptMappedFieldTypeTestCase { abstract class AbstractNonTextScriptFieldTypeTestCase extends AbstractScriptFieldTypeTestCase {
public void testFuzzyQueryIsError() throws IOException { public void testFuzzyQueryIsError() throws IOException {
assertQueryOnlyOnTextAndKeyword( assertQueryOnlyOnTextAndKeyword(
"fuzzy", "fuzzy",

View File

@ -25,7 +25,7 @@ import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
abstract class AbstractScriptMappedFieldTypeTestCase extends ESTestCase { abstract class AbstractScriptFieldTypeTestCase extends ESTestCase {
protected abstract MappedFieldType simpleMappedFieldType() throws IOException; protected abstract MappedFieldType simpleMappedFieldType() throws IOException;
protected abstract MappedFieldType loopFieldType() throws IOException; protected abstract MappedFieldType loopFieldType() throws IOException;

View File

@ -66,7 +66,7 @@ import static org.hamcrest.Matchers.instanceOf;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
public class BooleanScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedFieldTypeTestCase { public class BooleanScriptFieldTypeTests extends AbstractNonTextScriptFieldTypeTestCase {
@Override @Override
public void testDocValues() throws IOException { public void testDocValues() throws IOException {
try (Directory directory = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), directory)) { try (Directory directory = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), directory)) {
@ -75,7 +75,7 @@ public class BooleanScriptMappedFieldTypeTests extends AbstractNonTextScriptMapp
List<Long> results = new ArrayList<>(); List<Long> results = new ArrayList<>();
try (DirectoryReader reader = iw.getReader()) { try (DirectoryReader reader = iw.getReader()) {
IndexSearcher searcher = newSearcher(reader); IndexSearcher searcher = newSearcher(reader);
BooleanScriptMappedFieldType ft = simpleMappedFieldType(); BooleanScriptFieldType ft = simpleMappedFieldType();
BooleanScriptFieldData ifd = ft.fielddataBuilder("test", mockContext()::lookup).build(null, null, null); BooleanScriptFieldData ifd = ft.fielddataBuilder("test", mockContext()::lookup).build(null, null, null);
searcher.search(new MatchAllDocsQuery(), new Collector() { searcher.search(new MatchAllDocsQuery(), new Collector() {
@Override @Override
@ -436,7 +436,7 @@ public class BooleanScriptMappedFieldTypeTests extends AbstractNonTextScriptMapp
} }
@Override @Override
protected BooleanScriptMappedFieldType simpleMappedFieldType() throws IOException { protected BooleanScriptFieldType simpleMappedFieldType() throws IOException {
return build("read_foo", org.elasticsearch.common.collect.Map.of()); return build("read_foo", org.elasticsearch.common.collect.Map.of());
} }
@ -450,11 +450,11 @@ public class BooleanScriptMappedFieldTypeTests extends AbstractNonTextScriptMapp
return "boolean"; return "boolean";
} }
private static BooleanScriptMappedFieldType build(String code, Map<String, Object> params) throws IOException { private static BooleanScriptFieldType build(String code, Map<String, Object> params) throws IOException {
return build(new Script(ScriptType.INLINE, "test", code, params)); return build(new Script(ScriptType.INLINE, "test", code, params));
} }
private static BooleanScriptMappedFieldType build(Script script) throws IOException { private static BooleanScriptFieldType build(Script script) throws IOException {
ScriptPlugin scriptPlugin = new ScriptPlugin() { ScriptPlugin scriptPlugin = new ScriptPlugin() {
@Override @Override
public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) { public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
@ -520,7 +520,7 @@ public class BooleanScriptMappedFieldTypeTests extends AbstractNonTextScriptMapp
); );
try (ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptModule.engines, scriptModule.contexts)) { try (ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptModule.engines, scriptModule.contexts)) {
BooleanFieldScript.Factory factory = scriptService.compile(script, BooleanFieldScript.CONTEXT); BooleanFieldScript.Factory factory = scriptService.compile(script, BooleanFieldScript.CONTEXT);
return new BooleanScriptMappedFieldType("test", script, factory, emptyMap()); return new BooleanScriptFieldType("test", script, factory, emptyMap());
} }
} }
} }

View File

@ -64,7 +64,7 @@ import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class DateScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedFieldTypeTestCase { public class DateScriptFieldTypeTests extends AbstractNonTextScriptFieldTypeTestCase {
public void testFormat() throws IOException { public void testFormat() throws IOException {
assertThat(simpleMappedFieldType().docValueFormat("date", null).format(1595432181354L), equalTo("2020-07-22")); assertThat(simpleMappedFieldType().docValueFormat("date", null).format(1595432181354L), equalTo("2020-07-22"));
assertThat( assertThat(
@ -84,7 +84,7 @@ public class DateScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedF
public void testFormatDuel() throws IOException { public void testFormatDuel() throws IOException {
DateFormatter formatter = DateFormatter.forPattern(randomDateFormatterPattern()).withLocale(randomLocale(random())); DateFormatter formatter = DateFormatter.forPattern(randomDateFormatterPattern()).withLocale(randomLocale(random()));
DateScriptMappedFieldType scripted = build( DateScriptFieldType scripted = build(
new Script(ScriptType.INLINE, "test", "read_timestamp", org.elasticsearch.common.collect.Map.of()), new Script(ScriptType.INLINE, "test", "read_timestamp", org.elasticsearch.common.collect.Map.of()),
formatter formatter
); );
@ -114,7 +114,7 @@ public class DateScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedF
List<Long> results = new ArrayList<>(); List<Long> results = new ArrayList<>();
try (DirectoryReader reader = iw.getReader()) { try (DirectoryReader reader = iw.getReader()) {
IndexSearcher searcher = newSearcher(reader); IndexSearcher searcher = newSearcher(reader);
DateScriptMappedFieldType ft = build("add_days", org.elasticsearch.common.collect.Map.of("days", 1)); DateScriptFieldType ft = build("add_days", org.elasticsearch.common.collect.Map.of("days", 1));
DateScriptFieldData ifd = ft.fielddataBuilder("test", mockContext()::lookup).build(null, null, null); DateScriptFieldData ifd = ft.fielddataBuilder("test", mockContext()::lookup).build(null, null, null);
searcher.search(new MatchAllDocsQuery(), new Collector() { searcher.search(new MatchAllDocsQuery(), new Collector() {
@Override @Override
@ -347,7 +347,7 @@ public class DateScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedF
@Override @Override
protected Query randomRangeQuery(MappedFieldType ft, QueryShardContext ctx) { protected Query randomRangeQuery(MappedFieldType ft, QueryShardContext ctx) {
long d1 = randomDate(); long d1 = randomDate();
long d2 = randomValueOtherThan(d1, DateScriptMappedFieldTypeTests::randomDate); long d2 = randomValueOtherThan(d1, DateScriptFieldTypeTests::randomDate);
if (d1 > d2) { if (d1 > d2) {
long backup = d2; long backup = d2;
d2 = d1; d2 = d1;
@ -454,11 +454,11 @@ public class DateScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedF
@Override @Override
protected Query randomTermsQuery(MappedFieldType ft, QueryShardContext ctx) { protected Query randomTermsQuery(MappedFieldType ft, QueryShardContext ctx) {
return ft.termsQuery(randomList(1, 100, DateScriptMappedFieldTypeTests::randomDate), ctx); return ft.termsQuery(randomList(1, 100, DateScriptFieldTypeTests::randomDate), ctx);
} }
@Override @Override
protected DateScriptMappedFieldType simpleMappedFieldType() throws IOException { protected DateScriptFieldType simpleMappedFieldType() throws IOException {
return build("read_timestamp"); return build("read_timestamp");
} }
@ -467,7 +467,7 @@ public class DateScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedF
return build("loop"); return build("loop");
} }
private DateScriptMappedFieldType coolFormattedFieldType() throws IOException { private DateScriptFieldType coolFormattedFieldType() throws IOException {
return build(simpleMappedFieldType().script, DateFormatter.forPattern("yyyy-MM-dd(-■_■)HH:mm:ss.SSSz||epoch_millis")); return build(simpleMappedFieldType().script, DateFormatter.forPattern("yyyy-MM-dd(-■_■)HH:mm:ss.SSSz||epoch_millis"));
} }
@ -476,15 +476,15 @@ public class DateScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedF
return "date"; return "date";
} }
private static DateScriptMappedFieldType build(String code) throws IOException { private static DateScriptFieldType build(String code) throws IOException {
return build(code, org.elasticsearch.common.collect.Map.of()); return build(code, org.elasticsearch.common.collect.Map.of());
} }
private static DateScriptMappedFieldType build(String code, Map<String, Object> params) throws IOException { private static DateScriptFieldType build(String code, Map<String, Object> params) throws IOException {
return build(new Script(ScriptType.INLINE, "test", code, params), DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER); return build(new Script(ScriptType.INLINE, "test", code, params), DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER);
} }
private static DateScriptMappedFieldType build(Script script, DateFormatter dateTimeFormatter) throws IOException { private static DateScriptFieldType build(Script script, DateFormatter dateTimeFormatter) throws IOException {
ScriptPlugin scriptPlugin = new ScriptPlugin() { ScriptPlugin scriptPlugin = new ScriptPlugin() {
@Override @Override
public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) { public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
@ -566,7 +566,7 @@ public class DateScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedF
); );
try (ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptModule.engines, scriptModule.contexts)) { try (ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptModule.engines, scriptModule.contexts)) {
DateFieldScript.Factory factory = scriptService.compile(script, DateFieldScript.CONTEXT); DateFieldScript.Factory factory = scriptService.compile(script, DateFieldScript.CONTEXT);
return new DateScriptMappedFieldType("test", script, factory, dateTimeFormatter, emptyMap()); return new DateScriptFieldType("test", script, factory, dateTimeFormatter, emptyMap());
} }
} }

View File

@ -51,7 +51,7 @@ import java.util.Set;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class DoubleScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedFieldTypeTestCase { public class DoubleScriptFieldTypeTests extends AbstractNonTextScriptFieldTypeTestCase {
public void testFormat() throws IOException { public void testFormat() throws IOException {
assertThat(simpleMappedFieldType().docValueFormat("#.0", null).format(1), equalTo("1.0")); assertThat(simpleMappedFieldType().docValueFormat("#.0", null).format(1), equalTo("1.0"));
assertThat(simpleMappedFieldType().docValueFormat("#.0", null).format(1.2), equalTo("1.2")); assertThat(simpleMappedFieldType().docValueFormat("#.0", null).format(1.2), equalTo("1.2"));
@ -69,7 +69,7 @@ public class DoubleScriptMappedFieldTypeTests extends AbstractNonTextScriptMappe
List<Double> results = new ArrayList<>(); List<Double> results = new ArrayList<>();
try (DirectoryReader reader = iw.getReader()) { try (DirectoryReader reader = iw.getReader()) {
IndexSearcher searcher = newSearcher(reader); IndexSearcher searcher = newSearcher(reader);
DoubleScriptMappedFieldType ft = build("add_param", org.elasticsearch.common.collect.Map.of("param", 1)); DoubleScriptFieldType ft = build("add_param", org.elasticsearch.common.collect.Map.of("param", 1));
DoubleScriptFieldData ifd = ft.fielddataBuilder("test", mockContext()::lookup).build(null, null, null); DoubleScriptFieldData ifd = ft.fielddataBuilder("test", mockContext()::lookup).build(null, null, null);
searcher.search(new MatchAllDocsQuery(), new Collector() { searcher.search(new MatchAllDocsQuery(), new Collector() {
@Override @Override
@ -245,7 +245,7 @@ public class DoubleScriptMappedFieldTypeTests extends AbstractNonTextScriptMappe
} }
@Override @Override
protected DoubleScriptMappedFieldType simpleMappedFieldType() throws IOException { protected DoubleScriptFieldType simpleMappedFieldType() throws IOException {
return build("read_foo", org.elasticsearch.common.collect.Map.of()); return build("read_foo", org.elasticsearch.common.collect.Map.of());
} }
@ -259,11 +259,11 @@ public class DoubleScriptMappedFieldTypeTests extends AbstractNonTextScriptMappe
return "double"; return "double";
} }
private static DoubleScriptMappedFieldType build(String code, Map<String, Object> params) throws IOException { private static DoubleScriptFieldType build(String code, Map<String, Object> params) throws IOException {
return build(new Script(ScriptType.INLINE, "test", code, params)); return build(new Script(ScriptType.INLINE, "test", code, params));
} }
private static DoubleScriptMappedFieldType build(Script script) throws IOException { private static DoubleScriptFieldType build(Script script) throws IOException {
ScriptPlugin scriptPlugin = new ScriptPlugin() { ScriptPlugin scriptPlugin = new ScriptPlugin() {
@Override @Override
public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) { public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
@ -329,7 +329,7 @@ public class DoubleScriptMappedFieldTypeTests extends AbstractNonTextScriptMappe
); );
try (ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptModule.engines, scriptModule.contexts)) { try (ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptModule.engines, scriptModule.contexts)) {
DoubleFieldScript.Factory factory = scriptService.compile(script, DoubleFieldScript.CONTEXT); DoubleFieldScript.Factory factory = scriptService.compile(script, DoubleFieldScript.CONTEXT);
return new DoubleScriptMappedFieldType("test", script, factory, emptyMap()); return new DoubleScriptFieldType("test", script, factory, emptyMap());
} }
} }
} }

View File

@ -54,7 +54,7 @@ import static java.util.Collections.emptyMap;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.sameInstance; import static org.hamcrest.Matchers.sameInstance;
public class IpScriptMappedFieldTypeTests extends AbstractScriptMappedFieldTypeTestCase { public class IpScriptFieldTypeTests extends AbstractScriptFieldTypeTestCase {
public void testFormat() throws IOException { public void testFormat() throws IOException {
assertThat(simpleMappedFieldType().docValueFormat(null, null), sameInstance(DocValueFormat.IP)); assertThat(simpleMappedFieldType().docValueFormat(null, null), sameInstance(DocValueFormat.IP));
Exception e = expectThrows(IllegalArgumentException.class, () -> simpleMappedFieldType().docValueFormat("ASDFA", null)); Exception e = expectThrows(IllegalArgumentException.class, () -> simpleMappedFieldType().docValueFormat("ASDFA", null));
@ -77,7 +77,7 @@ public class IpScriptMappedFieldTypeTests extends AbstractScriptMappedFieldTypeT
List<Object> results = new ArrayList<>(); List<Object> results = new ArrayList<>();
try (DirectoryReader reader = iw.getReader()) { try (DirectoryReader reader = iw.getReader()) {
IndexSearcher searcher = newSearcher(reader); IndexSearcher searcher = newSearcher(reader);
IpScriptMappedFieldType ft = build("append_param", org.elasticsearch.common.collect.Map.of("param", ".1")); IpScriptFieldType ft = build("append_param", org.elasticsearch.common.collect.Map.of("param", ".1"));
BinaryScriptFieldData ifd = ft.fielddataBuilder("test", mockContext()::lookup).build(null, null, null); BinaryScriptFieldData ifd = ft.fielddataBuilder("test", mockContext()::lookup).build(null, null, null);
DocValueFormat format = ft.docValueFormat(null, null); DocValueFormat format = ft.docValueFormat(null, null);
searcher.search(new MatchAllDocsQuery(), new Collector() { searcher.search(new MatchAllDocsQuery(), new Collector() {
@ -231,7 +231,7 @@ public class IpScriptMappedFieldTypeTests extends AbstractScriptMappedFieldTypeT
iw.addDocument(org.elasticsearch.common.collect.List.of(new StoredField("_source", new BytesRef("{\"foo\": [\"200.0.0\"]}")))); iw.addDocument(org.elasticsearch.common.collect.List.of(new StoredField("_source", new BytesRef("{\"foo\": [\"200.0.0\"]}"))));
try (DirectoryReader reader = iw.getReader()) { try (DirectoryReader reader = iw.getReader()) {
IndexSearcher searcher = newSearcher(reader); IndexSearcher searcher = newSearcher(reader);
IpScriptMappedFieldType fieldType = build("append_param", org.elasticsearch.common.collect.Map.of("param", ".1")); IpScriptFieldType fieldType = build("append_param", org.elasticsearch.common.collect.Map.of("param", ".1"));
assertThat(searcher.count(fieldType.termQuery("192.168.0.1", mockContext())), equalTo(1)); assertThat(searcher.count(fieldType.termQuery("192.168.0.1", mockContext())), equalTo(1));
assertThat(searcher.count(fieldType.termQuery("192.168.0.7", mockContext())), equalTo(0)); assertThat(searcher.count(fieldType.termQuery("192.168.0.7", mockContext())), equalTo(0));
assertThat(searcher.count(fieldType.termQuery("192.168.0.0/16", mockContext())), equalTo(2)); assertThat(searcher.count(fieldType.termQuery("192.168.0.0/16", mockContext())), equalTo(2));
@ -288,7 +288,7 @@ public class IpScriptMappedFieldTypeTests extends AbstractScriptMappedFieldTypeT
} }
@Override @Override
protected IpScriptMappedFieldType simpleMappedFieldType() throws IOException { protected IpScriptFieldType simpleMappedFieldType() throws IOException {
return build("read_foo", org.elasticsearch.common.collect.Map.of()); return build("read_foo", org.elasticsearch.common.collect.Map.of());
} }
@ -302,11 +302,11 @@ public class IpScriptMappedFieldTypeTests extends AbstractScriptMappedFieldTypeT
return "ip"; return "ip";
} }
private static IpScriptMappedFieldType build(String code, Map<String, Object> params) throws IOException { private static IpScriptFieldType build(String code, Map<String, Object> params) throws IOException {
return build(new Script(ScriptType.INLINE, "test", code, params)); return build(new Script(ScriptType.INLINE, "test", code, params));
} }
private static IpScriptMappedFieldType build(Script script) throws IOException { private static IpScriptFieldType build(Script script) throws IOException {
ScriptPlugin scriptPlugin = new ScriptPlugin() { ScriptPlugin scriptPlugin = new ScriptPlugin() {
@Override @Override
public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) { public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
@ -372,7 +372,7 @@ public class IpScriptMappedFieldTypeTests extends AbstractScriptMappedFieldTypeT
); );
try (ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptModule.engines, scriptModule.contexts)) { try (ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptModule.engines, scriptModule.contexts)) {
IpFieldScript.Factory factory = scriptService.compile(script, IpFieldScript.CONTEXT); IpFieldScript.Factory factory = scriptService.compile(script, IpFieldScript.CONTEXT);
return new IpScriptMappedFieldType("test", script, factory, emptyMap()); return new IpScriptFieldType("test", script, factory, emptyMap());
} }
} }
} }

View File

@ -55,7 +55,7 @@ import java.util.Set;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class KeywordScriptMappedFieldTypeTests extends AbstractScriptMappedFieldTypeTestCase { public class KeywordScriptFieldTypeTests extends AbstractScriptFieldTypeTestCase {
@Override @Override
public void testDocValues() throws IOException { public void testDocValues() throws IOException {
try (Directory directory = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), directory)) { try (Directory directory = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), directory)) {
@ -64,7 +64,7 @@ public class KeywordScriptMappedFieldTypeTests extends AbstractScriptMappedField
List<String> results = new ArrayList<>(); List<String> results = new ArrayList<>();
try (DirectoryReader reader = iw.getReader()) { try (DirectoryReader reader = iw.getReader()) {
IndexSearcher searcher = newSearcher(reader); IndexSearcher searcher = newSearcher(reader);
KeywordScriptMappedFieldType ft = build("append_param", org.elasticsearch.common.collect.Map.of("param", "-suffix")); KeywordScriptFieldType ft = build("append_param", org.elasticsearch.common.collect.Map.of("param", "-suffix"));
StringScriptFieldData ifd = ft.fielddataBuilder("test", mockContext()::lookup).build(null, null, null); StringScriptFieldData ifd = ft.fielddataBuilder("test", mockContext()::lookup).build(null, null, null);
searcher.search(new MatchAllDocsQuery(), new Collector() { searcher.search(new MatchAllDocsQuery(), new Collector() {
@Override @Override
@ -282,7 +282,7 @@ public class KeywordScriptMappedFieldTypeTests extends AbstractScriptMappedField
iw.addDocument(org.elasticsearch.common.collect.List.of(new StoredField("_source", new BytesRef("{\"foo\": [2]}")))); iw.addDocument(org.elasticsearch.common.collect.List.of(new StoredField("_source", new BytesRef("{\"foo\": [2]}"))));
try (DirectoryReader reader = iw.getReader()) { try (DirectoryReader reader = iw.getReader()) {
IndexSearcher searcher = newSearcher(reader); IndexSearcher searcher = newSearcher(reader);
KeywordScriptMappedFieldType fieldType = build("append_param", org.elasticsearch.common.collect.Map.of("param", "-suffix")); KeywordScriptFieldType fieldType = build("append_param", org.elasticsearch.common.collect.Map.of("param", "-suffix"));
assertThat(searcher.count(fieldType.termQuery("1-suffix", mockContext())), equalTo(1)); assertThat(searcher.count(fieldType.termQuery("1-suffix", mockContext())), equalTo(1));
} }
} }
@ -344,7 +344,7 @@ public class KeywordScriptMappedFieldTypeTests extends AbstractScriptMappedField
iw.addDocument(org.elasticsearch.common.collect.List.of(new StoredField("_source", new BytesRef("{\"foo\": [2]}")))); iw.addDocument(org.elasticsearch.common.collect.List.of(new StoredField("_source", new BytesRef("{\"foo\": [2]}"))));
try (DirectoryReader reader = iw.getReader()) { try (DirectoryReader reader = iw.getReader()) {
IndexSearcher searcher = newSearcher(reader); IndexSearcher searcher = newSearcher(reader);
KeywordScriptMappedFieldType fieldType = build("append_param", org.elasticsearch.common.collect.Map.of("param", "-Suffix")); KeywordScriptFieldType fieldType = build("append_param", org.elasticsearch.common.collect.Map.of("param", "-Suffix"));
QueryShardContext queryShardContext = mockContext(true, fieldType); QueryShardContext queryShardContext = mockContext(true, fieldType);
Query query = new MatchQueryBuilder("test", "1-Suffix").toQuery(queryShardContext); Query query = new MatchQueryBuilder("test", "1-Suffix").toQuery(queryShardContext);
assertThat(searcher.count(query), equalTo(1)); assertThat(searcher.count(query), equalTo(1));
@ -353,12 +353,12 @@ public class KeywordScriptMappedFieldTypeTests extends AbstractScriptMappedField
} }
@Override @Override
protected KeywordScriptMappedFieldType simpleMappedFieldType() throws IOException { protected KeywordScriptFieldType simpleMappedFieldType() throws IOException {
return build("read_foo", org.elasticsearch.common.collect.Map.of()); return build("read_foo", org.elasticsearch.common.collect.Map.of());
} }
@Override @Override
protected KeywordScriptMappedFieldType loopFieldType() throws IOException { protected KeywordScriptFieldType loopFieldType() throws IOException {
return build("loop", org.elasticsearch.common.collect.Map.of()); return build("loop", org.elasticsearch.common.collect.Map.of());
} }
@ -367,11 +367,11 @@ public class KeywordScriptMappedFieldTypeTests extends AbstractScriptMappedField
return "keyword"; return "keyword";
} }
private static KeywordScriptMappedFieldType build(String code, Map<String, Object> params) throws IOException { private static KeywordScriptFieldType build(String code, Map<String, Object> params) throws IOException {
return build(new Script(ScriptType.INLINE, "test", code, params)); return build(new Script(ScriptType.INLINE, "test", code, params));
} }
private static KeywordScriptMappedFieldType build(Script script) throws IOException { private static KeywordScriptFieldType build(Script script) throws IOException {
ScriptPlugin scriptPlugin = new ScriptPlugin() { ScriptPlugin scriptPlugin = new ScriptPlugin() {
@Override @Override
public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) { public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
@ -437,7 +437,7 @@ public class KeywordScriptMappedFieldTypeTests extends AbstractScriptMappedField
); );
try (ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptModule.engines, scriptModule.contexts)) { try (ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptModule.engines, scriptModule.contexts)) {
StringFieldScript.Factory factory = scriptService.compile(script, StringFieldScript.CONTEXT); StringFieldScript.Factory factory = scriptService.compile(script, StringFieldScript.CONTEXT);
return new KeywordScriptMappedFieldType("test", script, factory, emptyMap()); return new KeywordScriptFieldType("test", script, factory, emptyMap());
} }
} }
} }

View File

@ -54,7 +54,7 @@ import static java.util.Collections.emptyMap;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
public class LongScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedFieldTypeTestCase { public class LongScriptFieldTypeTests extends AbstractNonTextScriptFieldTypeTestCase {
public void testFormat() throws IOException { public void testFormat() throws IOException {
assertThat(simpleMappedFieldType().docValueFormat("#.0", null).format(1), equalTo("1.0")); assertThat(simpleMappedFieldType().docValueFormat("#.0", null).format(1), equalTo("1.0"));
assertThat(simpleMappedFieldType().docValueFormat("#,##0.##", null).format(11), equalTo("11")); assertThat(simpleMappedFieldType().docValueFormat("#,##0.##", null).format(11), equalTo("11"));
@ -69,7 +69,7 @@ public class LongScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedF
List<Long> results = new ArrayList<>(); List<Long> results = new ArrayList<>();
try (DirectoryReader reader = iw.getReader()) { try (DirectoryReader reader = iw.getReader()) {
IndexSearcher searcher = newSearcher(reader); IndexSearcher searcher = newSearcher(reader);
LongScriptMappedFieldType ft = build("add_param", org.elasticsearch.common.collect.Map.of("param", 1)); LongScriptFieldType ft = build("add_param", org.elasticsearch.common.collect.Map.of("param", 1));
LongScriptFieldData ifd = ft.fielddataBuilder("test", mockContext()::lookup).build(null, null, null); LongScriptFieldData ifd = ft.fielddataBuilder("test", mockContext()::lookup).build(null, null, null);
searcher.search(new MatchAllDocsQuery(), new Collector() { searcher.search(new MatchAllDocsQuery(), new Collector() {
@Override @Override
@ -272,12 +272,12 @@ public class LongScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedF
} }
@Override @Override
protected LongScriptMappedFieldType simpleMappedFieldType() throws IOException { protected LongScriptFieldType simpleMappedFieldType() throws IOException {
return build("read_foo", Collections.emptyMap()); return build("read_foo", Collections.emptyMap());
} }
@Override @Override
protected LongScriptMappedFieldType loopFieldType() throws IOException { protected LongScriptFieldType loopFieldType() throws IOException {
return build("loop", org.elasticsearch.common.collect.Map.of()); return build("loop", org.elasticsearch.common.collect.Map.of());
} }
@ -286,11 +286,11 @@ public class LongScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedF
return "long"; return "long";
} }
private static LongScriptMappedFieldType build(String code, Map<String, Object> params) throws IOException { private static LongScriptFieldType build(String code, Map<String, Object> params) throws IOException {
return build(new Script(ScriptType.INLINE, "test", code, params)); return build(new Script(ScriptType.INLINE, "test", code, params));
} }
private static LongScriptMappedFieldType build(Script script) throws IOException { private static LongScriptFieldType build(Script script) throws IOException {
ScriptPlugin scriptPlugin = new ScriptPlugin() { ScriptPlugin scriptPlugin = new ScriptPlugin() {
@Override @Override
public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) { public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
@ -367,7 +367,7 @@ public class LongScriptMappedFieldTypeTests extends AbstractNonTextScriptMappedF
); );
try (ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptModule.engines, scriptModule.contexts)) { try (ScriptService scriptService = new ScriptService(Settings.EMPTY, scriptModule.engines, scriptModule.contexts)) {
LongFieldScript.Factory factory = scriptService.compile(script, LongFieldScript.CONTEXT); LongFieldScript.Factory factory = scriptService.compile(script, LongFieldScript.CONTEXT);
return new LongScriptMappedFieldType("test", script, factory, emptyMap()); return new LongScriptFieldType("test", script, factory, emptyMap());
} }
} }
} }

View File

@ -329,12 +329,7 @@ public class RuntimeFieldMapperTests extends MapperTestCase {
IllegalArgumentException iae = expectThrows( IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> config.buildIndexSort( () -> config.buildIndexSort(
field -> new KeywordScriptMappedFieldType( field -> new KeywordScriptFieldType(field, new Script(""), mock(StringFieldScript.Factory.class), Collections.emptyMap()),
field,
new Script(""),
mock(StringFieldScript.Factory.class),
Collections.emptyMap()
),
(fieldType, searchLookupSupplier) -> indexFieldDataService.getForField(fieldType, "index", searchLookupSupplier) (fieldType, searchLookupSupplier) -> indexFieldDataService.getForField(fieldType, "index", searchLookupSupplier)
) )
); );