diff --git a/packages/kbn-esql-validation-autocomplete/scripts/generate_function_definitions.ts b/packages/kbn-esql-validation-autocomplete/scripts/generate_function_definitions.ts index 8462f9e2a050b..3a810cac3ad75 100644 --- a/packages/kbn-esql-validation-autocomplete/scripts/generate_function_definitions.ts +++ b/packages/kbn-esql-validation-autocomplete/scripts/generate_function_definitions.ts @@ -218,7 +218,7 @@ const functionEnrichments: Record> ], }, mv_sort: { - signatures: new Array(9).fill({ + signatures: new Array(10).fill({ params: [{}, { acceptedValues: ['asc', 'desc'] }], }), }, diff --git a/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.command.stats.test.ts b/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.command.stats.test.ts index 829c12f7dabba..5234e93c159e2 100644 --- a/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.command.stats.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.command.stats.test.ts @@ -150,6 +150,7 @@ describe('autocomplete.suggest', () => { ...getFieldNamesByType([ ...ESQL_COMMON_NUMERIC_TYPES, 'date', + 'date_nanos', 'boolean', 'ip', 'version', @@ -158,7 +159,16 @@ describe('autocomplete.suggest', () => { ]), ...getFunctionSignaturesByReturnType( 'stats', - [...ESQL_COMMON_NUMERIC_TYPES, 'date', 'boolean', 'ip', 'version', 'text', 'keyword'], + [ + ...ESQL_COMMON_NUMERIC_TYPES, + 'date', + 'boolean', + 'ip', + 'version', + 'text', + 'keyword', + 'date_nanos', + ], { scalar: true, } diff --git a/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.suggest.eval.test.ts b/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.suggest.eval.test.ts index aae715ee66749..e81e74427b721 100644 --- a/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.suggest.eval.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.suggest.eval.test.ts @@ -370,8 +370,12 @@ describe('autocomplete.suggest', () => { // // Test suggestions for each possible param, within each signature variation, for each function for (const fn of scalarFunctionDefinitions) { // skip this fn for the moment as it's quite hard to test - // Add match in the text when the autocomplete is ready https://github.com/elastic/kibana/issues/196995 - if (!['bucket', 'date_extract', 'date_diff', 'case', 'match', 'qstr'].includes(fn.name)) { + // Add match in the test when the autocomplete is ready https://github.com/elastic/kibana/issues/196995 + if ( + !['bucket', 'date_extract', 'date_diff', 'case', 'match', 'qstr', 'date_trunc'].includes( + fn.name + ) + ) { test(`${fn.name}`, async () => { const testedCases = new Set(); @@ -539,9 +543,9 @@ describe('autocomplete.suggest', () => { 'from a | eval var0=date_trunc(/)', [ ...getLiteralsByType('time_literal').map((t) => `${t}, `), - ...getFunctionSignaturesByReturnType('eval', 'time_duration', { scalar: true }).map( - (t) => `${t.text},` - ), + ...getFunctionSignaturesByReturnType('eval', ['time_duration', 'date_period'], { + scalar: true, + }).map((t) => `${t.text},`), ], { triggerCharacter: '(' } ); diff --git a/packages/kbn-esql-validation-autocomplete/src/definitions/generated/aggregation_functions.ts b/packages/kbn-esql-validation-autocomplete/src/definitions/generated/aggregation_functions.ts index 6a429f2288f94..37dfe8de5822f 100644 --- a/packages/kbn-esql-validation-autocomplete/src/definitions/generated/aggregation_functions.ts +++ b/packages/kbn-esql-validation-autocomplete/src/definitions/generated/aggregation_functions.ts @@ -216,7 +216,7 @@ const countDefinition: FunctionDefinition = { validate: undefined, examples: [ 'FROM employees\n| STATS COUNT(height)', - 'FROM employees \n| STATS count = COUNT(*) BY languages \n| SORT languages DESC', + 'FROM employees\n| STATS count = COUNT(*) BY languages\n| SORT languages DESC', 'ROW words="foo;bar;baz;qux;quux;foo"\n| STATS word_count = COUNT(SPLIT(words, ";"))', 'ROW n=1\n| WHERE n < 0\n| STATS COUNT(n)', 'ROW n=1\n| STATS COUNT(n > 0 OR NULL), COUNT(n < 0 OR NULL)', @@ -343,6 +343,61 @@ const countDistinctDefinition: FunctionDefinition = { ], returnType: 'long', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'long', + }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + { + name: 'precision', + type: 'integer', + optional: true, + }, + ], + returnType: 'long', + }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + { + name: 'precision', + type: 'long', + optional: true, + }, + ], + returnType: 'long', + }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + { + name: 'precision', + type: 'unsigned_long', + optional: true, + }, + ], + returnType: 'long', + }, { params: [ { @@ -769,6 +824,16 @@ const maxDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'date_nanos', + }, { params: [ { @@ -984,6 +1049,16 @@ const minDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'date_nanos', + }, { params: [ { @@ -1544,6 +1619,16 @@ const valuesDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'date_nanos', + }, { params: [ { diff --git a/packages/kbn-esql-validation-autocomplete/src/definitions/generated/scalar_functions.ts b/packages/kbn-esql-validation-autocomplete/src/definitions/generated/scalar_functions.ts index 257753d036aa7..095310766f79d 100644 --- a/packages/kbn-esql-validation-autocomplete/src/definitions/generated/scalar_functions.ts +++ b/packages/kbn-esql-validation-autocomplete/src/definitions/generated/scalar_functions.ts @@ -814,6 +814,22 @@ const coalesceDefinition: FunctionDefinition = { returnType: 'date', minParams: 1, }, + { + params: [ + { + name: 'first', + type: 'date_nanos', + optional: false, + }, + { + name: 'rest', + type: 'date_nanos', + optional: true, + }, + ], + returnType: 'date_nanos', + minParams: 1, + }, { params: [ { @@ -1546,6 +1562,21 @@ const dateTruncDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'interval', + type: 'date_period', + optional: false, + }, + { + name: 'date', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'date_nanos', + }, { params: [ { @@ -1561,6 +1592,21 @@ const dateTruncDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'interval', + type: 'time_duration', + optional: false, + }, + { + name: 'date', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'date_nanos', + }, ], supportedCommands: ['stats', 'inlinestats', 'metrics', 'eval', 'where', 'row', 'sort'], supportedOptions: ['by'], @@ -1876,6 +1922,22 @@ const greatestDefinition: FunctionDefinition = { returnType: 'date', minParams: 1, }, + { + params: [ + { + name: 'first', + type: 'date_nanos', + optional: false, + }, + { + name: 'rest', + type: 'date_nanos', + optional: true, + }, + ], + returnType: 'date_nanos', + minParams: 1, + }, { params: [ { @@ -2390,6 +2452,22 @@ const leastDefinition: FunctionDefinition = { returnType: 'date', minParams: 1, }, + { + params: [ + { + name: 'first', + type: 'date_nanos', + optional: false, + }, + { + name: 'rest', + type: 'date_nanos', + optional: true, + }, + ], + returnType: 'date_nanos', + minParams: 1, + }, { params: [ { @@ -3322,7 +3400,7 @@ const matchDefinition: FunctionDefinition = { supportedOptions: [], validate: undefined, examples: [ - 'from books \n| where match(author, "Faulkner")\n| keep book_no, author \n| sort book_no \n| limit 5;', + 'FROM books \n| WHERE MATCH(author, "Faulkner")\n| KEEP book_no, author \n| SORT book_no \n| LIMIT 5;', ], }; @@ -3728,6 +3806,16 @@ const mvCountDefinition: FunctionDefinition = { ], returnType: 'integer', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'integer', + }, { params: [ { @@ -3885,6 +3973,16 @@ const mvDedupeDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'date_nanos', + }, { params: [ { @@ -4033,6 +4131,16 @@ const mvFirstDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'date_nanos', + }, { params: [ { @@ -4191,6 +4299,16 @@ const mvLastDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'date_nanos', + }, { params: [ { @@ -4329,6 +4447,16 @@ const mvMaxDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'date_nanos', + }, { params: [ { @@ -4574,6 +4702,16 @@ const mvMinDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'date_nanos', + }, { params: [ { @@ -4948,6 +5086,26 @@ const mvSliceDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + { + name: 'start', + type: 'integer', + optional: false, + }, + { + name: 'end', + type: 'integer', + optional: true, + }, + ], + returnType: 'date_nanos', + }, { params: [ { @@ -5180,6 +5338,22 @@ const mvSortDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + { + name: 'order', + type: 'keyword', + optional: true, + acceptedValues: ['asc', 'desc'], + }, + ], + returnType: 'date_nanos', + }, { params: [ { @@ -5937,7 +6111,7 @@ const qstrDefinition: FunctionDefinition = { supportedOptions: [], validate: undefined, examples: [ - 'from books \n| where qstr("author: Faulkner")\n| keep book_no, author \n| sort book_no \n| limit 5;', + 'FROM books \n| WHERE QSTR("author: Faulkner")\n| KEEP book_no, author \n| SORT book_no \n| LIMIT 5;', ], }; @@ -7950,7 +8124,78 @@ const toDateNanosDefinition: FunctionDefinition = { }), preview: true, alias: undefined, - signatures: [], + signatures: [ + { + params: [ + { + name: 'field', + type: 'date', + optional: false, + }, + ], + returnType: 'date_nanos', + }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'date_nanos', + }, + { + params: [ + { + name: 'field', + type: 'double', + optional: false, + }, + ], + returnType: 'date_nanos', + }, + { + params: [ + { + name: 'field', + type: 'keyword', + optional: false, + }, + ], + returnType: 'date_nanos', + }, + { + params: [ + { + name: 'field', + type: 'long', + optional: false, + }, + ], + returnType: 'date_nanos', + }, + { + params: [ + { + name: 'field', + type: 'text', + optional: false, + }, + ], + returnType: 'date_nanos', + }, + { + params: [ + { + name: 'field', + type: 'unsigned_long', + optional: false, + }, + ], + returnType: 'date_nanos', + }, + ], supportedCommands: ['stats', 'inlinestats', 'metrics', 'eval', 'where', 'row', 'sort'], supportedOptions: ['by'], validate: undefined, @@ -8027,6 +8272,16 @@ const toDatetimeDefinition: FunctionDefinition = { ], returnType: 'date', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'date', + }, { params: [ { @@ -8600,6 +8855,16 @@ const toLongDefinition: FunctionDefinition = { ], returnType: 'long', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'long', + }, { params: [ { @@ -8813,6 +9078,16 @@ const toStringDefinition: FunctionDefinition = { ], returnType: 'keyword', }, + { + params: [ + { + name: 'field', + type: 'date_nanos', + optional: false, + }, + ], + returnType: 'keyword', + }, { params: [ { diff --git a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts index 9f497550219ee..cce417095471f 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts @@ -429,7 +429,6 @@ describe('validation logic', () => { [], ['Invalid option ["bogus"] for mv_sort. Supported options: ["asc", "desc"].'] ); - testErrorsAndWarnings(`row var = mv_sort(["a", "b"], "ASC")`, []); testErrorsAndWarnings(`row var = mv_sort(["a", "b"], "DESC")`, []); diff --git a/packages/kbn-language-documentation/src/sections/generated/scalar_functions.tsx b/packages/kbn-language-documentation/src/sections/generated/scalar_functions.tsx index 855dea656adac..77d7ef4621cd5 100644 --- a/packages/kbn-language-documentation/src/sections/generated/scalar_functions.tsx +++ b/packages/kbn-language-documentation/src/sections/generated/scalar_functions.tsx @@ -1204,11 +1204,11 @@ export const functions = { Performs a match query on the specified field. Returns true if the provided query matches the row. \`\`\` - from books - | where match(author, "Faulkner") - | keep book_no, author - | sort book_no - | limit 5; + FROM books + | WHERE MATCH(author, "Faulkner") + | KEEP book_no, author + | SORT book_no + | LIMIT 5; \`\`\` `, description: @@ -1920,11 +1920,11 @@ export const functions = { Performs a query string query. Returns true if the provided query string matches the row. \`\`\` - from books - | where qstr("author: Faulkner") - | keep book_no, author - | sort book_no - | limit 5; + FROM books + | WHERE QSTR("author: Faulkner") + | KEEP book_no, author + | SORT book_no + | LIMIT 5; \`\`\` `, description: