Skip to content

Commit f1f3b28

Browse files
jeffhajewskinik9000
authored andcommitted
Delete deprecated getValues from ScriptDocValues (#36183)
* Adds deprecation logging to ScriptDocValues#getValues. First commit addressing issue #22919. `ScriptDocValues#getValues` was added for backwards compatibility but no longer needed. Scripts using the syntax `doc['foo'].values` when `doc['foo']` is a list should be using `doc['foo']` instead. * Fixes two build errors in #34279 * Removes unused import in ScriptDocValuesDatesTest * Removes used of `.values` in example in diversified-sampler-aggregation.asciidoc * Removes use of .values from painless test. Part of #34279 * Updates tests to use `doc[foo]` syntax rather than `doc[foo].values`. * Removes use of `getValues()` and replaces use of `doc[foo].values` with `doc[foo]`. * Indentation fix. * Remove unnecessary list construction at previous `getValues()` callsite in ScriptDocValues.GeoPoints. * Update migration doc and add link to `getValue` in ScriptDocValues javadoc. * Fix compile * Fix javadoc issue * Removes ScriptDocValues#getValues usage from painless whitelist.
1 parent db8f07c commit f1f3b28

File tree

14 files changed

+32
-298
lines changed

14 files changed

+32
-298
lines changed

docs/reference/migration/migrate_7_0/scripting.asciidoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ To check if a document is missing a value, you can use
2929
Malformed scripts, either in search templates, ingest pipelines or search
3030
requests, return `400 - Bad request` while they would previously return
3131
`500 - Internal Server Error`. This also applies for stored scripts.
32+
33+
[float]
34+
==== getValues() removed
35+
36+
The `ScriptDocValues#getValues()` method is deprecated in 6.6 and will
37+
be removed in 7.0. Use `doc["foo"]` in place of `doc["foo"].values`.

modules/lang-painless/src/main/resources/org/elasticsearch/painless/spi/org.elasticsearch.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ class org.elasticsearch.common.geo.GeoPoint {
6767
class org.elasticsearch.index.fielddata.ScriptDocValues$Strings {
6868
String get(int)
6969
String getValue()
70-
List getValues()
7170
}
7271

7372
class org.elasticsearch.index.fielddata.ScriptDocValues$Longs {
7473
Long get(int)
7574
long getValue()
76-
List getValues()
7775
}
7876

7977
class org.elasticsearch.script.JodaCompatibleZonedDateTime {
@@ -163,19 +161,16 @@ class org.elasticsearch.script.JodaCompatibleZonedDateTime {
163161
class org.elasticsearch.index.fielddata.ScriptDocValues$Dates {
164162
JodaCompatibleZonedDateTime get(int)
165163
JodaCompatibleZonedDateTime getValue()
166-
List getValues()
167164
}
168165

169166
class org.elasticsearch.index.fielddata.ScriptDocValues$Doubles {
170167
Double get(int)
171168
double getValue()
172-
List getValues()
173169
}
174170

175171
class org.elasticsearch.index.fielddata.ScriptDocValues$GeoPoints {
176172
org.elasticsearch.common.geo.GeoPoint get(int)
177173
org.elasticsearch.common.geo.GeoPoint getValue()
178-
List getValues()
179174
double getLat()
180175
double getLon()
181176
double[] getLats()
@@ -193,13 +188,11 @@ class org.elasticsearch.index.fielddata.ScriptDocValues$GeoPoints {
193188
class org.elasticsearch.index.fielddata.ScriptDocValues$Booleans {
194189
Boolean get(int)
195190
boolean getValue()
196-
List getValues()
197191
}
198192

199193
class org.elasticsearch.index.fielddata.ScriptDocValues$BytesRefs {
200194
BytesRef get(int)
201195
BytesRef getValue()
202-
List getValues()
203196
}
204197

205198
class org.apache.lucene.util.BytesRef {
@@ -213,7 +206,6 @@ class org.apache.lucene.util.BytesRef {
213206
class org.elasticsearch.index.mapper.IpFieldMapper$IpFieldType$IpScriptDocValues {
214207
String get(int)
215208
String getValue()
216-
List getValues()
217209
}
218210

219211
class org.elasticsearch.search.lookup.FieldLookup {
@@ -268,4 +260,4 @@ static_import {
268260
int staticAddIntsTest(int, int) from_class org.elasticsearch.painless.StaticTest
269261
float staticAddFloatsTest(float, float) from_class org.elasticsearch.painless.FeatureTest
270262
int testAddWithState(int, int, int, double) bound_to org.elasticsearch.painless.BindingTest
271-
}
263+
}

server/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java

Lines changed: 7 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -19,73 +19,38 @@
1919

2020
package org.elasticsearch.index.fielddata;
2121

22-
import org.apache.logging.log4j.LogManager;
2322
import org.apache.lucene.index.SortedNumericDocValues;
2423
import org.apache.lucene.util.ArrayUtil;
2524
import org.apache.lucene.util.BytesRef;
2625
import org.apache.lucene.util.BytesRefBuilder;
2726
import org.elasticsearch.common.geo.GeoHashUtils;
2827
import org.elasticsearch.common.geo.GeoPoint;
2928
import org.elasticsearch.common.geo.GeoUtils;
30-
import org.elasticsearch.common.logging.DeprecationLogger;
3129
import org.elasticsearch.script.JodaCompatibleZonedDateTime;
3230

3331
import java.io.IOException;
34-
import java.security.AccessController;
35-
import java.security.PrivilegedAction;
3632
import java.time.Instant;
3733
import java.time.ZoneOffset;
3834
import java.util.AbstractList;
3935
import java.util.Arrays;
4036
import java.util.Comparator;
41-
import java.util.List;
42-
import java.util.function.BiConsumer;
4337
import java.util.function.UnaryOperator;
4438

4539
/**
4640
* Script level doc values, the assumption is that any implementation will
47-
* implement a <code>getValue</code> and a <code>getValues</code> that return
48-
* the relevant type that then can be used in scripts.
41+
* implement a {@link Longs#getValue getValue} method.
4942
*
5043
* Implementations should not internally re-use objects for the values that they
5144
* return as a single {@link ScriptDocValues} instance can be reused to return
5245
* values form multiple documents.
5346
*/
5447
public abstract class ScriptDocValues<T> extends AbstractList<T> {
5548

56-
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(ScriptDocValues.class));
57-
/**
58-
* Callback for deprecated fields. In production this should always point to
59-
* {@link #deprecationLogger} but tests will override it so they can test
60-
* that we use the required permissions when calling it.
61-
*/
62-
private final BiConsumer<String, String> deprecationCallback;
63-
64-
public ScriptDocValues() {
65-
deprecationCallback = deprecationLogger::deprecatedAndMaybeLog;
66-
}
67-
68-
/**
69-
* Constructor for testing deprecation callback.
70-
*/
71-
ScriptDocValues(BiConsumer<String, String> deprecationCallback) {
72-
this.deprecationCallback = deprecationCallback;
73-
}
74-
7549
/**
7650
* Set the current doc ID.
7751
*/
7852
public abstract void setNextDocId(int docId) throws IOException;
7953

80-
/**
81-
* Return a copy of the list of the values for the current document.
82-
*/
83-
public final List<T> getValues() {
84-
deprecated("ScriptDocValues#getValues", "Deprecated getValues used, the field is a list and should be accessed directly."
85-
+ " For example, use doc['foo'] instead of doc['foo'].values.");
86-
return this;
87-
}
88-
8954
// Throw meaningful exceptions if someone tries to modify the ScriptDocValues.
9055
@Override
9156
public final void add(int index, T element) {
@@ -112,21 +77,6 @@ public final void sort(Comparator<? super T> c) {
11277
throw new UnsupportedOperationException("doc values are unmodifiable");
11378
}
11479

115-
/**
116-
* Log a deprecation log, with the server's permissions and not the permissions
117-
* of the script calling this method. We need to do this to prevent errors
118-
* when rolling the log file.
119-
*/
120-
private void deprecated(String key, String message) {
121-
AccessController.doPrivileged(new PrivilegedAction<Void>() {
122-
@Override
123-
public Void run() {
124-
deprecationCallback.accept(key, message);
125-
return null;
126-
}
127-
});
128-
}
129-
13080
public static final class Longs extends ScriptDocValues<Long> {
13181
private final SortedNumericDocValues in;
13282
private long[] values = new long[0];
@@ -139,14 +89,6 @@ public Longs(SortedNumericDocValues in) {
13989
this.in = in;
14090
}
14191

142-
/**
143-
* Constructor for testing deprecation callback.
144-
*/
145-
Longs(SortedNumericDocValues in, BiConsumer<String, String> deprecationCallback) {
146-
super(deprecationCallback);
147-
this.in = in;
148-
}
149-
15092
@Override
15193
public void setNextDocId(int docId) throws IOException {
15294
if (in.advanceExact(docId)) {
@@ -204,14 +146,6 @@ public Dates(SortedNumericDocValues in) {
204146
this.in = in;
205147
}
206148

207-
/**
208-
* Constructor for testing deprecation callback.
209-
*/
210-
Dates(SortedNumericDocValues in, BiConsumer<String, String> deprecationCallback) {
211-
super(deprecationCallback);
212-
this.in = in;
213-
}
214-
215149
/**
216150
* Fetch the first field value or 0 millis after epoch if there are no
217151
* in.
@@ -330,14 +264,6 @@ public GeoPoints(MultiGeoPointValues in) {
330264
this.in = in;
331265
}
332266

333-
/**
334-
* Constructor for testing deprecation callback.
335-
*/
336-
GeoPoints(MultiGeoPointValues in, BiConsumer<String, String> deprecationCallback) {
337-
super(deprecationCallback);
338-
this.in = in;
339-
}
340-
341267
@Override
342268
public void setNextDocId(int docId) throws IOException {
343269
if (in.advanceExact(docId)) {
@@ -379,19 +305,17 @@ public double getLat() {
379305
}
380306

381307
public double[] getLats() {
382-
List<GeoPoint> points = getValues();
383-
double[] lats = new double[points.size()];
384-
for (int i = 0; i < points.size(); i++) {
385-
lats[i] = points.get(i).lat();
308+
double[] lats = new double[size()];
309+
for (int i = 0; i < size(); i++) {
310+
lats[i] = get(i).lat();
386311
}
387312
return lats;
388313
}
389314

390315
public double[] getLons() {
391-
List<GeoPoint> points = getValues();
392-
double[] lons = new double[points.size()];
393-
for (int i = 0; i < points.size(); i++) {
394-
lons[i] = points.get(i).lon();
316+
double[] lons = new double[size()];
317+
for (int i = 0; i < size(); i++) {
318+
lons[i] = get(i).lon();
395319
}
396320
return lons;
397321
}

server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesDatesTests.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)