-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[ES|QL] support SAMPLE command
#221446
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
Merged
Merged
[ES|QL] support SAMPLE command
#221446
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
0e937a9
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 7ffbf4c
Merge branch 'main' of github.com:elastic/kibana
drewdaemon b426318
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 511ccaa
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 2d71300
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 0076de9
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 2898ce1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon ace0009
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 6cdd8c1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 98616e9
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 64e40fd
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 1e3f8d1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon afd5630
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 31c6cb3
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 08f4b1b
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 0c11f55
Merge branch 'main' of github.com:elastic/kibana
drewdaemon de2bc7a
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 828d142
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 34bd1ef
Merge branch 'main' of github.com:elastic/kibana
drewdaemon f0070c6
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 16a27c7
Merge branch 'main' of github.com:elastic/kibana
drewdaemon cde697e
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 8b66178
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 3555b0c
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 57a5f4a
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 420eb2b
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 8e5e4a8
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 141765f
Merge branch 'main' of github.com:elastic/kibana
drewdaemon cdf4d20
Merge branch 'main' of github.com:elastic/kibana
drewdaemon 135795f
add sample command to AST
drewdaemon dc6ab94
Merge branch 'main' of github.com:elastic/kibana into 217977/support-…
drewdaemon dac4ab5
add AST apis
drewdaemon 12fdf3b
Autocomplete
drewdaemon 1a04a78
Merge branch 'main' into 217977/support-sample
stratoula 8eb2a14
Merge branch 'main' of github.com:elastic/kibana into 217977/support-…
drewdaemon 36bd43e
fix type
drewdaemon ea86f80
comment for regex
drewdaemon c79cf30
Merge branch 'main' into 217977/support-sample
stratoula File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
src/platform/packages/shared/kbn-esql-ast/src/parser/__tests__/sample.test.ts
This file contains hidden or 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,96 @@ | ||
| /* | ||
| * 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 { Parser } from '../parser'; | ||
|
|
||
| describe('SAMPLE', () => { | ||
| describe('correctly formatted', () => { | ||
| test('without seed', () => { | ||
| const text = ` | ||
| FROM employees | ||
| | SAMPLE 0.25 | ||
| `; | ||
| const { ast, errors } = Parser.parse(text); | ||
|
|
||
| expect(errors.length).toBe(0); | ||
| expect(ast).toMatchObject([ | ||
| {}, | ||
| { | ||
| type: 'command', | ||
| name: 'sample', | ||
| args: [ | ||
| { | ||
| type: 'literal', | ||
| literalType: 'double', | ||
| value: 0.25, | ||
| }, | ||
| ], | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| test('with seed', () => { | ||
| const text = ` | ||
| FROM employees | ||
| | SAMPLE 0.25 123 | ||
| `; | ||
| const { ast, errors } = Parser.parse(text); | ||
|
|
||
| expect(errors.length).toBe(0); | ||
| expect(ast).toMatchObject([ | ||
| {}, | ||
| { | ||
| type: 'command', | ||
| name: 'sample', | ||
| args: [ | ||
| { | ||
| type: 'literal', | ||
| literalType: 'double', | ||
| value: 0.25, | ||
| }, | ||
| { | ||
| type: 'literal', | ||
| literalType: 'integer', | ||
| value: 123, | ||
| }, | ||
| ], | ||
| }, | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('errors', () => { | ||
| it('wrong data type for probability', () => { | ||
| const { errors } = Parser.parse(` | ||
| FROM employees | ||
| | SAMPLE 25 | ||
| `); | ||
|
|
||
| expect(errors.length).toBe(1); | ||
| }); | ||
|
|
||
| it('wrong data type for seed', () => { | ||
| const { errors } = Parser.parse(` | ||
| FROM employees | ||
| | SAMPLE .25 .123 | ||
| `); | ||
|
|
||
| expect(errors.length).toBe(1); | ||
| }); | ||
|
|
||
| it('command with no args', () => { | ||
| const { errors } = Parser.parse(` | ||
| FROM employees | ||
| | SAMPLE | ||
| `); | ||
|
|
||
| expect(errors.length).toBe(1); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
23 changes: 23 additions & 0 deletions
23
...ql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.command.sample.test.ts
This file contains hidden or 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,23 @@ | ||
| /* | ||
| * 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 { setup } from './helpers'; | ||
|
|
||
| describe('autocomplete.suggest', () => { | ||
| describe('SAMPLE <percentage> [<seed>]', () => { | ||
| test('suggests percentages', async () => { | ||
| const { assertSuggestions } = await setup(); | ||
| assertSuggestions('from a | SAMPLE /', ['.1 ', '.01 ', '.001 ']); | ||
| }); | ||
|
|
||
| test('suggests pipe after number', async () => { | ||
| const { assertSuggestions } = await setup(); | ||
| assertSuggestions('from a | SAMPLE .48 /', ['| ']); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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
24 changes: 24 additions & 0 deletions
24
...ackages/shared/kbn-esql-validation-autocomplete/src/autocomplete/commands/sample/index.ts
This file contains hidden or 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,24 @@ | ||
| /* | ||
| * 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 { CommandSuggestParams } from '../../../definitions/types'; | ||
| import type { SuggestionRawDefinition } from '../../types'; | ||
| import { buildConstantsDefinitions } from '../../factories'; | ||
| import { pipeCompleteItem } from '../../complete_items'; | ||
|
|
||
| export function suggest({ innerText }: CommandSuggestParams<'sample'>): SuggestionRawDefinition[] { | ||
| // test for a number and at least one whitespace char at the end of the innerText | ||
| if (/[0-9]\s+$/.test(innerText)) { | ||
| return [pipeCompleteItem]; | ||
| } | ||
|
|
||
| return buildConstantsDefinitions(['.1', '.01', '.001'], '', undefined, { | ||
| advanceCursorAndOpenSuggestions: true, | ||
| }); | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.