Skip to content

Commit

Permalink
Script: ulong via fields API (#76519) (#76613)
Browse files Browse the repository at this point in the history
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
```

Backport: aea8bff
  • Loading branch information
stu-elastic committed Aug 17, 2021
1 parent 39acaf1 commit 5491d94
Show file tree
Hide file tree
Showing 23 changed files with 1,516 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@

# API
class org.elasticsearch.script.Field {
org.elasticsearch.script.Converter BigInteger
org.elasticsearch.script.Converter Long
String getName()
boolean isEmpty()
List getValues()
def getValue(def)
double getDouble(double)
long getLong(long)
org.elasticsearch.script.Field as(org.elasticsearch.script.Converter)
}

class org.elasticsearch.script.Converter {
}

class org.elasticsearch.script.DocBasedScript {
Expand Down
Loading

0 comments on commit 5491d94

Please sign in to comment.