Skip to content

Commit

Permalink
[9.0] [ES|QL] Improvements in JOIN autocomplete (#210401) (#210517)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `9.0`:
- [[ES|QL] Improvements in JOIN autocomplete
(#210401)](#210401)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Stratoula
Kalafateli","email":"efstratia.kalafateli@elastic.co"},"sourceCommit":{"committedDate":"2025-02-11T09:35:29Z","message":"[ES|QL]
Improvements in JOIN autocomplete (#210401)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/210382\n\n<img width=\"826\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/e13c51a7-2c39-4954-8502-3053ec52a46d\"\n/>\n\n\n![image](https://github.com/user-attachments/assets/d8500c92-d85d-470f-b25c-44535d832156)\n\n-
Added a tech preview label (also for MV_EXPAND)\n- Improve the
signature","sha":"3ccdae70b66703de134073efa806e0dddaa5e66b","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Feature:ES|QL","Team:ESQL","backport:version","v8.18.0","v9.1.0","v8.19.0"],"title":"[ES|QL]
Improvements in JOIN
autocomplete","number":210401,"url":"https://github.com/elastic/kibana/pull/210401","mergeCommit":{"message":"[ES|QL]
Improvements in JOIN autocomplete (#210401)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/210382\n\n<img width=\"826\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/e13c51a7-2c39-4954-8502-3053ec52a46d\"\n/>\n\n\n![image](https://github.com/user-attachments/assets/d8500c92-d85d-470f-b25c-44535d832156)\n\n-
Added a tech preview label (also for MV_EXPAND)\n- Improve the
signature","sha":"3ccdae70b66703de134073efa806e0dddaa5e66b"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/210401","number":210401,"mergeCommit":{"message":"[ES|QL]
Improvements in JOIN autocomplete (#210401)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/210382\n\n<img width=\"826\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/e13c51a7-2c39-4954-8502-3053ec52a46d\"\n/>\n\n\n![image](https://github.com/user-attachments/assets/d8500c92-d85d-470f-b25c-44535d832156)\n\n-
Added a tech preview label (also for MV_EXPAND)\n- Improve the
signature","sha":"3ccdae70b66703de134073efa806e0dddaa5e66b"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
  • Loading branch information
kibanamachine and stratoula authored Feb 11, 2025
1 parent 3f49fd9 commit a9ae718
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import { getCommandDefinition } from '../shared/helpers';
import { getCommandSignature } from '../definitions/helpers';
import { buildDocumentation } from './documentation_util';

const techPreviewLabel = i18n.translate(
'kbn-esql-validation-autocomplete.esql.autocomplete.techPreviewLabel',
{
defaultMessage: `Technical Preview`,
}
);

export function getAssignmentDefinitionCompletitionItem() {
const assignFn = builtinFunctions.find(({ name }) => name === '=')!;
return getOperatorSuggestion(assignFn);
Expand All @@ -32,7 +39,6 @@ export const getCommandAutocompleteDefinitions = (
}

const commandDefinition = getCommandDefinition(command.name);
const commandSignature = getCommandSignature(commandDefinition);
const label = commandDefinition.name.toUpperCase();
const text = commandDefinition.signature.params.length
? `${commandDefinition.name.toUpperCase()} $0`
Expand All @@ -45,12 +51,17 @@ export const getCommandAutocompleteDefinitions = (
];

for (const type of types) {
let detail = type.description || commandDefinition.description;
if (commandDefinition.preview) {
detail = `[${techPreviewLabel}] ${detail}`;
}
const commandSignature = getCommandSignature(commandDefinition, type.name);
const suggestion: SuggestionRawDefinition = {
label: type.name ? `${type.name.toLocaleUpperCase()} ${label}` : label,
text: type.name ? `${type.name.toLocaleUpperCase()} ${text}` : text,
asSnippet: true,
kind: 'Method',
detail: type.description || commandDefinition.description,
detail,
documentation: {
value: buildDocumentation(commandSignature.declaration, commandSignature.examples),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
examples: ['row a=[1,2,3] | mv_expand a'],
options: [],
modes: [],
preview: true,
signature: {
multipleParams: false,
params: [{ name: 'column', type: 'column', innerTypes: ['any'] }],
Expand Down Expand Up @@ -557,19 +558,20 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.joinDoc', {
defaultMessage: 'Join table with another table.',
}),
preview: true,
examples: [
'… | LOOKUP JOIN lookup_index ON join_field',
// TODO: Uncomment when other join types are implemented
// '… | <LEFT | RIGHT | LOOKUP> JOIN index ON index.field = index2.field',
// '… | <LEFT | RIGHT | LOOKUP> JOIN index AS alias ON index.field = index2.field',
// '… | <LEFT | RIGHT | LOOKUP> JOIN index AS alias ON index.field = index2.field, index.field2 = index2.field2',
],
options: [],
modes: [],
signature: {
multipleParams: false,
multipleParams: true,
params: [{ name: 'index', type: 'source', wildcards: true }],
},
options: [onOption],
suggest: suggestForJoin,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ function handleAdditionalArgs(

export function getCommandSignature(
{ name, signature, options, examples }: CommandDefinition<string>,
typeName?: string,
{ withTypes }: { withTypes: boolean } = { withTypes: true }
) {
const commandName = typeName
? `${typeName.toUpperCase()} ${name.toUpperCase()}`
: name.toUpperCase();
return {
declaration: `${name.toUpperCase()} ${printCommandArguments(signature, withTypes)} ${(
declaration: `${commandName} ${printCommandArguments(signature, withTypes)} ${(
options || []
).map(
(option) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ export interface CommandBaseDefinition<CommandName extends string> {

alias?: string;
description: string;
/**
* Displays a Technical preview label in the autocomplete
*/
preview?: boolean;
/**
* Whether to show or hide in autocomplete suggestion list
*/
Expand Down

0 comments on commit a9ae718

Please sign in to comment.