-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Support unsigned long field type in painless #64361
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
Comments
Pinging @elastic/es-core-infra (:Core/Infra/Scripting) |
There are two major issues with unsigned long fields in scripting as it stands.
|
It depends what precision a user expects. Conversion to double leads to loss of precision on last digits. For aggregations it doesn't much matter, as they already work on doubles, but for something like
I would suggest before this is ready, to leave things as they are and just to add a warning in the documentation for WDYT? |
@mayya-sharipova I took a look at #64422 and the documentation is good. My two main concerns noted above remain, however. Here's what I would propose instead:
Now a script looks like (I know this is how you've written the docs 👍)
Now a script looks like
These changes allow for strong consistency in how unsigned long fields are accessed and remove any potential casting inconsistencies. |
I have a different proposal, not better or worse, just another alternative. Unsigned longs fit into a normal |
@rjernst proposal will have the best performance. |
Current problems with unsigned_long in scripts:
Solution options:
|
We had a team discussion and decided we would like to return ScriptDocValues for unsigned_long always return the same type. This type could be:
Since we have not made yet a final decision how to handle unsigned_long in scripts, we have decided to disable using unsigned_long in scripts in 7.10. |
Backport for elastic#64523 Relates to elastic#64361
Backport for elastic#64523 Relates to elastic#64361
I have an idea of a slightly different proposal:
I can see several pluses for this proposal:
One minus for this proposal:
@jimczi @rjernst @jdconrad @stu-elastic What do you think of this proposal? |
I wanted to briefly ask if we possibly see this added in 7.12, for scheduling the SQL support for it. Cheers! |
Leaking the internal representation will be a really sharp edge for users. We'll block this work pending the universal api work's |
Just to add besides type coercions, we've made a decision that:
And as @stu-elastic said the exposure of unsigned_long in scripts will be postponed until we are ready for field centric API in scripts |
I don't know if this would help to address this problem, but I might be tempted to add a new class UnsignedLong and hide all the representation details of two's complement etc... that would be fast and it wouldn't violate encapsulation. Btw, java.lang.Long does provide divideUnsigned(long, long). |
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 ``` Fixes: elastic#64361
The casting model needs to be overhauled to support the
unsigned long
field type, added in 60050, as this type can return aBigInteger
.Type promotion in the casting model works well for primitive types, String and
def
.The
def
type is tricky to handle with boxed types and type promotion, the current model has limited support for boxed types.As this is a major rework on a subtle subsystem, we should look toward interim support for unsigned long.
@jimczi @mayya-sharipova what do you think about having
unsigned long
field returndouble
s forScriptDocValues
?Relates: #64347
The text was updated successfully, but these errors were encountered: