Skip to content

Commit

Permalink
[ES|QL] Generate function definitions from Elasticsearch metadata (#1…
Browse files Browse the repository at this point in the history
…79584)

## Summary

Resolve #179634

This PR introduces a script to gather metadata from Elasticsearch and
build the function definitions for Kibana's client-side validation.

To run the script: `cd packages/kbn-esql-validation-autocomplete && yarn
makedefs path/to/elasticsearch/repo`

## Current limitations
### Things we can't (yet) gather from ES

#### Things that are currently being filled in on the Kibana side but
would be missing if we had to rely completely on ES
- function aliases (e.g. `to_str`)
- operators and aggs (issues for Elasticsearch
elastic/elasticsearch#107219 and
elastic/elasticsearch#107220)
- Kibana AST parameter settings
- `constantOnly` — whether a parameter can be a non-literal or not
(`percentile`, `auto_bucket`)
- `constantOptions`/`constantSuggestions` — specific information about
which constants are accepted or suggested for particular parameters.
- `supportsWildcard` — whether a parameter can contain `*` (only `count`
at the moment)
- `noNestingFunctions` — whether a parameter can contain nested
functions (used for all agg functions)
- Kibana date constant types
  - `chrono_literal`
  - `time_literal`

### Other considerations
- Asciidoc links need to be scrubbed (e.g. `Function
{wikipedia}/foo/bar[arccosine] returns blah blah`)
- As of elastic/elasticsearch#106454 some
descriptions reference outdated parameter names and some parameter names
are questionable:
<img width="600" alt="Screenshot 2024-03-28 at 1 07 16 PM"
src="https://github.com/elastic/kibana/assets/315764/3b9ab457-e9fd-4c5f-afb2-23ae769bb44a">

_parameter `n` is now called `number`, but the description still calls
it `n`... also, is `number` really the best name for the variable?_

### Checklist

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Stratoula Kalafateli <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
3 people authored May 24, 2024
1 parent e7e0c86 commit 72d2a56
Show file tree
Hide file tree
Showing 23 changed files with 19,251 additions and 4,758 deletions.
1 change: 1 addition & 0 deletions packages/kbn-esql-validation-autocomplete/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
SRCS = glob(
[
"**/*.ts",
"**/*functions.json",
],
exclude = [
"**/*.config.js",
Expand Down
7 changes: 6 additions & 1 deletion packages/kbn-esql-validation-autocomplete/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"license": "SSPL-1.0 OR Elastic License 2.0",
"sideEffects": false,
"scripts": {
"maketests": "ts-node --transpileOnly ./scripts/generate_function_validation_tests.ts"
"make:tests": "ts-node --transpileOnly ./scripts/generate_function_validation_tests.ts",
"postmake:tests": "yarn run lint:fix",
"make:defs": "ts-node --transpileOnly ./scripts/generate_function_definitions.ts",
"postmake:defs": "yarn run lint:fix && yarn run i18n:fix",
"lint:fix": "cd ../.. && node ./scripts/eslint --fix ./packages/kbn-esql-validation-autocomplete/src/**/*.ts",
"i18n:fix": "cd ../.. && node ./scripts/i18n_check.js --fix"
}
}
Loading

0 comments on commit 72d2a56

Please sign in to comment.