Skip to content

Commit f4652e2

Browse files
stratoulavadimkibana
authored andcommitted
[ES|QL] Supports TS agg functions (elastic#226539)
## Summary Closes elastic#220730 Supports of TS inner agg functions. 1. Retrieves the functions and the docs from elastic/elasticsearch#130290 2. Suggest them only when an agg is already selected and only if the source command is TS ![meow](https://github.com/user-attachments/assets/9143ff0d-c5ab-4e93-a802-3e535dbc5121) Atm you won't see any changes in the editor. You can test it though if you change the `src/platform/packages/shared/kbn-esql-validation-autocomplete/src/definitions/generated/time_series_agg_functions.ts` `ignoreAsSuggestion` flags to false. ### Checklist - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Vadim Kibana <[email protected]>
1 parent 05f6c9f commit f4652e2

File tree

18 files changed

+633
-22
lines changed

18 files changed

+633
-22
lines changed

src/platform/packages/private/kbn-language-documentation/scripts/generate_esql_docs.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ interface DocsSectionContent {
2020

2121
(function () {
2222
const pathToElasticsearch = process.argv[2];
23-
2423
if (!pathToElasticsearch) {
2524
throw new Error('Path to Elasticsearch must be provided as the first argument.');
2625
}
@@ -29,6 +28,10 @@ interface DocsSectionContent {
2928
const functionTypes = [
3029
{ fnType: 'scalar', outputFile: '../src/sections/generated/scalar_functions.tsx' },
3130
{ fnType: 'agg', outputFile: '../src/sections/generated/aggregation_functions.tsx' },
31+
{
32+
fnType: 'time_series_agg',
33+
outputFile: '../src/sections/generated/timeseries_aggregation_functions.tsx',
34+
},
3235
{ fnType: 'grouping', outputFile: '../src/sections/generated/grouping_functions.tsx' },
3336
{ fnType: 'operator', outputFile: '../src/sections/generated/operators.tsx' },
3437
];

src/platform/packages/private/kbn-language-documentation/src/sections/esql_documentation_sections.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,5 +795,6 @@ Refer to **Operators** for an overview of the supported operators.
795795

796796
export { functions as scalarFunctions } from './generated/scalar_functions';
797797
export { functions as aggregationFunctions } from './generated/aggregation_functions';
798+
export { functions as timeseriesAggregationFunctions } from './generated/timeseries_aggregation_functions';
798799
export { functions as groupingFunctions } from './generated/grouping_functions';
799800
export { functions as operators } from './generated/operators';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import { i18n } from '@kbn/i18n';
11+
12+
// DO NOT RENAME!
13+
export const functions = {
14+
label: i18n.translate('languageDocumentation.documentationESQL.timeseriesAggregationFunctions', {
15+
defaultMessage: 'Timeseries aggregation functions',
16+
}),
17+
description: i18n.translate(
18+
'languageDocumentation.documentationESQL.timeseriesAggregationFunctionsDocumentationESQLDescription',
19+
{
20+
defaultMessage: `These functions can by used with STATS ...BY when a TS command is used:`,
21+
}
22+
),
23+
// items are managed by scripts/generate_esql_docs.ts
24+
items: [],
25+
};

src/platform/packages/shared/kbn-esql-ast/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export type {
1111
ESQLAst,
1212
ESQLAstItem,
1313
ESQLAstCommand,
14-
ESQLAstTimeseriesCommand,
1514
ESQLAstJoinCommand,
1615
ESQLCommand,
1716
ESQLCommandOption,

src/platform/packages/shared/kbn-esql-ast/scripts/generate_function_definitions.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ function getFunctionDefinition(ESFunctionDefinition: Record<string, any>): Funct
4949
if (FULL_TEXT_SEARCH_FUNCTIONS.includes(ESFunctionDefinition.name)) {
5050
locationsAvailable = [Location.WHERE, Location.STATS_WHERE];
5151
}
52+
53+
if (ESFunctionDefinition.type === FunctionDefinitionTypes.TIME_SERIES_AGG) {
54+
locationsAvailable = [Location.STATS_TIMESERIES];
55+
}
5256
const ret = {
5357
type: ESFunctionDefinition.type,
5458
name: ESFunctionDefinition.name,
@@ -356,7 +360,7 @@ ${
356360
.join('\n\n');
357361

358362
const fileContents = `${fileHeader}${functionDefinitionsString}
359-
export const ${functionsType}FunctionDefinitions = [${functionDefinitions
363+
export const ${_.camelCase(functionsType)}FunctionDefinitions = [${functionDefinitions
360364
.map(({ name }) => getDefinitionName(name))
361365
.join(',\n')}];`;
362366

@@ -418,6 +422,7 @@ export const esqlFunctionNames = ${JSON.stringify(functionNames, null, 2)};
418422

419423
const scalarFunctionDefinitions: FunctionDefinition[] = [];
420424
const aggFunctionDefinitions: FunctionDefinition[] = [];
425+
const timeSeriesFunctionDefinitions: FunctionDefinition[] = [];
421426
const operatorDefinitions: FunctionDefinition[] = [];
422427
const groupingFunctionDefinitions: FunctionDefinition[] = [];
423428

@@ -449,6 +454,8 @@ export const esqlFunctionNames = ${JSON.stringify(functionNames, null, 2)};
449454
aggFunctionDefinitions.push(functionDefinition);
450455
} else if (functionDefinition.type === FunctionDefinitionTypes.GROUPING) {
451456
groupingFunctionDefinitions.push(functionDefinition);
457+
} else if (functionDefinition.type === FunctionDefinitionTypes.TIME_SERIES_AGG) {
458+
timeSeriesFunctionDefinitions.push(functionDefinition);
452459
}
453460
}
454461

@@ -462,6 +469,13 @@ export const esqlFunctionNames = ${JSON.stringify(functionNames, null, 2)};
462469
join(__dirname, '../src/definitions/generated/aggregation_functions.ts'),
463470
printGeneratedFunctionsFile(aggFunctionDefinitions, FunctionDefinitionTypes.AGG)
464471
);
472+
await writeFile(
473+
join(__dirname, '../src/definitions/generated/time_series_agg_functions.ts'),
474+
printGeneratedFunctionsFile(
475+
timeSeriesFunctionDefinitions,
476+
FunctionDefinitionTypes.TIME_SERIES_AGG
477+
)
478+
);
465479
await writeFile(
466480
join(__dirname, '../src/definitions/generated/operators.ts'),
467481
printGeneratedFunctionsFile(

src/platform/packages/shared/kbn-esql-ast/src/commands_registry/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ export enum Location {
182182
*/
183183
STATS_WHERE = 'stats_where',
184184

185+
/**
186+
* WHEN TS is used as a source command, inner STATS functions
187+
*/
188+
STATS_TIMESERIES = 'stats_timeseries',
189+
185190
/**
186191
* Top-level ENRICH command
187192
*/

0 commit comments

Comments
 (0)