-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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: fill in get contexts REST API #48319
Scripting: fill in get contexts REST API #48319
Conversation
Updates response for `GET /_script_context`, returning a `contexts` object with a list of context description objects. The description includes the context name and a list of methods available. The methods list has the signature for the `execute` mathod and any getters. eg. ``` { "contexts": [ { "name" : "moving-function", "methods" : [ { "name" : "execute", "return_type" : "double", "params" : [ { "type" : "java.util.Map", "name" : "params" }, { "type" : "double[]", "name" : "values" } ] } ] }, { "name" : "number_sort", "methods" : [ { "name" : "execute", "return_type" : "double", "params" : [ ] }, { "name" : "getDoc", "return_type" : "java.util.Map", "params" : [ ] }, { "name" : "getParams", "return_type" : "java.util.Map", "params" : [ ] }, { "name" : "get_score", "return_type" : "double", "params" : [ ] } ] }, ... ] } ``` fixes: elastic#47411
Pinging @elastic/es-core-infra (:Core/Infra/Scripting) |
…e/47411-painless-script-context-rest_2_exec_getters_merge
…different contexts
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.
@stu-elastic Thank you for the work here. This looks good to me, and I don't have any other comments as we've been chatting throughout. I'm very pleased with the changes to the structure of the response.
...a/org/elasticsearch/action/admin/cluster/storedscripts/ScriptMethodInfoSerializingTests.java
Show resolved
Hide resolved
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.
Thanks for getting this up so quickly, and especially for the extensive serialization tests. I have a few comments.
- match: { contexts.number_sort: {} } | ||
- match: { contexts.processor_conditional: {} } | ||
- match: { contexts.score: {} } | ||
- match: { contexts.script_heuristic: {} } |
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.
We seem to have lost a lot of builtin contexts here?
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.
Unfortunately the change to list made performing the comparison after this differ in different contexts. This will be addressed when I address your next comment.
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.
I've cut this test down to make it more reliable, now just checking that at least one context exists, it has a execute method with return value field.
- match: { contexts.0.name: "aggregation_selector" } | ||
- match: { contexts.0.methods: [{"name": "execute", "return_type": "boolean", "params": []}, {"name": "getParams", "return_type": "java.util.Map", "params": []}] } | ||
|
||
- match: { contexts.1.name: "aggs" } |
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.
Why is this structure changed to a list of objects? The order of these do not matter, so I don't think it should be a list.
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.
Agreed, I was going with ease of using our existing parsing primitives, which have a difficulty addressing dynamic keys. Will take a pass at making it a map and we'll see how ugly it gets.
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.
It got pretty ugly. Per offline conversation, we're gonna keep this structure for now.
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.
It got pretty ugly doing the fragment parsing and made testing difficult. Per offline conversation, we're gonna keep this structure for now.
...main/java/org/elasticsearch/action/admin/cluster/storedscripts/GetScriptContextResponse.java
Outdated
Show resolved
Hide resolved
...main/java/org/elasticsearch/action/admin/cluster/storedscripts/GetScriptContextResponse.java
Outdated
Show resolved
Hide resolved
...main/java/org/elasticsearch/action/admin/cluster/storedscripts/GetScriptContextResponse.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/script/ScriptContextInfo.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/script/ScriptContextInfo.java
Outdated
Show resolved
Hide resolved
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
||
public class ScriptContextInfo implements ToXContentObject, Writeable { |
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.
I still think the naming is quite confusing here, but I can live with it for now since this is an internal api and thus these can be changed without backcompat.
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.
Happy to change when we can think of a better name.
The reason I chose this name is ScriptContextInfo
is this is a description of a ScriptContext
and appending Info
is the naming convention we have, see PainlessContextInfo
.
...a/org/elasticsearch/action/admin/cluster/storedscripts/ScriptMethodInfoSerializingTests.java
Outdated
Show resolved
Hide resolved
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.
LGTM
* Scripting: fill in get contexts REST API Updates response for `GET /_script_context`, returning a `contexts` object with a list of context description objects. The description includes the context name and a list of methods available. The methods list has the signature for the `execute` mathod and any getters. eg. ``` { "contexts": [ { "name" : "moving-function", "methods" : [ { "name" : "execute", "return_type" : "double", "params" : [ { "type" : "java.util.Map", "name" : "params" }, { "type" : "double[]", "name" : "values" } ] } ] }, { "name" : "number_sort", "methods" : [ { "name" : "execute", "return_type" : "double", "params" : [ ] }, { "name" : "getDoc", "return_type" : "java.util.Map", "params" : [ ] }, { "name" : "getParams", "return_type" : "java.util.Map", "params" : [ ] }, { "name" : "get_score", "return_type" : "double", "params" : [ ] } ] }, ... ] } ``` fixes: elastic#47411
Updates response for `GET /_script_context`, returning a `contexts` object with a list of context description objects. The description includes the context name and a list of methods available. The methods list has the signature for the `execute` mathod and any getters. eg. ``` { "contexts": [ { "name" : "moving-function", "methods" : [ { "name" : "execute", "return_type" : "double", "params" : [ { "type" : "java.util.Map", "name" : "params" }, { "type" : "double[]", "name" : "values" } ] } ] }, { "name" : "number_sort", "methods" : [ { "name" : "execute", "return_type" : "double", "params" : [ ] }, { "name" : "getDoc", "return_type" : "java.util.Map", "params" : [ ] }, { "name" : "getParams", "return_type" : "java.util.Map", "params" : [ ] }, { "name" : "get_score", "return_type" : "double", "params" : [ ] } ] }, ... ] } ``` fixes: #47411
Updates response for
GET /_script_context
, returning acontexts
object with a list of context description objects. The description
includes the context name and a list of methods available. The
methods list has the signature for the
execute
mathod and anygetters. eg.
fixes: #47411