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

Scripting: Replace advanced and native scripts with ScriptEngine docs #24603

Merged
merged 5 commits into from May 11, 2017

Conversation

rjernst
Copy link
Member

@rjernst rjernst commented May 10, 2017

This commit documents how to write a ScriptEngine in order to use
expert internal apis, such as using Lucene directly to find index term
statistics. These documents prepare the way to remove both native
scripts and IndexLookup.

The example java code is actually compiled and tested under a new gradle
subproject for example plugins. This change does not yet breakup
jvm-example into the new examples dir, which should be done separately.

relates #19359
relates #19966

This commit documents how to write a `ScriptEngine` in order to use
expert internal apis, such as using Lucene directly to find index term
statistics. These documents prepare the way to remove both native
scripts and IndexLookup.

The example java code is actually compiled and tested under a new gradle
subproject for example plugins. This change does not yet breakup
jvm-example into the new examples dir, which should be done separately.

relates elastic#19359
relates elastic#19966
@rjernst rjernst added :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >docs General docs changes v5.5.0 v6.0.0 labels May 10, 2017
@rjernst rjernst requested review from nik9000 and imotov May 10, 2017 23:03
@@ -38,7 +38,9 @@
/**
* The extension for file scripts in this language.
*/
String getExtension();
default String getExtension() {
return getType();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -76,6 +76,15 @@ List projects = [
'qa:wildfly'
]

File examplePluginsDir = new File(rootProject.projectDir, 'plugins/examples')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just declare them like all the other plugins? This doesn't seem like it is better than having the plugin in :plugins:examples:advanced-scoring.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it is different from every other project because the path doesn't match the name, which I'd prefer not to do just to keep things consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this for two reasons:

  1. Otherwise all the places that list plugins (eg smoke-test-plugins) via the gradle project :plugins must add a bunch of logic we must copy every time we want to get all the plugins.
  2. I have come around to hating having to list every plugin/module, as it is both cumbersome to change, as well as error prone because moving/creating a new module results in a cryptic error message from gradle until it is added (thinking that the project is standalone instead of our multi project build).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are both fine points. Is there any way to accomplish them without using the funny project name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the first point, no. It works without having to affect anything iterating the plugins precisely because it is not a subproject of :plugins.

Honestly, I don't see it as that big of a deal. This is what settings.gradle is for, to control how the multi project build is laid out. There is nothing that says project's directories must match their directory layout. The only reason I didn't add a top level example-plugins directory is I think the root directory already has far too many things in it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just make a directory called example-plugins instead of keeping it in the plugins directory? I like that the names all line up. Exception for buildSrc, but buildSrc is known special and weird.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said, i think the root project is already too crowded. I don't want to add more directories there, I want to remove them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I spaced out and didn't read the second half of your paragraph. I should probably sleep soon!

I really want the names to line up if I can have it. If i can't fine.

What about putting it as a subdirectory of docs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having it as a subdirectory of docs will be confusing, because this is compilable and testable code, not ascii docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really want the names to line up if I can have it.

The names already don't line up, see for example the core hack we have around the same spot in settings.gradle. I really dont' see why the directory name matching the project name matters. These aren't things we ever have to deal with, other than in gradle, and gradle doesn't care what the names are, only that there is a dir associated with each project. cding into the plugins/examples dir still allows running tests as normal.

@Override
public void close() {}
}
// end::expert_engine
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should include LeafScript in the tag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good enough tweak I will try to move these into LeafSearchScript.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed adf95e6.

}
--------------------------------------------------
// CONSOLE
// TEST[skip:we don't have an expert script plugin installed to test this]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, we totally could though. We already install all the plugins, I think we'd just need to fix the loop we use for it and this'd be installed too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but I'd rather leave that as a separate issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We install all the other plugins for these tests so I think this would be the PR to add it.

Copy link
Contributor

@imotov imotov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left a couple of minor comments.

if ("pure_df".equals(scriptSource)) {
return p -> new SearchScript() {
String field = p.get("field").toString();
String term = p.get("term").toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to add a check for existence of these parameters for completeness.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added checks in 1070eb3.

* Return the result as a long. This is used by aggregation scripts over long fields.
*/
default long runAsLong() {
return (long) runAsDouble();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am somewhat conflicted about this. On one side I like this simplicity, on the other side if these default implementation are ever invoked, it most likely means that the script is used in a wrong context or has not been optimized for some contexts. Maybe, we shouldn't provide a default implementation, but instead clearly document in which contexts runAsLong, runAsDouble and run are called from and follow the same model as we do with search vs executable script and throw UnsupportedOperationException if a wrong method is called. I think this will encourage the users to read the comments on the method and implement the right method for their use case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I changed runAsLong to default to UnsupportedOperationException and tweaked the docs a tiny bit. Also note that with contexts coming this will all change significantly, as each context will have its own dedicated interface, so no more of this shared interface trying to satisfy multiple use cases.

@rjernst rjernst merged commit c1f1f66 into elastic:master May 11, 2017
@rjernst rjernst deleted the replace_native_script_docs branch May 11, 2017 19:15
rjernst added a commit that referenced this pull request May 11, 2017
…#24603)

This commit documents how to write a `ScriptEngine` in order to use
expert internal apis, such as using Lucene directly to find index term
statistics. These documents prepare the way to remove both native
scripts and IndexLookup.

The example java code is actually compiled and tested under a new gradle
subproject for example plugins. This change does not yet breakup
jvm-example into the new examples dir, which should be done separately.

relates #19359
relates #19966
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 >docs General docs changes v5.5.0 v6.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants