Skip to content

Commit 509f1d1

Browse files
authored
Remove unnecessary method AbstractFieldScript#getSource. (#65294)
Previously it looked like `_source` was exposed as a top-level parameter in runtime field scripts. The method is only used in tests and can be removed altogether.
1 parent 0986ae9 commit 509f1d1

File tree

9 files changed

+17
-23
lines changed

9 files changed

+17
-23
lines changed

x-pack/plugin/runtime-fields/src/main/java/org/elasticsearch/xpack/runtimefields/mapper/AbstractFieldScript.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@ public final Map<String, Object> getParams() {
8787
return params;
8888
}
8989

90-
/**
91-
* Expose the {@code _source} to the script.
92-
*/
93-
protected final Map<String, Object> getSource() {
94-
return leafSearchLookup.source();
95-
}
96-
9790
/**
9891
* Expose field data to the script as {@code doc}.
9992
*/

x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/BooleanScriptFieldTypeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ private BooleanFieldScript.Factory factory(String code) {
437437
return (fieldName, params, lookup) -> (ctx) -> new BooleanFieldScript(fieldName, params, lookup, ctx) {
438438
@Override
439439
public void execute() {
440-
for (Object foo : (List<?>) getSource().get("foo")) {
440+
for (Object foo : (List<?>) lookup.source().get("foo")) {
441441
emit((Boolean) foo);
442442
}
443443
}
@@ -446,7 +446,7 @@ public void execute() {
446446
return (fieldName, params, lookup) -> (ctx) -> new BooleanFieldScript(fieldName, params, lookup, ctx) {
447447
@Override
448448
public void execute() {
449-
for (Object foo : (List<?>) getSource().get("foo")) {
449+
for (Object foo : (List<?>) lookup.source().get("foo")) {
450450
emit((Boolean) foo ^ ((Boolean) getParams().get("param")));
451451
}
452452
}

x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/DateScriptFieldTypeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ private DateFieldScript.Factory factory(String code) {
497497
) {
498498
@Override
499499
public void execute() {
500-
for (Object timestamp : (List<?>) getSource().get("timestamp")) {
500+
for (Object timestamp : (List<?>) lookup.source().get("timestamp")) {
501501
DateFieldScript.Parse parse = new DateFieldScript.Parse(this);
502502
emit(parse.parse(timestamp));
503503
}
@@ -513,7 +513,7 @@ public void execute() {
513513
) {
514514
@Override
515515
public void execute() {
516-
for (Object timestamp : (List<?>) getSource().get("timestamp")) {
516+
for (Object timestamp : (List<?>) lookup.source().get("timestamp")) {
517517
long epoch = (Long) timestamp;
518518
ZonedDateTime dt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(epoch), ZoneId.of("UTC"));
519519
dt = dt.plus(((Number) params.get("days")).longValue(), ChronoUnit.DAYS);

x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/DoubleScriptFieldTypeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private DoubleFieldScript.Factory factory(String code) {
279279
return (fieldName, params, lookup) -> (ctx) -> new DoubleFieldScript(fieldName, params, lookup, ctx) {
280280
@Override
281281
public void execute() {
282-
for (Object foo : (List<?>) getSource().get("foo")) {
282+
for (Object foo : (List<?>) lookup.source().get("foo")) {
283283
emit(((Number) foo).doubleValue());
284284
}
285285
}
@@ -288,7 +288,7 @@ public void execute() {
288288
return (fieldName, params, lookup) -> (ctx) -> new DoubleFieldScript(fieldName, params, lookup, ctx) {
289289
@Override
290290
public void execute() {
291-
for (Object foo : (List<?>) getSource().get("foo")) {
291+
for (Object foo : (List<?>) lookup.source().get("foo")) {
292292
emit(((Number) foo).doubleValue() + ((Number) getParams().get("param")).doubleValue());
293293
}
294294
}

x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/GeoPointScriptFieldTypeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ private GeoPointFieldScript.Factory factory(String code) {
249249
return (fieldName, params, lookup) -> (ctx) -> new GeoPointFieldScript(fieldName, params, lookup, ctx) {
250250
@Override
251251
public void execute() {
252-
Map<?, ?> foo = (Map<?, ?>) getSource().get("foo");
252+
Map<?, ?> foo = (Map<?, ?>) lookup.source().get("foo");
253253
emit(((Number) foo.get("lat")).doubleValue(), ((Number) foo.get("lon")).doubleValue());
254254
}
255255
};

x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/IpScriptFieldTypeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ private IpFieldScript.Factory factory(String code) {
296296
return (fieldName, params, lookup) -> (ctx) -> new IpFieldScript(fieldName, params, lookup, ctx) {
297297
@Override
298298
public void execute() {
299-
for (Object foo : (List<?>) getSource().get("foo")) {
299+
for (Object foo : (List<?>) lookup.source().get("foo")) {
300300
emit(foo.toString());
301301
}
302302
}
@@ -305,7 +305,7 @@ public void execute() {
305305
return (fieldName, params, lookup) -> (ctx) -> new IpFieldScript(fieldName, params, lookup, ctx) {
306306
@Override
307307
public void execute() {
308-
for (Object foo : (List<?>) getSource().get("foo")) {
308+
for (Object foo : (List<?>) lookup.source().get("foo")) {
309309
emit(foo.toString() + getParams().get("param"));
310310
}
311311
}

x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/KeywordScriptFieldTypeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ private StringFieldScript.Factory factory(String code) {
397397
return (fieldName, params, lookup) -> ctx -> new StringFieldScript(fieldName, params, lookup, ctx) {
398398
@Override
399399
public void execute() {
400-
for (Object foo : (List<?>) getSource().get("foo")) {
400+
for (Object foo : (List<?>) lookup.source().get("foo")) {
401401
emit(foo.toString());
402402
}
403403
}
@@ -406,7 +406,7 @@ public void execute() {
406406
return (fieldName, params, lookup) -> ctx -> new StringFieldScript(fieldName, params, lookup, ctx) {
407407
@Override
408408
public void execute() {
409-
for (Object foo : (List<?>) getSource().get("foo")) {
409+
for (Object foo : (List<?>) lookup.source().get("foo")) {
410410
emit(foo.toString() + getParams().get("param").toString());
411411
}
412412
}

x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/LongScriptFieldTypeTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ private LongFieldScript.Factory factory(String code) {
298298
return (fieldName, params, lookup) -> (ctx) -> new LongFieldScript(fieldName, params, lookup, ctx) {
299299
@Override
300300
public void execute() {
301-
for (Object foo : (List<?>) getSource().get("foo")) {
301+
for (Object foo : (List<?>) lookup.source().get("foo")) {
302302
emit(((Number) foo).longValue());
303303
}
304304
}
@@ -307,7 +307,7 @@ public void execute() {
307307
return (fieldName, params, lookup) -> (ctx) -> new LongFieldScript(fieldName, params, lookup, ctx) {
308308
@Override
309309
public void execute() {
310-
for (Object foo : (List<?>) getSource().get("foo")) {
310+
for (Object foo : (List<?>) lookup.source().get("foo")) {
311311
emit(((Number) foo).longValue() + ((Number) getParams().get("param")).longValue());
312312
}
313313
}
@@ -318,7 +318,7 @@ public void execute() {
318318
return (fieldName, params, lookup) -> (ctx) -> new LongFieldScript(fieldName, params, lookup, ctx) {
319319
@Override
320320
public void execute() {
321-
for (Object timestamp : (List<?>) getSource().get("timestamp")) {
321+
for (Object timestamp : (List<?>) lookup.source().get("timestamp")) {
322322
emit(now - ((Number) timestamp).longValue());
323323
}
324324
}

x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/query/LongScriptFieldDistanceFeatureQueryTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,17 @@ public void testMatches() throws IOException {
7575
iw.addDocument(List.of(new StoredField("_source", new BytesRef("{\"timestamp\": [1595432181351]}"))));
7676
try (DirectoryReader reader = iw.getReader()) {
7777
IndexSearcher searcher = newSearcher(reader);
78+
SearchLookup searchLookup = new SearchLookup(null, null);
7879
Function<LeafReaderContext, AbstractLongFieldScript> leafFactory = ctx -> new DateFieldScript(
7980
"test",
8081
Map.of(),
81-
new SearchLookup(null, null),
82+
searchLookup,
8283
null,
8384
ctx
8485
) {
8586
@Override
8687
public void execute() {
87-
for (Object timestamp : (List<?>) getSource().get("timestamp")) {
88+
for (Object timestamp : (List<?>) searchLookup.source().get("timestamp")) {
8889
emit(((Number) timestamp).longValue());
8990
}
9091
}

0 commit comments

Comments
 (0)