Skip to content
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f8e9e16
Update script for operators
qn895 Nov 14, 2024
ccb590e
Merge remote-tracking branch 'upstream/main' into esql-sync-operators
qn895 Nov 19, 2024
0918b0a
Update script to automatically sync operators
qn895 Nov 19, 2024
6a7cdde
Update missing not_in, not_like, not_rlike
qn895 Nov 19, 2024
41f7ea3
Update script
qn895 Nov 19, 2024
4f1e647
Update scripts
qn895 Nov 19, 2024
ebf0211
Update types
qn895 Nov 20, 2024
4f6c9e9
Update math function failures
qn895 Nov 20, 2024
de6225e
Update tests
qn895 Nov 28, 2024
6a8113b
Merge branch 'esql-sync-operators' into sync-esql-operators
qn895 Jan 4, 2025
44749aa
Update tests
qn895 Jan 4, 2025
860878e
Clean up
qn895 Jan 4, 2025
6b5c866
Pull operators latest elasticsearch snapshots
qn895 Jan 4, 2025
28388a6
Update types
qn895 Jan 4, 2025
1610c0a
Fix translations
qn895 Jan 5, 2025
847457d
Update tests
qn895 Jan 7, 2025
acc0e79
Merge branch 'main' into sync-esql-operators
stratoula Jan 8, 2025
0f2776e
Merge remote-tracking branch 'upstream/main' into sync-esql-operators
qn895 Jan 13, 2025
93d1853
Clean up
qn895 Jan 13, 2025
3073872
Update to latest, fix types
qn895 Jan 13, 2025
599994b
Clean up getSupportedTypesForBinaryOperators
qn895 Jan 13, 2025
8bec12f
Merge upstream/main
qn895 Jan 14, 2025
261a7ac
Merge branch 'main' into sync-esql-operators
elasticmachine Jan 15, 2025
b70a626
Update operators definition from latest elasticsearch
qn895 Jan 17, 2025
c4b47fd
Update syntax
qn895 Jan 17, 2025
6a00df6
Merge branch 'main' into sync-esql-operators
elasticmachine Jan 21, 2025
4e2bcd9
Update suggest
qn895 Jan 22, 2025
27d36cd
Revert "Update suggest"
qn895 Jan 23, 2025
e144c1a
Fix previous commit deleting content
qn895 Jan 23, 2025
951f39a
Update with latest from elasticsearch
qn895 Jan 23, 2025
a6fd992
Merge remote-tracking branch 'upstream/main' into sync-esql-operators
qn895 Jan 23, 2025
73dd937
Update latest from es again
qn895 Jan 23, 2025
f4b4229
Merge remote-tracking branch 'upstream/main' into sync-esql-operators
qn895 Jan 28, 2025
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ describe('WHERE <expression>', () => {
const expectedComparisonWithDateSuggestions = [
...getDateLiterals(),
...getFieldNamesByType(['date']),
// all functions compatible with a keywordField type
...getFunctionSignaturesByReturnType('where', ['date'], { scalar: true }),
...getFieldNamesByType(['date_nanos']),
...getFunctionSignaturesByReturnType('where', ['date', 'date_nanos'], { scalar: true }),
];
await assertSuggestions(
'from a | where dateField == /',
Expand Down Expand Up @@ -212,10 +212,18 @@ describe('WHERE <expression>', () => {
]);
await assertSuggestions('from index | WHERE not /', [
...getFieldNamesByType('boolean').map((name) => attachTriggerCommand(`${name} `)),
...getFunctionSignaturesByReturnType('where', 'boolean', { scalar: true }),
...getFunctionSignaturesByReturnType('where', 'boolean', { scalar: true }, undefined, [
':',
]),
]);
await assertSuggestions('FROM index | WHERE NOT ENDS_WITH(keywordField, "foo") /', [
...getFunctionSignaturesByReturnType('where', 'boolean', { builtin: true }, ['boolean']),
...getFunctionSignaturesByReturnType(
'where',
'boolean',
{ builtin: true },
['boolean'],
[':']
),
pipeCompleteItem,
]);
await assertSuggestions('from index | WHERE keywordField IS NOT/', [
Expand Down Expand Up @@ -290,9 +298,13 @@ describe('WHERE <expression>', () => {
const { assertSuggestions } = await setup();

await assertSuggestions('FROM index | WHERE doubleField + doubleField /', [
...getFunctionSignaturesByReturnType('where', 'any', { builtin: true, skipAssign: true }, [
'double',
]),
...getFunctionSignaturesByReturnType(
'where',
'any',
{ builtin: true, skipAssign: true },
['double'],
[':']
),
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,37 @@ describe('autocomplete.suggest', () => {
'| ',
...getFunctionSignaturesByReturnType('eval', 'any', { builtin: true, skipAssign: true }, [
'double',
'long',
]),
'IN $0',
'IS NOT NULL',
'IS NULL',
]);
await assertSuggestions(
'from a | eval a=round(doubleField, /',
[
...getFieldNamesByType('integer'),
...getFunctionSignaturesByReturnType('eval', 'integer', { scalar: true }, undefined, [
'round',
]),
...getFieldNamesByType(['integer', 'long']),
...getFunctionSignaturesByReturnType(
'eval',
['integer', 'long'],
{ scalar: true },
undefined,
['round']
),
],
{ triggerCharacter: '(' }
);
await assertSuggestions(
'from a | eval round(doubleField, /',
[
...getFieldNamesByType('integer'),
...getFunctionSignaturesByReturnType('eval', 'integer', { scalar: true }, undefined, [
'round',
]),
...getFieldNamesByType(['integer', 'long']),
...getFunctionSignaturesByReturnType(
'eval',
['integer', 'long'],
{ scalar: true },
undefined,
['round']
),
],
{ triggerCharacter: '(' }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,13 @@ describe('autocomplete', () => {
const expectedDateDiff2ndArgSuggestions = [
TIME_PICKER_SUGGESTION,
...TIME_SYSTEM_PARAMS.map((t) => `${t}, `),
...getFieldNamesByType('date').map((name) => `${name}, `),
...getFunctionSignaturesByReturnType('eval', 'date', { scalar: true }).map((s) => ({
...s,
text: `${s.text},`,
})),
...getFieldNamesByType(['date', 'date_nanos']).map((name) => `${name}, `),
...getFunctionSignaturesByReturnType('eval', ['date', 'date_nanos'], { scalar: true }).map(
(s) => ({
...s,
text: `${s.text},`,
})
),
];
testSuggestions('FROM a | EVAL DATE_DIFF("day", /)', expectedDateDiff2ndArgSuggestions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import {
getOperatorSuggestions,
getSuggestionsAfterNot,
} from './factories';
import { EDITOR_MARKER, METADATA_FIELDS } from '../shared/constants';
import { EDITOR_MARKER, FULL_TEXT_SEARCH_FUNCTIONS, METADATA_FIELDS } from '../shared/constants';
import { getAstContext, removeMarkerArgFromArgsList } from '../shared/context';
import {
buildQueryUntilPreviousCommand,
Expand Down Expand Up @@ -1209,10 +1209,12 @@ async function getFunctionArgsSuggestions(
}))
);
}

// could also be in stats (bucket) but our autocomplete is not great yet
if (
(getTypesFromParamDefs(typesToSuggestNext).includes('date') &&
['where', 'eval'].includes(command.name)) ||
['where', 'eval'].includes(command.name) &&
!FULL_TEXT_SEARCH_FUNCTIONS.includes(fnDefinition.name)) ||
(command.name === 'stats' &&
typesToSuggestNext.some((t) => t && t.type === 'date' && t.constantOnly === true))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { getOverlapRange, getSuggestionsToRightOfOperatorExpression } from '../.
import { getPosition } from './util';
import { pipeCompleteItem } from '../../complete_items';
import {
EDITOR_MARKER,
UNSUPPORTED_COMMANDS_BEFORE_MATCH,
UNSUPPORTED_COMMANDS_BEFORE_QSTR,
} from '../../../shared/constants';
Expand Down Expand Up @@ -169,12 +170,14 @@ export async function suggest(
if (priorCommands.some((c) => UNSUPPORTED_COMMANDS_BEFORE_QSTR.has(c))) {
ignored.push('qstr');
}

const columnSuggestions = await getColumnsByType('any', [], {
advanceCursor: true,
openSuggestions: true,
});

const last = fullTextAst?.[fullTextAst.length - 1];
let columnSuggestions: SuggestionRawDefinition[] = [];
if (!last?.text?.endsWith(`:${EDITOR_MARKER}`)) {
columnSuggestions = await getColumnsByType('any', [], {
advanceCursor: true,
openSuggestions: true,
});
}
suggestions.push(
...columnSuggestions,
...getFunctionSuggestions({ command: 'where', ignored })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ export async function getSuggestionsToRightOfOperatorExpression({
operatorReturnType === 'unknown' || operatorReturnType === 'unsupported'
? 'any'
: operatorReturnType,
ignored: ['='],
ignored: ['=', ':'],
})
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import { i18n } from '@kbn/i18n';
import { ESQL_NUMBER_TYPES, isNumericType } from '../shared/esql_types';
import { isNumericType } from '../shared/esql_types';
import type { FunctionDefinition, FunctionParameterType, FunctionReturnType } from './types';

import { operatorsFunctionDefinitions } from './generated/operators';
type MathFunctionSignature = [FunctionParameterType, FunctionParameterType, FunctionReturnType];

function createMathDefinition(
Expand Down Expand Up @@ -384,150 +384,6 @@ export const comparisonFunctions: FunctionDefinition[] = [
},
].map((op): FunctionDefinition => createComparisonDefinition(op));

const likeFunctions: FunctionDefinition[] = [
// Skip the insensitive case equality until it gets restored back
// new special comparison operator for strings only
// {
// name: '=~',
// description: i18n.translate('kbn-esql-validation-autocomplete.esql.definition.equalToCaseInsensitiveDoc', {
// defaultMessage: 'Case insensitive equality',
// }),
// },
{
name: 'like',
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definition.likeDoc', {
defaultMessage: 'Filter data based on string patterns',
}),
},
{ name: 'not_like', description: '' },
{
name: 'rlike',
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definition.rlikeDoc', {
defaultMessage: 'Filter data based on string regular expressions',
}),
},
{ name: 'not_rlike', description: '' },
].map(({ name, description }) => {
const def: FunctionDefinition = {
type: 'builtin' as const,
ignoreAsSuggestion: /not/.test(name),
name,
description,
supportedCommands: ['eval', 'where', 'row', 'sort'],
supportedOptions: ['by'],
signatures: [
{
params: [
{ name: 'left', type: 'text' as const },
{ name: 'right', type: 'text' as const },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'text' as const },
{ name: 'right', type: 'keyword' as const },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'keyword' as const },
{ name: 'right', type: 'text' as const },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'keyword' as const },
{ name: 'right', type: 'keyword' as const },
],
returnType: 'boolean',
},
],
};

return def;
});

const inFunctions: FunctionDefinition[] = [
{
name: 'in',
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definition.inDoc', {
defaultMessage:
'Tests if the value an expression takes is contained in a list of other expressions',
}),
},
{ name: 'not_in', description: '' },
].map<FunctionDefinition>(({ name, description }) => ({
// set all arrays to type "any" for now
// this only applies to the "in" operator
// e.g. "foo" in ( "foo", "bar" )
//
// we did this because the "in" operator now supports
// mixed-type arrays like ( "1.2.3", versionVar )
// because of implicit casting.
//
// we need to revisit with more robust validation
type: 'builtin',
ignoreAsSuggestion: /not/.test(name),
name,
description,
supportedCommands: ['eval', 'where', 'row', 'sort'],
signatures: [
...ESQL_NUMBER_TYPES.map((type) => ({
params: [
{ name: 'left', type: type as FunctionParameterType },

{ name: 'right', type: 'any[]' as FunctionParameterType },
],
returnType: 'boolean' as FunctionReturnType,
})),
{
params: [
{ name: 'left', type: 'keyword' },
{ name: 'right', type: 'any[]' },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'text' },
{ name: 'right', type: 'any[]' },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'boolean' },
{ name: 'right', type: 'any[]' },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'date' },
{ name: 'right', type: 'any[]' },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'version' },
{ name: 'right', type: 'any[]' },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'ip' },
{ name: 'right', type: 'any[]' },
],
returnType: 'boolean',
},
],
}));

export const logicalOperators: FunctionDefinition[] = [
{
name: 'and',
Expand Down Expand Up @@ -681,10 +537,7 @@ const otherDefinitions: FunctionDefinition[] = [
];

export const builtinFunctions: FunctionDefinition[] = [
...mathFunctions,
...comparisonFunctions,
...likeFunctions,
...inFunctions,
...operatorsFunctionDefinitions,
...logicalOperators,
...nullFunctions,
...otherDefinitions,
Expand Down
Loading