elasticsearch/docs/reference/scripting-languages/painless/how-painless-dispatches-function.md
Colleen McGinnis b7e3a1e14b
[docs] Migrate docs from AsciiDoc to Markdown (#123507)
* delete asciidoc files

* add migrated files

* fix errors

* Disable docs tests

* Clarify release notes page titles

* Revert "Clarify release notes page titles"

This reverts commit 8be688648d.

* Comment out edternal URI images

* Clean up query languages landing pages, link to conceptual docs

* Add .md to url

* Fixes inference processor nesting.

---------

Co-authored-by: Liam Thompson <32779855+leemthompo@users.noreply.github.com>
Co-authored-by: Liam Thompson <leemthompo@gmail.com>
Co-authored-by: Martijn Laarman <Mpdreamz@gmail.com>
Co-authored-by: István Zoltán Szabó <szabosteve@gmail.com>
2025-02-27 17:56:14 +01:00

1.8 KiB
Raw Blame History

mapped_pages
https://www.elastic.co/guide/en/elasticsearch/painless/current/modules-scripting-painless-dispatch.html

How painless dispatches function [modules-scripting-painless-dispatch]

Painless uses receiver, name, and arity for method dispatch. For example, s.foo(a, b) is resolved by first getting the class of s and then looking up the method foo with two parameters. This is different from Groovy which uses the runtime types of the parameters and Java which uses the compile time types of the parameters.

The consequence of this that Painless doesnt support overloaded methods like Java, leading to some trouble when it allows classes from the Java standard library. For example, in Java and Groovy, Matcher has two methods: group(int) and group(String). Painless cant allow both of these methods because they have the same name and the same number of parameters. So instead it has group(int) and namedGroup(String).

We have a few justifications for this different way of dispatching methods:

  1. It makes operating on def types simpler and, presumably, faster. Using receiver, name, and arity means that when Painless sees a call on a def object it can dispatch the appropriate method without having to do expensive comparisons of the types of the parameters. The same is true for invocations with def typed parameters.
  2. It keeps things consistent. It would be genuinely weird for Painless to behave like Groovy if any def typed parameters were involved and Java otherwise. Itd be slow for it to behave like Groovy all the time.
  3. It keeps Painless maintainable. Adding the Java or Groovy like method dispatch feels like itd add a ton of complexity whichd make maintenance and other improvements much more difficult.