Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable using unsigned_long in scripts #64523

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/reference/mapping/types/unsigned_long.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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;
Expand Down Expand Up @@ -761,8 +760,6 @@ public static double defTodoubleImplicit(final Object value) {
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 " +
Expand Down Expand Up @@ -895,8 +892,7 @@ public static double defTodoubleExplicit(final Object value) {
value instanceof Integer ||
value instanceof Long ||
value instanceof Float ||
value instanceof Double ||
value instanceof BigInteger
value instanceof Double
) {
return ((Number)value).doubleValue();
} else {
Expand Down Expand Up @@ -1035,8 +1031,6 @@ public static Double defToDoubleImplicit(final Object value) {
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 " +
Expand Down Expand Up @@ -1183,8 +1177,7 @@ public static Double defToDoubleExplicit(final Object value) {
value instanceof Integer ||
value instanceof Long ||
value instanceof Float ||
value instanceof Double ||
value instanceof BigInteger
value instanceof Double
) {
return ((Number)value).doubleValue();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public void testdefTodoubleImplicit() {
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;"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,17 @@

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 = 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public int docValueCount() {

@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
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down