Skip to content

Expose constant fields used by script #60001

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

Closed
stu-elastic opened this issue Jul 21, 2020 · 5 comments
Closed

Expose constant fields used by script #60001

stu-elastic opened this issue Jul 21, 2020 · 5 comments
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 Jul 21, 2020

This will allows runtime fields to validate that scripts only use fields available and facilitate cycle detection.

  • One advanced feature here is users only see doc as part of the "main" method in Painless. If doc is passed into a user-defined function this must be tracked and the parameter in the function must also add constant fields used as part of doc.

  • Handle doc aliasing (def foo = doc).

Related: #59332

@stu-elastic stu-elastic added >enhancement :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache labels Jul 21, 2020
@elasticmachine
Copy link
Collaborator

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

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Jul 21, 2020
stu-elastic added a commit to stu-elastic/elasticsearch that referenced this issue Jul 23, 2020
* Add DocFieldsPhase visitor during compilation
* Fields are accessible via ScriptScope.docFields()

Doc field accesses that are expressions, even constant expressions are not
handled.

Refs: elastic#60001
jdconrad pushed a commit that referenced this issue Jul 27, 2020
* Add DocFieldsPhase visitor during compilation
* Fields are accessible via ScriptScope.docFields()

Doc field accesses that are expressions, even constant expressions are not handled.

Refs: #60001
@jdconrad
Copy link
Contributor

Some notes based on @stu-elastic first PR: this covers simple doc usage in the main method only. This needs to be extended to track doc into user-defined methods. However, one very important note is we still need to check for cycles at runtime unless we prevent doc from assignment and restrict it to only methods we know are not using assignment. Otherwise, we can lose track if the user decides to assign doc to a data structure such as a List or Map. We must also only allow doc to be referenced by String constants.

@stu-elastic
Copy link
Contributor Author

stu-elastic commented Aug 5, 2020

Next tasks:

  • Remove ability to assign doc to anything, we lose track of doc access if so
  • Allow "read only" variables to be used as doc accessors, String a = "foo"; return doc[a];" should still work as long as a` is never updated.

Pending optional compiler phases: #60156, #59647

@rjernst rjernst added the needs:triage Requires assignment of a team area label label Dec 3, 2020
@stu-elastic
Copy link
Contributor Author

@javanna is there anything runtime fields needs here beyond #60158?

@stu-elastic stu-elastic removed the needs:triage Requires assignment of a team area label label Dec 9, 2020
@javanna
Copy link
Member

javanna commented Dec 10, 2020

@stu-elastic we should be good for now, thanks!

@javanna javanna closed this as completed Dec 10, 2020
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

No branches or pull requests

5 participants