-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Enhance painless documentation #22720
Comments
To be fair, when developers hear that two languages are similar, they do not have an expectation that they can paste code from one language into another. For example, developers freely admit that C# and Java are similar (in fact, very similar), but no developer comfortable with one of those languages expects they can paste code back and forth between the two (sometimes you can paste a snippet, the vast majority of the time you can not). This does not negate the point that we should always work to improve our documentation, especially for a feature as nascent as Painless is, but I do think it's worth correcting the expectation that developers have when they say and hear that two languages are similar. |
Agree 100% the documentation needs improvements. I'm currently working on making some, but there's a lot to cover and it's going to take some time to get there. I also see how comparing this language to Groovy could be confusing given the lack of documentation here. |
I'm still working on prerequisites for an API reference.... I think I have one review left before I can revive my work on the reference. That'll help. Some. |
The API reference I was talking about: #22775 |
Adds "Appending B. Painless API Reference", a reference of all classes and methods available from Painless. Removes links to java packages because they contain methods that we don't expose and don't contain methods that we do expose (the ones in Augmentation). Instead this generates a list of every class and every exposed method using the same type information available to the interpreter/compiler/whatever-we-call-it. From there you can jump to the relevant docs. Right now you build all the asciidoc files by running ``` gradle generatePainlessApi ``` These files are expected to be committed because we build the docs without running `gradle`. Also changes the output of `Debug.explain` so that it is easy to search for the class in the generated reference documentation. You can also run it in an IDE safely if you pass the path to the directory in which to generate the docs as the first parameter. It'll blow away the entire directory an recreate it from scratch so be careful. And then you can build the docs by running something like: ``` ../docs/build_docs.pl --out ../built_docs/ --doc docs/reference/index.asciidoc --open ``` That is, if you have checked out https://github.com/elastic/docs in `../docs`. Wait a minute or two and your browser will pop open in with all of Elasticsearch's reference documentation. If you go to `http://localhost:8000/painless-api-reference.html` you can see this list. Or you can get there by following the links to `Modules` and `Scripting` and `Painless` and then clicking the link in the paragraphs below titled `Appendix B. Painless API Reference`. I like having these in asciidoc because we can deep link to them from the rest of the guide with constructs like `<<painless-api-reference-Object-hashCode-0>>` and `<<painless-api-reference->>` and we get link checking. Then the only brittle link maintenance bit is the link generation for javadoc. Which sucks. But I think it is important that we link to the methods directly so they are easy to find. Relates to #22720
Adds "Appending B. Painless API Reference", a reference of all classes and methods available from Painless. Removes links to java packages because they contain methods that we don't expose and don't contain methods that we do expose (the ones in Augmentation). Instead this generates a list of every class and every exposed method using the same type information available to the interpreter/compiler/whatever-we-call-it. From there you can jump to the relevant docs. Right now you build all the asciidoc files by running ``` gradle generatePainlessApi ``` These files are expected to be committed because we build the docs without running `gradle`. Also changes the output of `Debug.explain` so that it is easy to search for the class in the generated reference documentation. You can also run it in an IDE safely if you pass the path to the directory in which to generate the docs as the first parameter. It'll blow away the entire directory an recreate it from scratch so be careful. And then you can build the docs by running something like: ``` ../docs/build_docs.pl --out ../built_docs/ --doc docs/reference/index.asciidoc --open ``` That is, if you have checked out https://github.com/elastic/docs in `../docs`. Wait a minute or two and your browser will pop open in with all of Elasticsearch's reference documentation. If you go to `http://localhost:8000/painless-api-reference.html` you can see this list. Or you can get there by following the links to `Modules` and `Scripting` and `Painless` and then clicking the link in the paragraphs below titled `Appendix B. Painless API Reference`. I like having these in asciidoc because we can deep link to them from the rest of the guide with constructs like `<<painless-api-reference-Object-hashCode-0>>` and `<<painless-api-reference->>` and we get link checking. Then the only brittle link maintenance bit is the link generation for javadoc. Which sucks. But I think it is important that we link to the methods directly so they are easy to find. Relates to #22720
My findings from working with painless a bit:
Attached is an example that will traverse each JSON document in order to fix invalid fields names. Can be attached to an ingest pipeline: |
@PhaedrusTheGreek Thank you for the feedback here! Appreciate it. |
I wouldn't want Emacs to be left out, so: (add-to-list 'auto-mode-alist '("\\.painless$" . groovy-mode)) (requires |
I would not do this. If we want syntax highlighting, then we should create our own filetype plugins for vim/emacs. Otherwise you will think eg a closure is valid, because of syntax highlighting, but painless does not have closures. Likewise, it would not properly format lambdas, since groovy does not support them. |
I believe you can do it java style like |
Sure, I'll add this to my TODO list |
@dakrone If/when you find the time to do this, maybe you can just pull from the existing grammar files to know what valid syntax is. |
Don't forget the semicolon hacks! |
Painless uses Ruby-like method dispatch (reciever type, method name, and arity) rather than Java-like (reciever type, method name, and argument compile time types) or Groovy-like method dispatch (receiver type, method name, and argument run time types). We do this for mostly good reasons but we never documented it. Relates to elastic#22720
Painless uses Ruby-like method dispatch (reciever type, method name, and arity) rather than Java-like (reciever type, method name, and argument compile time types) or Groovy-like method dispatch (receiver type, method name, and argument run time types). We do this for mostly good reasons but we never documented it. Relates to #22720
Painless uses Ruby-like method dispatch (reciever type, method name, and arity) rather than Java-like (reciever type, method name, and argument compile time types) or Groovy-like method dispatch (receiver type, method name, and argument run time types). We do this for mostly good reasons but we never documented it. Relates to #22720
Painless uses Ruby-like method dispatch (reciever type, method name, and arity) rather than Java-like (reciever type, method name, and argument compile time types) or Groovy-like method dispatch (receiver type, method name, and argument run time types). We do this for mostly good reasons but we never documented it. Relates to #22720
@jdconrad Please find some time to answer StackOverFlow questions, right now it is very hard learning curve. |
@Cinerar I'd be happy to. Do you have any particular questions or links to questions that you would like to me to prioritize? |
@Cinerar it is more appropriate to open a new issue in http://discuss.elastic.co/ if you have a specific question. I am sure that @jdconrad or any other Engineer will be more than happy to help 😃 . |
@jdconrad There are not so much of them right now. I'm interested in http://stackoverflow.com/questions/42009778/elasticsearch-painless-script-how-to-iterate-in-an-array-of-nested-objects Thank you. |
A few things
|
Closing this in favor of (#23777) |
We state that painless is similar than Groovy, but to be fair most of the code that you paste from groovy will need to be modified in order to work with this new language.
One simple example is the following that works in Groovy but not in Painless:
Now, this could be translated into the following:
Also, looks like
joda.time.DateTime
cannot be used, and there is no clear explanation how to deal with dates. See #22162.As you can see, it's similar, but still you usually need to modify a big part of the code. Unfortunately this type of similarities are not documented, nor you can understand in an easy way how to translate groovy or how to develop with painless. My proposal is to:
We shouldn't expect to have a large documentation, but at least to have the general concepts. Just to see how other languages are explained:
The text was updated successfully, but these errors were encountered: