Skip to content

Commit aea8bff

Browse files
authored
Script: ulong via fields API (#76519)
* Script: ulong via fields API Exposes unsigned long via the fields API. Unsigned longs default to java signed longs. That means the upper range appears negative. Consumers should use `Long.compareUnsigned(long, long)` `Long.divideUnsigned(long, long)` and `Long.remainderUnsigned(long, long)` to correctly work with values known to be unsigned long. Alternatively, users may treat the unsigned long type as `BigInteger` using the field API, `field('ul').as(Field.BigInteger).getValue(BigInteger.ZERO)`. ``` field('ul').as(Field.BigInteger).getValue(BigInteger.valueOf(1000)) field('ul').getValue(1000L) ``` This change also implements the beginning of the converters for the fields API. The following conversions have been added: ``` ulong <-> BigInteger long <-> BigInteger double -> BigInteger String (parsed as long or double) -> BigInteger double -> long String (parsed as long or double) -> long Date (epoch milliseconds) -> long Nano Date (epoch nanoseconds) -> long boolean (1L for true, 0L for false) -> long ```
1 parent 0428970 commit aea8bff

File tree

23 files changed

+1512
-104
lines changed

23 files changed

+1512
-104
lines changed

modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.fields.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@
1010

1111
# API
1212
class org.elasticsearch.script.Field {
13+
org.elasticsearch.script.Converter BigInteger
14+
org.elasticsearch.script.Converter Long
1315
String getName()
1416
boolean isEmpty()
1517
List getValues()
1618
def getValue(def)
19+
double getDouble(double)
20+
long getLong(long)
21+
org.elasticsearch.script.Field as(org.elasticsearch.script.Converter)
22+
}
23+
24+
class org.elasticsearch.script.Converter {
1725
}
1826

1927
class org.elasticsearch.script.DocBasedScript {

0 commit comments

Comments
 (0)