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]
|
//TEST[continued]
|
||||||
|
|
||||||
Similarly to sort values, script values of an `unsigned_long` field
|
|
||||||
return a `Number` representing a `Long` or `BigInteger`.
|
==== Unsigned long in scripts
|
||||||
The same values: `Long` or `BigInteger` are used for `terms` aggregations.
|
Currently unsigned_long is not supported in scripts.
|
||||||
|
|
||||||
==== Stored fields
|
==== Stored fields
|
||||||
A stored field of `unsigned_long` is stored and returned as `String`.
|
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
|
==== Queries with mixed numeric types
|
||||||
|
|
||||||
Searches with mixed numeric types one of which is `unsigned_long` are
|
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.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.MethodType;
|
import java.lang.invoke.MethodType;
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -761,8 +760,6 @@ public final class Def {
|
||||||
return (float)value;
|
return (float)value;
|
||||||
} else if (value instanceof Double) {
|
} else if (value instanceof Double) {
|
||||||
return (double)value;
|
return (double)value;
|
||||||
} else if (value instanceof BigInteger) {
|
|
||||||
return ((BigInteger)value).doubleValue();
|
|
||||||
} else {
|
} else {
|
||||||
throw new ClassCastException("cannot implicitly cast " +
|
throw new ClassCastException("cannot implicitly cast " +
|
||||||
"def [" + PainlessLookupUtility.typeToUnboxedType(value.getClass()).getCanonicalName() + "] to " +
|
"def [" + PainlessLookupUtility.typeToUnboxedType(value.getClass()).getCanonicalName() + "] to " +
|
||||||
|
@ -895,8 +892,7 @@ public final class Def {
|
||||||
value instanceof Integer ||
|
value instanceof Integer ||
|
||||||
value instanceof Long ||
|
value instanceof Long ||
|
||||||
value instanceof Float ||
|
value instanceof Float ||
|
||||||
value instanceof Double ||
|
value instanceof Double
|
||||||
value instanceof BigInteger
|
|
||||||
) {
|
) {
|
||||||
return ((Number)value).doubleValue();
|
return ((Number)value).doubleValue();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1035,8 +1031,6 @@ public final class Def {
|
||||||
return (double)(float)value;
|
return (double)(float)value;
|
||||||
} else if (value instanceof Double) {
|
} else if (value instanceof Double) {
|
||||||
return (Double) value;
|
return (Double) value;
|
||||||
} else if (value instanceof BigInteger) {
|
|
||||||
return ((BigInteger)value).doubleValue();
|
|
||||||
} else {
|
} else {
|
||||||
throw new ClassCastException("cannot implicitly cast " +
|
throw new ClassCastException("cannot implicitly cast " +
|
||||||
"def [" + PainlessLookupUtility.typeToUnboxedType(value.getClass()).getCanonicalName() + "] to " +
|
"def [" + PainlessLookupUtility.typeToUnboxedType(value.getClass()).getCanonicalName() + "] to " +
|
||||||
|
@ -1183,8 +1177,7 @@ public final class Def {
|
||||||
value instanceof Integer ||
|
value instanceof Integer ||
|
||||||
value instanceof Long ||
|
value instanceof Long ||
|
||||||
value instanceof Float ||
|
value instanceof Float ||
|
||||||
value instanceof Double ||
|
value instanceof Double
|
||||||
value instanceof BigInteger
|
|
||||||
) {
|
) {
|
||||||
return ((Number)value).doubleValue();
|
return ((Number)value).doubleValue();
|
||||||
} else {
|
} 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 = 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 = 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 = 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;"));
|
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.PainlessExtension;
|
||||||
import org.elasticsearch.painless.spi.Whitelist;
|
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.ScriptContext;
|
||||||
import org.elasticsearch.script.StringSortScript;
|
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
|
||||||
|
|
||||||
public class DocValuesWhitelistExtension implements PainlessExtension {
|
public class DocValuesWhitelistExtension implements PainlessExtension {
|
||||||
|
|
||||||
private static final Whitelist WHITELIST = WhitelistLoader.loadFromResourceFiles(DocValuesWhitelistExtension.class, "whitelist.txt");
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<ScriptContext<?>, List<Whitelist>> getContextWhitelists() {
|
public Map<ScriptContext<?>, List<Whitelist>> getContextWhitelists() {
|
||||||
List<Whitelist> whitelist = singletonList(WHITELIST);
|
// TODO: support unsigned_long in scripts
|
||||||
Map<ScriptContext<?>, List<Whitelist>> contexts = org.elasticsearch.common.collect.Map.of(
|
return Collections.emptyMap();
|
||||||
FieldScript.CONTEXT,
|
|
||||||
whitelist,
|
|
||||||
ScoreScript.CONTEXT,
|
|
||||||
whitelist,
|
|
||||||
FilterScript.CONTEXT,
|
|
||||||
whitelist,
|
|
||||||
AggregationScript.CONTEXT,
|
|
||||||
whitelist,
|
|
||||||
NumberSortScript.CONTEXT,
|
|
||||||
whitelist,
|
|
||||||
StringSortScript.CONTEXT,
|
|
||||||
whitelist,
|
|
||||||
BucketAggregationSelectorScript.CONTEXT,
|
|
||||||
whitelist
|
|
||||||
);
|
|
||||||
return contexts;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,8 @@ public class UnsignedLongLeafFieldData implements LeafNumericFieldData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScriptDocValues<?> getScriptValues() {
|
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
|
@Override
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
setup:
|
setup:
|
||||||
|
|
||||||
- skip:
|
- skip:
|
||||||
version: " - 7.9.99"
|
version: "all"
|
||||||
reason: "unsigned_long was added in 7.10"
|
reason: "AwaitsFix https://github.com/elastic/elasticsearch/issues/64361"
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
indices.create:
|
indices.create:
|
||||||
|
|
Loading…
Reference in New Issue