-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ES|QL] AST query and mutation APIs for metadata fields (#195364)
## Summary Partially addresses #191812 This PR implements some generic ES|QL AST mutation APIs and specifically APIs for working with `FROM` command `METADATA` fields: - `from.metadata.list()` — List all `METADATA` fields. - `from.metadata.find()` — Find a `METADATA` field by name. - `from.metadata.removeByPredicate()` — Remove a `METADATA` field by matching a predicate. - `from.metadata.remove()` — Remove a `METADATA` field by name. - `from.metadata.insert()` — Insert a `METADATA` field. - `from.metadata.upsert()` — Insert `METADATA` field, if it does not exist. ### 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
cfc8aaf
commit a819d65
Showing
15 changed files
with
1,022 additions
and
2 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
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
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,36 @@ | ||
# Mutation API | ||
|
||
The ES|QL mutation API provides methods to navigate and modify the AST. | ||
|
||
|
||
## Usage | ||
|
||
For example, insert a `FROM` command `METADATA` field: | ||
|
||
```typescript | ||
import { parse, mutate, BasicPrettyPrinter } from '@elastic/esql'; | ||
|
||
const { root } = parse('FROM index METADATA _lang'); | ||
|
||
console.log([...mutate.commands.from.metadata.list(root)]); // [ '_lang' ] | ||
|
||
mutate.commands.from.metadata.upsert(root, '_id'); | ||
|
||
console.log([...mutate.commands.from.metadata.list(root)]); // [ '_lang', '_id' ] | ||
|
||
const src = BasicPrettyPrinter.print(root); | ||
|
||
console.log(src); // FROM index METADATA _lang, _id | ||
``` | ||
|
||
|
||
## API | ||
|
||
- `.commands.from.metadata.list()` — List all `METADATA` fields. | ||
- `.commands.from.metadata.find()` — Find a `METADATA` field by name. | ||
- `.commands.from.metadata.removeByPredicate()` — Remove a `METADATA` | ||
field by matching a predicate. | ||
- `.commands.from.metadata.remove()` — Remove a `METADATA` field by name. | ||
- `.commands.from.metadata.insert()` — Insert a `METADATA` field. | ||
- `.commands.from.metadata.upsert()` — Insert `METADATA` field, if it does | ||
not exist. |
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,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import * as metadata from './metadata'; | ||
|
||
export { metadata }; |
Oops, something went wrong.