Backport for #64523 Relates to #64361
This commit is contained in:
parent
1ceafb4d00
commit
8c25130a80
|
@ -102,13 +102,18 @@ GET /my_index/_search
|
|||
--------------------------------
|
||||
//TEST[continued]
|
||||
|
||||
Similarly to sort values, script values of an `unsigned_long` field
|
||||
return a `Number` representing a `Long` or `BigInteger`.
|
||||
The same values: `Long` or `BigInteger` are used for `terms` aggregations.
|
||||
|
||||
==== Unsigned long in scripts
|
||||
Currently unsigned_long is not supported in scripts.
|
||||
|
||||
==== Stored fields
|
||||
A stored field of `unsigned_long` is stored and returned as `String`.
|
||||
|
||||
==== Aggregations
|
||||
For `terms` aggregations, similarly to sort values, `Long` or
|
||||
`BigInteger` values are used. For other aggregations,
|
||||
values are converted to the `double` type.
|
||||
|
||||
==== Queries with mixed numeric types
|
||||
|
||||
Searches with mixed numeric types one of which is `unsigned_long` are
|
||||
|
|
|
@ -29,7 +29,6 @@ import java.lang.invoke.CallSite;
|
|||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.math.BigInteger;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
|
@ -761,8 +760,6 @@ public final class Def {
|
|||
return (float)value;
|
||||
} else if (value instanceof Double) {
|
||||
return (double)value;
|
||||
} else if (value instanceof BigInteger) {
|
||||
return ((BigInteger)value).doubleValue();
|
||||
} else {
|
||||
throw new ClassCastException("cannot implicitly cast " +
|
||||
"def [" + PainlessLookupUtility.typeToUnboxedType(value.getClass()).getCanonicalName() + "] to " +
|
||||
|
@ -895,8 +892,7 @@ public final class Def {
|
|||
value instanceof Integer ||
|
||||
value instanceof Long ||
|
||||
value instanceof Float ||
|
||||
value instanceof Double ||
|
||||
value instanceof BigInteger
|
||||
value instanceof Double
|
||||
) {
|
||||
return ((Number)value).doubleValue();
|
||||
} else {
|
||||
|
@ -1035,8 +1031,6 @@ public final class Def {
|
|||
return (double)(float)value;
|
||||
} else if (value instanceof Double) {
|
||||
return (Double) value;
|
||||
} else if (value instanceof BigInteger) {
|
||||
return ((BigInteger)value).doubleValue();
|
||||
} else {
|
||||
throw new ClassCastException("cannot implicitly cast " +
|
||||
"def [" + PainlessLookupUtility.typeToUnboxedType(value.getClass()).getCanonicalName() + "] to " +
|
||||
|
@ -1183,8 +1177,7 @@ public final class Def {
|
|||
value instanceof Integer ||
|
||||
value instanceof Long ||
|
||||
value instanceof Float ||
|
||||
value instanceof Double ||
|
||||
value instanceof BigInteger
|
||||
value instanceof Double
|
||||
) {
|
||||
return ((Number)value).doubleValue();
|
||||
} else {
|
||||
|
|
|
@ -166,7 +166,6 @@ public class DefCastTests extends ScriptTestCase {
|
|||
assertEquals((double)0, exec("def d = Long.valueOf(0); double b = d; b"));
|
||||
assertEquals((double)0, exec("def d = Float.valueOf(0); double b = d; b"));
|
||||
assertEquals((double)0, exec("def d = Double.valueOf(0); double b = d; b"));
|
||||
assertEquals((double)0, exec("def d = BigInteger.valueOf(0); double b = d; b"));
|
||||
expectScriptThrows(ClassCastException.class, () -> exec("def d = new ArrayList(); double b = d;"));
|
||||
}
|
||||
|
||||
|
|
|
@ -8,44 +8,17 @@ package org.elasticsearch.xpack.unsignedlong;
|
|||
|
||||
import org.elasticsearch.painless.spi.PainlessExtension;
|
||||
import org.elasticsearch.painless.spi.Whitelist;
|
||||
import org.elasticsearch.painless.spi.WhitelistLoader;
|
||||
import org.elasticsearch.script.AggregationScript;
|
||||
import org.elasticsearch.script.BucketAggregationSelectorScript;
|
||||
import org.elasticsearch.script.FieldScript;
|
||||
import org.elasticsearch.script.FilterScript;
|
||||
import org.elasticsearch.script.NumberSortScript;
|
||||
import org.elasticsearch.script.ScoreScript;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.StringSortScript;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
public class DocValuesWhitelistExtension implements PainlessExtension {
|
||||
|
||||
private static final Whitelist WHITELIST = WhitelistLoader.loadFromResourceFiles(DocValuesWhitelistExtension.class, "whitelist.txt");
|
||||
|
||||
@Override
|
||||
public Map<ScriptContext<?>, List<Whitelist>> getContextWhitelists() {
|
||||
List<Whitelist> whitelist = singletonList(WHITELIST);
|
||||
Map<ScriptContext<?>, List<Whitelist>> contexts = org.elasticsearch.common.collect.Map.of(
|
||||
FieldScript.CONTEXT,
|
||||
whitelist,
|
||||
ScoreScript.CONTEXT,
|
||||
whitelist,
|
||||
FilterScript.CONTEXT,
|
||||
whitelist,
|
||||
AggregationScript.CONTEXT,
|
||||
whitelist,
|
||||
NumberSortScript.CONTEXT,
|
||||
whitelist,
|
||||
StringSortScript.CONTEXT,
|
||||
whitelist,
|
||||
BucketAggregationSelectorScript.CONTEXT,
|
||||
whitelist
|
||||
);
|
||||
return contexts;
|
||||
// TODO: support unsigned_long in scripts
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,8 @@ public class UnsignedLongLeafFieldData implements LeafNumericFieldData {
|
|||
|
||||
@Override
|
||||
public ScriptDocValues<?> getScriptValues() {
|
||||
return new UnsignedLongScriptDocValues(getLongValues());
|
||||
// TODO: add support for scripts
|
||||
throw new UnsupportedOperationException("Using unsigned_long in scripts is currently not supported!");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
setup:
|
||||
|
||||
- skip:
|
||||
version: " - 7.9.99"
|
||||
reason: "unsigned_long was added in 7.10"
|
||||
version: "all"
|
||||
reason: "AwaitsFix https://github.com/elastic/elasticsearch/issues/64361"
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
|
|
Loading…
Reference in New Issue