Skip to content

Commit 0ffbcd3

Browse files
Disable using unsigned_long in scripts (#64523)
Relates to #64361
1 parent 887c98e commit 0ffbcd3

File tree

6 files changed

+17
-46
lines changed

6 files changed

+17
-46
lines changed

docs/reference/mapping/types/unsigned_long.asciidoc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,18 @@ GET /my_index/_search
102102
--------------------------------
103103
//TEST[continued]
104104

105-
Similarly to sort values, script values of an `unsigned_long` field
106-
return a `Number` representing a `Long` or `BigInteger`.
107-
The same values: `Long` or `BigInteger` are used for `terms` aggregations.
105+
106+
==== Unsigned long in scripts
107+
Currently unsigned_long is not supported in scripts.
108108

109109
==== Stored fields
110110
A stored field of `unsigned_long` is stored and returned as `String`.
111111

112+
==== Aggregations
113+
For `terms` aggregations, similarly to sort values, `Long` or
114+
`BigInteger` values are used. For other aggregations,
115+
values are converted to the `double` type.
116+
112117
==== Queries with mixed numeric types
113118

114119
Searches with mixed numeric types one of which is `unsigned_long` are

modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.lang.invoke.MethodHandle;
3030
import java.lang.invoke.MethodHandles;
3131
import java.lang.invoke.MethodType;
32-
import java.math.BigInteger;
3332
import java.time.ZonedDateTime;
3433
import java.util.BitSet;
3534
import java.util.Collections;
@@ -761,8 +760,6 @@ public static double defTodoubleImplicit(final Object value) {
761760
return (float)value;
762761
} else if (value instanceof Double) {
763762
return (double)value;
764-
} else if (value instanceof BigInteger) {
765-
return ((BigInteger)value).doubleValue();
766763
} else {
767764
throw new ClassCastException("cannot implicitly cast " +
768765
"def [" + PainlessLookupUtility.typeToUnboxedType(value.getClass()).getCanonicalName() + "] to " +
@@ -895,8 +892,7 @@ public static double defTodoubleExplicit(final Object value) {
895892
value instanceof Integer ||
896893
value instanceof Long ||
897894
value instanceof Float ||
898-
value instanceof Double ||
899-
value instanceof BigInteger
895+
value instanceof Double
900896
) {
901897
return ((Number)value).doubleValue();
902898
} else {
@@ -1035,8 +1031,6 @@ public static Double defToDoubleImplicit(final Object value) {
10351031
return (double)(float)value;
10361032
} else if (value instanceof Double) {
10371033
return (Double) value;
1038-
} else if (value instanceof BigInteger) {
1039-
return ((BigInteger)value).doubleValue();
10401034
} else {
10411035
throw new ClassCastException("cannot implicitly cast " +
10421036
"def [" + PainlessLookupUtility.typeToUnboxedType(value.getClass()).getCanonicalName() + "] to " +
@@ -1183,8 +1177,7 @@ public static Double defToDoubleExplicit(final Object value) {
11831177
value instanceof Integer ||
11841178
value instanceof Long ||
11851179
value instanceof Float ||
1186-
value instanceof Double ||
1187-
value instanceof BigInteger
1180+
value instanceof Double
11881181
) {
11891182
return ((Number)value).doubleValue();
11901183
} else {

modules/lang-painless/src/test/java/org/elasticsearch/painless/DefCastTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ public void testdefTodoubleImplicit() {
166166
assertEquals((double)0, exec("def d = Long.valueOf(0); double b = d; b"));
167167
assertEquals((double)0, exec("def d = Float.valueOf(0); double b = d; b"));
168168
assertEquals((double)0, exec("def d = Double.valueOf(0); double b = d; b"));
169-
assertEquals((double)0, exec("def d = BigInteger.valueOf(0); double b = d; b"));
170169
expectScriptThrows(ClassCastException.class, () -> exec("def d = new ArrayList(); double b = d;"));
171170
}
172171

x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/DocValuesWhitelistExtension.java

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,17 @@
88

99
import org.elasticsearch.painless.spi.PainlessExtension;
1010
import org.elasticsearch.painless.spi.Whitelist;
11-
import org.elasticsearch.painless.spi.WhitelistLoader;
12-
import org.elasticsearch.script.AggregationScript;
13-
import org.elasticsearch.script.BucketAggregationSelectorScript;
14-
import org.elasticsearch.script.FieldScript;
15-
import org.elasticsearch.script.FilterScript;
16-
import org.elasticsearch.script.NumberSortScript;
17-
import org.elasticsearch.script.ScoreScript;
1811
import org.elasticsearch.script.ScriptContext;
19-
import org.elasticsearch.script.StringSortScript;
2012

13+
import java.util.Collections;
2114
import java.util.List;
2215
import java.util.Map;
2316

24-
import static java.util.Collections.singletonList;
25-
2617
public class DocValuesWhitelistExtension implements PainlessExtension {
2718

28-
private static final Whitelist WHITELIST = WhitelistLoader.loadFromResourceFiles(DocValuesWhitelistExtension.class, "whitelist.txt");
29-
3019
@Override
3120
public Map<ScriptContext<?>, List<Whitelist>> getContextWhitelists() {
32-
List<Whitelist> whitelist = singletonList(WHITELIST);
33-
Map<ScriptContext<?>, List<Whitelist>> contexts = Map.of(
34-
FieldScript.CONTEXT,
35-
whitelist,
36-
ScoreScript.CONTEXT,
37-
whitelist,
38-
FilterScript.CONTEXT,
39-
whitelist,
40-
AggregationScript.CONTEXT,
41-
whitelist,
42-
NumberSortScript.CONTEXT,
43-
whitelist,
44-
StringSortScript.CONTEXT,
45-
whitelist,
46-
BucketAggregationSelectorScript.CONTEXT,
47-
whitelist
48-
);
49-
return contexts;
21+
// TODO: support unsigned_long in scripts
22+
return Collections.emptyMap();
5023
}
5124
}

x-pack/plugin/mapper-unsigned-long/src/main/java/org/elasticsearch/xpack/unsignedlong/UnsignedLongLeafFieldData.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public int docValueCount() {
7373

7474
@Override
7575
public ScriptDocValues<?> getScriptValues() {
76-
return new UnsignedLongScriptDocValues(getLongValues());
76+
// TODO: add support for scripts
77+
throw new UnsupportedOperationException("Using unsigned_long in scripts is currently not supported!");
7778
}
7879

7980
@Override

x-pack/plugin/src/test/resources/rest-api-spec/test/unsigned_long/50_script_values.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
setup:
22

33
- skip:
4-
version: " - 7.9.99"
5-
reason: "unsigned_long was added in 7.10"
4+
version: "all"
5+
reason: "AwaitsFix https://github.com/elastic/elasticsearch/issues/64361"
66

77
- do:
88
indices.create:

0 commit comments

Comments
 (0)