forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ES|QL] Support all AST node types in
Walker
(elastic#188712)
## Summary Partially addresses elastic#182255 - This PR add support for all ES|QL AST node types in the `Walker` class, which means all nodes from any query now will be visited. ### Checklist Delete any items that are not applicable to this PR. - [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 ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- Loading branch information
1 parent
d5b9af1
commit cc65a51
Showing
4 changed files
with
724 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# ES|QL AST Walker | ||
|
||
The ES|QL AST Walker is a utility that traverses the ES|QL AST and provides a | ||
set of callbacks that can be used to perform introspection of the AST. | ||
|
||
To start a new *walk* you create a `Walker` instance and call the `walk()` method | ||
with the AST node to start the walk from. | ||
|
||
```ts | ||
|
||
import { Walker, getAstAndSyntaxErrors } from '@kbn/esql-ast'; | ||
|
||
const walker = new Walker({ | ||
// Called every time a function node is visited. | ||
visitFunction: (fn) => { | ||
console.log('Function:', fn.name); | ||
}, | ||
// Called every time a source identifier node is visited. | ||
visitSource: (source) => { | ||
console.log('Source:', source.name); | ||
}, | ||
}); | ||
|
||
const { ast } = getAstAndSyntaxErrors('FROM source | STATS fn()'); | ||
walker.walk(ast); | ||
``` | ||
|
||
Conceptual structure of an ES|QL AST: | ||
|
||
- A single ES|QL query is composed of one or more source commands and zero or | ||
more transformation commands. | ||
- Each command is represented by a `command` node. | ||
- Each command contains a list expressions named in ES|QL AST as *AST Item*. | ||
- `function` — function call expression. | ||
- `option` — a list of expressions with a specific role in the command. | ||
- `source` — s source identifier expression. | ||
- `column` — a field identifier expression. | ||
- `timeInterval` — a time interval expression. | ||
- `list` — a list literal expression. | ||
- `literal` — a literal expression. | ||
- `inlineCast` — an inline cast expression. |
Oops, something went wrong.