Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export type {
FunctionDefinition,
CommandDefinition,
CommandOptionsDefinition,
CommandModeDefinition,
Literals,
} from './src/definitions/types';
export type { ESQLCallbacks } from './src/shared/types';
Expand Down Expand Up @@ -51,7 +50,6 @@ export {
printFunctionSignature,
checkFunctionArgMatchesDefinition as isEqualType,
isSourceItem,
isSettingItem,
isFunctionItem,
isOptionItem,
isColumnItem,
Expand All @@ -61,7 +59,6 @@ export {
isAssignmentComplete,
isSingleItem,
} from './src/shared/helpers';
export { ENRICH_MODES } from './src/definitions/settings';
export { timeUnits } from './src/definitions/literals';
export { aggFunctionDefinitions } from './src/definitions/generated/aggregation_functions';
export { getFunctionSignatures } from './src/definitions/helpers';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import { ESQLCommand } from '@kbn/esql-ast';
import { i18n } from '@kbn/i18n';
import { ENRICH_MODES } from '../../../definitions/commands_helpers';
import { isSingleItem } from '../../../..';
import { ENRICH_MODES } from '../../../definitions/settings';
import { SuggestionRawDefinition } from '../../types';
import { TRIGGER_SUGGESTION_COMMAND, getSafeInsertText } from '../../factories';

Expand Down Expand Up @@ -92,13 +92,25 @@ export const noPoliciesAvailableSuggestion: SuggestionRawDefinition = {
},
};

export const modeSuggestions: SuggestionRawDefinition[] = ENRICH_MODES.values.map(
export const modeDescription = i18n.translate(
'kbn-esql-validation-autocomplete.esql.definitions.ccqMode',
{
defaultMessage: 'Cross-cluster query mode',
}
);

export const modeSuggestions: SuggestionRawDefinition[] = ENRICH_MODES.map(
({ name, description }) => ({
label: `${ENRICH_MODES.prefix || ''}${name}`,
text: `${ENRICH_MODES.prefix || ''}${name}:$0`,
label: `_${name}`,
text: `_${name}:$0`,
asSnippet: true,
kind: 'Reference',
detail: `${ENRICH_MODES.description} - ${description}`,
detail: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.ccqModeDoc', {
defaultMessage: 'Cross-cluster query mode - ${description}',
values: {
description,
},
}),
sortText: 'D',
command: TRIGGER_SUGGESTION_COMMAND,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ import {
type ESQLFunction,
isFunctionExpression,
isWhereExpression,
ESQLCommandMode,
} from '@kbn/esql-ast';
import { isAssignment, isColumnItem, isFunctionItem } from '../shared/helpers';
import {
isAssignment,
isColumnItem,
isFunctionItem,
isSingleItem,
noCaseCompare,
} from '../shared/helpers';
import {
appendSeparatorOption,
asOption,
Expand All @@ -25,10 +32,9 @@ import {
onOption,
withOption,
} from './options';
import { ENRICH_MODES } from './settings';

import { type CommandDefinition } from './types';
import { checkAggExistence, checkFunctionContent } from './commands_helpers';
import { ENRICH_MODES, checkAggExistence, checkFunctionContent } from './commands_helpers';

import { suggest as suggestForDissect } from '../autocomplete/commands/dissect';
import { suggest as suggestForDrop } from '../autocomplete/commands/drop';
Expand All @@ -47,6 +53,8 @@ import { suggest as suggestForSort } from '../autocomplete/commands/sort';
import { suggest as suggestForStats } from '../autocomplete/commands/stats';
import { suggest as suggestForWhere } from '../autocomplete/commands/where';

import { getMessageFromId } from '../validation/errors';

const statsValidator = (command: ESQLCommand) => {
const messages: ESQLMessage[] = [];
const commandName = command.name.toUpperCase();
Expand Down Expand Up @@ -147,7 +155,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
},
suggest: suggestForRow,
options: [],
modes: [],
},
{
name: 'from',
Expand All @@ -157,7 +164,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
}),
examples: ['from logs', 'from logs-*', 'from logs_*, events-*'],
options: [metadataOption],
modes: [],
signature: {
multipleParams: true,
params: [{ name: 'index', type: 'source', wildcards: true }],
Expand All @@ -171,7 +177,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
}),
examples: ['SHOW INFO'],
options: [],
modes: [],
signature: {
multipleParams: false,
params: [{ name: 'functions', type: 'function' }],
Expand Down Expand Up @@ -200,7 +205,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
'metrics src1, src2 agg1, agg2 by field1, field2',
],
options: [],
modes: [],
signature: {
multipleParams: true,
params: [
Expand All @@ -222,7 +226,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
params: [{ name: 'expression', type: 'function', optional: true }],
},
options: [byOption],
modes: [],
validate: statsValidator,
suggest: suggestForStats,
},
Expand All @@ -242,7 +245,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
params: [{ name: 'expression', type: 'function', optional: true }],
},
options: [byOption],
modes: [],
// Reusing the same validation logic as stats command
validate: statsValidator,
suggest: () => [],
Expand All @@ -265,7 +267,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
params: [{ name: 'expression', type: 'any' }],
},
options: [],
modes: [],
suggest: suggestForEval,
},
{
Expand All @@ -279,7 +280,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
params: [{ name: 'renameClause', type: 'column' }],
},
options: [asOption],
modes: [],
suggest: suggestForRename,
},
{
Expand All @@ -294,7 +294,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
params: [{ name: 'size', type: 'integer', constantOnly: true }],
},
options: [],
modes: [],
suggest: suggestForLimit,
},
{
Expand All @@ -306,7 +305,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
examples: ['… | keep a', '… | keep a,b'],
suggest: suggestForKeep,
options: [],
modes: [],
signature: {
multipleParams: true,
params: [{ name: 'column', type: 'column', wildcards: true }],
Expand All @@ -319,7 +317,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
}),
examples: ['… | drop a', '… | drop a,b'],
options: [],
modes: [],
signature: {
multipleParams: true,
params: [{ name: 'column', type: 'column', wildcards: true }],
Expand Down Expand Up @@ -376,7 +373,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
'… | sort a - abs(b)',
],
options: [],
modes: [],
signature: {
multipleParams: true,
params: [{ name: 'expression', type: 'any' }],
Expand All @@ -396,7 +392,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
params: [{ name: 'expression', type: 'boolean' }],
},
options: [],
modes: [],
suggest: suggestForWhere,
},
{
Expand All @@ -407,7 +402,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
}),
examples: ['… | DISSECT a "%{b} %{c}" APPEND_SEPARATOR = ":"'],
options: [appendSeparatorOption],
modes: [],
signature: {
multipleParams: false,
params: [
Expand All @@ -425,7 +419,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
}),
examples: ['… | GROK a "%{IP:b} %{NUMBER:c}"'],
options: [],
modes: [],
signature: {
multipleParams: false,
params: [
Expand All @@ -442,7 +435,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
}),
examples: ['row a=[1,2,3] | mv_expand a'],
options: [],
modes: [],
preview: true,
signature: {
multipleParams: false,
Expand All @@ -462,20 +454,44 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
'… | enrich my-policy on pivotField with a = enrichFieldA, b = enrichFieldB',
],
options: [onOption, withOption],
modes: [ENRICH_MODES],
signature: {
multipleParams: false,
params: [{ name: 'policyName', type: 'source', innerTypes: ['policy'] }],
},
suggest: suggestForEnrich,
validate: (command: ESQLCommand) => {
const modeArg = command.args.find((arg) => isSingleItem(arg) && arg.type === 'mode') as
| ESQLCommandMode
| undefined;

if (!modeArg) {
return [];
}

const acceptedValues = ENRICH_MODES.map(({ name }) => '_' + name);
if (acceptedValues.some((value) => noCaseCompare(modeArg.text, value))) {
return [];
}

return [
getMessageFromId({
messageId: 'unsupportedMode',
values: {
command: 'ENRICH',
value: modeArg.text,
expected: acceptedValues.join(', '),
},
locations: modeArg.location,
}),
];
},
},
{
name: 'hidden_command',
description: 'A test fixture to test hidden-ness',
hidden: true,
examples: [],
options: [],
modes: [],
signature: {
params: [],
multipleParams: false,
Expand Down Expand Up @@ -527,7 +543,6 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
// '… | <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',
],
modes: [],
signature: {
multipleParams: true,
params: [{ name: 'index', type: 'source', wildcards: true }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
isFieldExpression,
Walker,
} from '@kbn/esql-ast';
import { i18n } from '@kbn/i18n';
import {
getFunctionDefinition,
isFunctionItem,
Expand Down Expand Up @@ -80,3 +81,27 @@ export function checkAggExistence(arg: ESQLFunction): boolean {

return false;
}

export const ENRICH_MODES = [
{
name: 'any',
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.ccqAnyDoc', {
defaultMessage: 'Enrich takes place on any cluster',
}),
},
{
name: 'coordinator',
description: i18n.translate(
'kbn-esql-validation-autocomplete.esql.definitions.ccqCoordinatorDoc',
{
defaultMessage: 'Enrich takes place on the coordinating cluster receiving an ES|QL',
}
),
},
{
name: 'remote',
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.ccqRemoteDoc', {
defaultMessage: 'Enrich takes place on the cluster hosting the target index.',
}),
},
];

This file was deleted.

Loading