|
@@ -19,7 +19,6 @@
|
|
|
|
|
|
package org.elasticsearch.index.fielddata;
|
|
|
|
|
|
-import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.lucene.index.SortedNumericDocValues;
|
|
|
import org.apache.lucene.util.ArrayUtil;
|
|
|
import org.apache.lucene.util.BytesRef;
|
|
@@ -27,25 +26,19 @@ import org.apache.lucene.util.BytesRefBuilder;
|
|
|
import org.elasticsearch.common.geo.GeoHashUtils;
|
|
|
import org.elasticsearch.common.geo.GeoPoint;
|
|
|
import org.elasticsearch.common.geo.GeoUtils;
|
|
|
-import org.elasticsearch.common.logging.DeprecationLogger;
|
|
|
import org.elasticsearch.script.JodaCompatibleZonedDateTime;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.security.AccessController;
|
|
|
-import java.security.PrivilegedAction;
|
|
|
import java.time.Instant;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.util.AbstractList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.function.BiConsumer;
|
|
|
import java.util.function.UnaryOperator;
|
|
|
|
|
|
/**
|
|
|
* Script level doc values, the assumption is that any implementation will
|
|
|
- * implement a <code>getValue</code> and a <code>getValues</code> that return
|
|
|
- * the relevant type that then can be used in scripts.
|
|
|
+ * implement a {@link Longs#getValue getValue} method.
|
|
|
*
|
|
|
* Implementations should not internally re-use objects for the values that they
|
|
|
* return as a single {@link ScriptDocValues} instance can be reused to return
|
|
@@ -53,39 +46,11 @@ import java.util.function.UnaryOperator;
|
|
|
*/
|
|
|
public abstract class ScriptDocValues<T> extends AbstractList<T> {
|
|
|
|
|
|
- private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(ScriptDocValues.class));
|
|
|
- /**
|
|
|
- * Callback for deprecated fields. In production this should always point to
|
|
|
- * {@link #deprecationLogger} but tests will override it so they can test
|
|
|
- * that we use the required permissions when calling it.
|
|
|
- */
|
|
|
- private final BiConsumer<String, String> deprecationCallback;
|
|
|
-
|
|
|
- public ScriptDocValues() {
|
|
|
- deprecationCallback = deprecationLogger::deprecatedAndMaybeLog;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Constructor for testing deprecation callback.
|
|
|
- */
|
|
|
- ScriptDocValues(BiConsumer<String, String> deprecationCallback) {
|
|
|
- this.deprecationCallback = deprecationCallback;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Set the current doc ID.
|
|
|
*/
|
|
|
public abstract void setNextDocId(int docId) throws IOException;
|
|
|
|
|
|
- /**
|
|
|
- * Return a copy of the list of the values for the current document.
|
|
|
- */
|
|
|
- public final List<T> getValues() {
|
|
|
- deprecated("ScriptDocValues#getValues", "Deprecated getValues used, the field is a list and should be accessed directly."
|
|
|
- + " For example, use doc['foo'] instead of doc['foo'].values.");
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
// Throw meaningful exceptions if someone tries to modify the ScriptDocValues.
|
|
|
@Override
|
|
|
public final void add(int index, T element) {
|
|
@@ -112,21 +77,6 @@ public abstract class ScriptDocValues<T> extends AbstractList<T> {
|
|
|
throw new UnsupportedOperationException("doc values are unmodifiable");
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Log a deprecation log, with the server's permissions and not the permissions
|
|
|
- * of the script calling this method. We need to do this to prevent errors
|
|
|
- * when rolling the log file.
|
|
|
- */
|
|
|
- private void deprecated(String key, String message) {
|
|
|
- AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
|
|
- @Override
|
|
|
- public Void run() {
|
|
|
- deprecationCallback.accept(key, message);
|
|
|
- return null;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
public static final class Longs extends ScriptDocValues<Long> {
|
|
|
private final SortedNumericDocValues in;
|
|
|
private long[] values = new long[0];
|
|
@@ -139,14 +89,6 @@ public abstract class ScriptDocValues<T> extends AbstractList<T> {
|
|
|
this.in = in;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Constructor for testing deprecation callback.
|
|
|
- */
|
|
|
- Longs(SortedNumericDocValues in, BiConsumer<String, String> deprecationCallback) {
|
|
|
- super(deprecationCallback);
|
|
|
- this.in = in;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void setNextDocId(int docId) throws IOException {
|
|
|
if (in.advanceExact(docId)) {
|
|
@@ -204,14 +146,6 @@ public abstract class ScriptDocValues<T> extends AbstractList<T> {
|
|
|
this.in = in;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Constructor for testing deprecation callback.
|
|
|
- */
|
|
|
- Dates(SortedNumericDocValues in, BiConsumer<String, String> deprecationCallback) {
|
|
|
- super(deprecationCallback);
|
|
|
- this.in = in;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Fetch the first field value or 0 millis after epoch if there are no
|
|
|
* in.
|
|
@@ -330,14 +264,6 @@ public abstract class ScriptDocValues<T> extends AbstractList<T> {
|
|
|
this.in = in;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Constructor for testing deprecation callback.
|
|
|
- */
|
|
|
- GeoPoints(MultiGeoPointValues in, BiConsumer<String, String> deprecationCallback) {
|
|
|
- super(deprecationCallback);
|
|
|
- this.in = in;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void setNextDocId(int docId) throws IOException {
|
|
|
if (in.advanceExact(docId)) {
|
|
@@ -379,19 +305,17 @@ public abstract class ScriptDocValues<T> extends AbstractList<T> {
|
|
|
}
|
|
|
|
|
|
public double[] getLats() {
|
|
|
- List<GeoPoint> points = getValues();
|
|
|
- double[] lats = new double[points.size()];
|
|
|
- for (int i = 0; i < points.size(); i++) {
|
|
|
- lats[i] = points.get(i).lat();
|
|
|
+ double[] lats = new double[size()];
|
|
|
+ for (int i = 0; i < size(); i++) {
|
|
|
+ lats[i] = get(i).lat();
|
|
|
}
|
|
|
return lats;
|
|
|
}
|
|
|
|
|
|
public double[] getLons() {
|
|
|
- List<GeoPoint> points = getValues();
|
|
|
- double[] lons = new double[points.size()];
|
|
|
- for (int i = 0; i < points.size(); i++) {
|
|
|
- lons[i] = points.get(i).lon();
|
|
|
+ double[] lons = new double[size()];
|
|
|
+ for (int i = 0; i < size(); i++) {
|
|
|
+ lons[i] = get(i).lon();
|
|
|
}
|
|
|
return lons;
|
|
|
}
|