Skip to content
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

Painless user methods as instance methods #69742

Closed
stu-elastic opened this issue Mar 1, 2021 · 2 comments · Fixed by #74268
Closed

Painless user methods as instance methods #69742

stu-elastic opened this issue Mar 1, 2021 · 2 comments · Fixed by #74268
Assignees
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >enhancement Team:Core/Infra Meta label for core/infra team

Comments

@stu-elastic
Copy link
Contributor

stu-elastic commented Mar 1, 2021

Arguments to execute and proxied variables (x is exposed when a script defines getX and/or setX) are not available in user functions. This adds ceremony when creating user functions, as they must be passed in.

Exposing these as globals simplifies the implementation of the universal fields API (#61388) as well as reducing ceremony.

We will allow existing arguments to user functions with the same name to shadow the globals. This avoids breaking existing scripts and incurring backwards compatibility costs.

As a follow up, we will deprecate shadowing as it's inconsistent with the painless variable model.

Instead of global variables, we'll make user defined methods into instance methods, which is a simplier implementation and still helps with the universal fields API (#61388)

@stu-elastic stu-elastic added >enhancement :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache labels Mar 1, 2021
@stu-elastic stu-elastic self-assigned this Mar 1, 2021
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Mar 1, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@princejha95
Copy link

Hi @stu-elastic

I am very much interested to pick up this issue. Since i am new to Elastic Search community, can you please give me a brief info about this issue like which all classes do i need to take a look at in order to provide resolution for this issue ?

Any help would be appreciated.

stu-elastic added a commit to stu-elastic/elasticsearch that referenced this issue Apr 27, 2021
Adds `GlobalMember` decoration to the User Tree for
variables which have name conflicts with global variables.

Parameter `isLocalMember` specifies if the variable
shadows the global name.

Refs: elastic#69742
stu-elastic added a commit to stu-elastic/elasticsearch that referenced this issue May 10, 2021
Prepend `&` to user function names.  In future changes user
functions will switch from being static methods to member methods.
The mangled user function names will prohibit users from overriden
other script methods.

Refs: elastic#69742
stu-elastic added a commit that referenced this issue May 10, 2021
Prepend `&` to user function names.  In future changes user
functions will switch from being static methods to member methods.
The mangled user function names will prohibit users from overriden
other script methods.

Refs: #69742
stu-elastic added a commit to stu-elastic/elasticsearch that referenced this issue May 10, 2021
Prepend `&` to user function names.  In future changes user
functions will switch from being static methods to member methods.
The mangled user function names will prohibit users from overriden
other script methods.

Refs: elastic#69742
Backport: f6bf99c
@stu-elastic stu-elastic changed the title Painless global variables Painless ~global variables~ user methods as instance methods Jun 17, 2021
@stu-elastic stu-elastic changed the title Painless ~global variables~ user methods as instance methods Painless user methods as instance methods Jun 17, 2021
stu-elastic added a commit to stu-elastic/elasticsearch that referenced this issue Jun 17, 2021
User defined functions are instance methods on the Script class.

Update lambdas and method references to capture the script `this`
reference.

Def method encoding string takes an extra char at index 1, whether
to capture the script reference.

For runtime fields, this means emit, which is an script instance
method already, now works in user defined functions.

Fixes: elastic#69742
Refs: elastic#68235
stu-elastic added a commit that referenced this issue Jul 1, 2021
User defined functions are instance methods on the Script class.

Update lambdas and method references to capture the script `this`
reference.

Def method encoding string takes an extra char at index 1, whether
to capture the script reference.

For runtime fields, this means emit, which is an script instance
method already, now works in user defined functions.

Fixes: #69742
Refs: #68235
stu-elastic added a commit to stu-elastic/elasticsearch that referenced this issue Jul 1, 2021
User defined functions are instance methods on the Script class.

Update lambdas and method references to capture the script `this`
reference.

Def method encoding string takes an extra char at index 1, whether
to capture the script reference.

For runtime fields, this means emit, which is an script instance
method already, now works in user defined functions.

Fixes: elastic#69742
Refs: elastic#68235
Backport: e26fa4e
stu-elastic added a commit that referenced this issue Jul 1, 2021
Prepend `&` to user function names.  In future changes user
functions will switch from being static methods to member methods.
The mangled user function names will prohibit users from overriden
other script methods.

Refs: #69742
Backport: f6bf99c
stu-elastic added a commit to stu-elastic/elasticsearch that referenced this issue Jul 1, 2021
User defined functions are instance methods on the Script class.

Update lambdas and method references to capture the script `this`
reference.

Def method encoding string takes an extra char at index 1, whether
to capture the script reference.

For runtime fields, this means emit, which is an script instance
method already, now works in user defined functions.

Fixes: elastic#69742
Refs: elastic#68235
Backport: e26fa4e
stu-elastic added a commit that referenced this issue Jul 1, 2021
User defined functions are instance methods on the Script class.

Update lambdas and method references to capture the script `this`
reference.

Def method encoding string takes an extra char at index 1, whether
to capture the script reference.

For runtime fields, this means emit, which is an script instance
method already, now works in user defined functions.

Fixes: #69742
Refs: #68235
Backport: e26fa4e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >enhancement Team:Core/Infra Meta label for core/infra team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants