-
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.
Browse files
Browse the repository at this point in the history
# Backport This will backport the following commits from `main` to `8.x`: - [[ES|QL] handle snapshot-only functions (#195691)](#195691) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Drew Tate","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-11T14:34:13Z","message":"[ES|QL] handle snapshot-only functions (#195691)\n\n## Summary\r\n\r\nClose https://github.com/elastic/kibana/issues/192712\r\n\r\nSnapshot-only functions are no longer suggested by the editor, though\r\nthey are still validated if typed.\r\n\r\nAlso, they are excluded from the inline function documentation.\r\n\r\n### Checklist\r\n\r\n- [x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"65df0280e1c96a9cc8b88f77ed0aca23190f7537","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","Feature:ES|QL","Team:ESQL"],"title":"[ES|QL] handle snapshot-only functions","number":195691,"url":"https://github.com/elastic/kibana/pull/195691","mergeCommit":{"message":"[ES|QL] handle snapshot-only functions (#195691)\n\n## Summary\r\n\r\nClose https://github.com/elastic/kibana/issues/192712\r\n\r\nSnapshot-only functions are no longer suggested by the editor, though\r\nthey are still validated if typed.\r\n\r\nAlso, they are excluded from the inline function documentation.\r\n\r\n### Checklist\r\n\r\n- [x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"65df0280e1c96a9cc8b88f77ed0aca23190f7537"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195691","number":195691,"mergeCommit":{"message":"[ES|QL] handle snapshot-only functions (#195691)\n\n## Summary\r\n\r\nClose https://github.com/elastic/kibana/issues/192712\r\n\r\nSnapshot-only functions are no longer suggested by the editor, though\r\nthey are still validated if typed.\r\n\r\nAlso, they are excluded from the inline function documentation.\r\n\r\n### Checklist\r\n\r\n- [x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine <[email protected]>","sha":"65df0280e1c96a9cc8b88f77ed0aca23190f7537"}}]}] BACKPORT--> Co-authored-by: Drew Tate <[email protected]>
- Loading branch information
1 parent
7b9ace8
commit f029ee9
Showing
8 changed files
with
164 additions
and
86 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
124 changes: 124 additions & 0 deletions
124
...-validation-autocomplete/src/autocomplete/__tests__/hidden_functions_and_commands.test.ts
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,124 @@ | ||
/* | ||
* 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 { setTestFunctions } from '../../shared/test_functions'; | ||
import { setup } from './helpers'; | ||
|
||
describe('hidden commands', () => { | ||
it('does not suggest hidden commands', async () => { | ||
const { suggest } = await setup(); | ||
const suggestedCommands = (await suggest('FROM index | /')).map((s) => s.text); | ||
expect(suggestedCommands).not.toContain('HIDDEN_COMMAND $0'); | ||
expect(suggestedCommands).toContain('EVAL $0'); | ||
expect(suggestedCommands.every((s) => !s.toLowerCase().includes('HIDDEN_COMMAND'))).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('hidden functions', () => { | ||
afterEach(() => { | ||
setTestFunctions([]); | ||
}); | ||
|
||
it('does not suggest hidden scalar functions', async () => { | ||
setTestFunctions([ | ||
{ | ||
type: 'eval', | ||
name: 'HIDDEN_FUNCTION', | ||
description: 'This is a hidden function', | ||
signatures: [{ params: [], returnType: 'text' }], | ||
supportedCommands: ['eval'], | ||
ignoreAsSuggestion: true, | ||
}, | ||
{ | ||
type: 'eval', | ||
name: 'VISIBLE_FUNCTION', | ||
description: 'This is a visible function', | ||
signatures: [{ params: [], returnType: 'text' }], | ||
supportedCommands: ['eval'], | ||
ignoreAsSuggestion: false, | ||
}, | ||
]); | ||
|
||
const { suggest } = await setup(); | ||
const suggestedFunctions = (await suggest('FROM index | EVAL /')).map((s) => s.text); | ||
expect(suggestedFunctions).toContain('VISIBLE_FUNCTION($0)'); | ||
expect(suggestedFunctions).not.toContain('HIDDEN_FUNCTION($0)'); | ||
}); | ||
it('does not suggest hidden agg functions', async () => { | ||
setTestFunctions([ | ||
{ | ||
type: 'agg', | ||
name: 'HIDDEN_FUNCTION', | ||
description: 'This is a hidden function', | ||
signatures: [{ params: [], returnType: 'text' }], | ||
supportedCommands: ['stats'], | ||
ignoreAsSuggestion: true, | ||
}, | ||
{ | ||
type: 'agg', | ||
name: 'VISIBLE_FUNCTION', | ||
description: 'This is a visible function', | ||
signatures: [{ params: [], returnType: 'text' }], | ||
supportedCommands: ['stats'], | ||
ignoreAsSuggestion: false, | ||
}, | ||
]); | ||
|
||
const { suggest } = await setup(); | ||
const suggestedFunctions = (await suggest('FROM index | STATS /')).map((s) => s.text); | ||
expect(suggestedFunctions).toContain('VISIBLE_FUNCTION($0)'); | ||
expect(suggestedFunctions).not.toContain('HIDDEN_FUNCTION($0)'); | ||
}); | ||
|
||
it('does not suggest hidden operators', async () => { | ||
setTestFunctions([ | ||
{ | ||
type: 'builtin', | ||
name: 'HIDDEN_OPERATOR', | ||
description: 'This is a hidden function', | ||
supportedCommands: ['eval', 'where', 'row', 'sort'], | ||
ignoreAsSuggestion: true, | ||
supportedOptions: ['by'], | ||
signatures: [ | ||
{ | ||
params: [ | ||
{ name: 'left', type: 'keyword' as const }, | ||
{ name: 'right', type: 'keyword' as const }, | ||
], | ||
returnType: 'boolean', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'builtin', | ||
name: 'VISIBLE_OPERATOR', | ||
description: 'This is a visible function', | ||
supportedCommands: ['eval', 'where', 'row', 'sort'], | ||
ignoreAsSuggestion: false, | ||
supportedOptions: ['by'], | ||
signatures: [ | ||
{ | ||
params: [ | ||
{ name: 'left', type: 'keyword' as const }, | ||
{ name: 'right', type: 'keyword' as const }, | ||
], | ||
returnType: 'boolean', | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
const { suggest } = await setup(); | ||
const suggestedFunctions = (await suggest('FROM index | EVAL keywordField /')).map( | ||
(s) => s.text | ||
); | ||
expect(suggestedFunctions).toContain('VISIBLE_OPERATOR $0'); | ||
expect(suggestedFunctions).not.toContain('HIDDEN_OPERATOR $0'); | ||
}); | ||
}); |
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
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