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 @@ -559,7 +559,10 @@ describe('autocomplete', () => {
}

describe('sort', () => {
testSuggestions('from a | sort ', getFieldNamesByType('any'));
testSuggestions('from a | sort ', [
...getFieldNamesByType('any'),
...getFunctionSignaturesByReturnType('sort', 'any', { evalMath: true }),
]);
testSuggestions('from a | sort stringField ', ['asc', 'desc', ',', '|']);
testSuggestions('from a | sort stringField desc ', ['nulls first', 'nulls last', ',', '|']);
// @TODO: improve here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,11 @@ async function getExpressionSuggestionsByType(
option?.name,
getFieldsByType,
{
functions: canHaveAssignments,
// TODO instead of relying on canHaveAssignments and other command name checks
// we should have a more generic way to determine if a command can have functions.
// I think it comes down to the definition of 'column' since 'any' should always
// include functions.
functions: canHaveAssignments || command.name === 'sort',
fields: !argDef.constantOnly,
variables: anyVariables,
literals: argDef.constantOnly,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function createMathDefinition(
type: 'builtin',
name,
description,
supportedCommands: ['eval', 'where', 'row', 'stats'],
supportedCommands: ['eval', 'where', 'row', 'stats', 'sort'],
supportedOptions: ['by'],
signatures: types.map((type) => {
if (Array.isArray(type)) {
Expand Down Expand Up @@ -59,7 +59,7 @@ function createComparisonDefinition(
type: 'builtin' as const,
name,
description,
supportedCommands: ['eval', 'where', 'row'],
supportedCommands: ['eval', 'where', 'row', 'sort'],
supportedOptions: ['by'],
validate,
signatures: [
Expand Down Expand Up @@ -296,7 +296,7 @@ export const builtinFunctions: FunctionDefinition[] = [
ignoreAsSuggestion: /not/.test(name),
name,
description,
supportedCommands: ['eval', 'where', 'row'],
supportedCommands: ['eval', 'where', 'row', 'sort'],
supportedOptions: ['by'],
signatures: [
{
Expand All @@ -322,7 +322,7 @@ export const builtinFunctions: FunctionDefinition[] = [
ignoreAsSuggestion: /not/.test(name),
name,
description,
supportedCommands: ['eval', 'where', 'row'],
supportedCommands: ['eval', 'where', 'row', 'sort'],
signatures: [
{
params: [
Expand Down Expand Up @@ -371,7 +371,7 @@ export const builtinFunctions: FunctionDefinition[] = [
type: 'builtin' as const,
name,
description,
supportedCommands: ['eval', 'where', 'row'],
supportedCommands: ['eval', 'where', 'row', 'sort'],
supportedOptions: ['by'],
signatures: [
{
Expand Down Expand Up @@ -410,7 +410,7 @@ export const builtinFunctions: FunctionDefinition[] = [
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definition.notDoc', {
defaultMessage: 'Not',
}),
supportedCommands: ['eval', 'where', 'row'],
supportedCommands: ['eval', 'where', 'row', 'sort'],
supportedOptions: ['by'],
signatures: [
{
Expand All @@ -436,7 +436,7 @@ export const builtinFunctions: FunctionDefinition[] = [
type: 'builtin',
name,
description,
supportedCommands: ['eval', 'where', 'row'],
supportedCommands: ['eval', 'where', 'row', 'sort'],
signatures: [
{
params: [{ name: 'left', type: 'any' }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,14 @@ export const commandDefinitions: CommandDefinition[] = [
'… | sort a desc, b nulls last, c asc nulls first',
'… | sort b nulls last',
'… | sort c asc nulls first',
'… | sort a - abs(b)',
],
options: [],
modes: [],
signature: {
multipleParams: true,
params: [
{ name: 'column', type: 'column' },
{ name: 'expression', type: 'any' },
{ name: 'direction', type: 'string', optional: true, values: ['asc', 'desc'] },
{ name: 'nulls', type: 'string', optional: true, values: ['nulls first', 'nulls last'] },
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ export const evalFunctionsDefinitions: FunctionDefinition[] = [
.sort(({ name: a }, { name: b }) => a.localeCompare(b))
.map((def) => ({
...def,
supportedCommands: ['stats', 'eval', 'where', 'row'],
supportedCommands: ['stats', 'eval', 'where', 'row', 'sort'],
supportedOptions: ['by'],
type: 'eval',
}));
Loading