-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Scripting: Converters can adapt return values #60937
Scripting: Converters can adapt return values #60937
Conversation
…ing/59647-1-casting-model
…ing/59647-1-casting-model
Add ability to explicitly coerce the return value from a script. Runtime fields want to avoid returning `Object` from the execute method in each context. Instead, they will return an array of primitive objects, such as `long[]`. However, it's convenient to allow a user to return a single primitive type rather than allocating a length-one array. To achieve this, an implementer can add explicit conversion functions to a context with signature: `public static <context-return-value> convertFrom<Suffix>(<any type>)` When a user returns a type other than the context return value, at compile-time, painless will insert a call to their `convertFrom` method. This commit is Phase 1 of this work. It handles explicit converters for all painless types EXCEPT def type. Refs: elastic#59647
Pinging @elastic/es-core-infra (:Core/Infra/Scripting) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solid first step! Just as a note, when we address primitives I think it's better to do this as a standard cast from the type to the parameter of the conversion method and then a second step where the method is actually called.
Add ability to explicitly coerce the return value from a script.
Runtime fields wants to avoid returning
Object
from the execute methodin each context. Instead, they will return an array of primitives, such as
long[]
.However, it's convenient to allow a user to return a single primitive
type rather than allocating a length-one array.
To achieve this, an implementer can add explicit conversion functions to
a context with the signature:
public static <context-return-value> convertFrom<Suffix>(<any type>)
When a user returns a type other than the context return value, at
compile-time, painless will insert a call to their
convertFrom
method.This commit is Phase 1 of this work. It handles explicit converters for
all painless types EXCEPT def type.
Refs: #59647