Skip to content

Commit

Permalink
[ES|QL] Marks tech preview functions in the editor (elastic#199631)
Browse files Browse the repository at this point in the history
## Summary

Closes elastic#194062

Indicates tech preview functions in the editor.

![image
(62)](https://github.com/user-attachments/assets/a6d2b1e8-f7c7-4bee-8a9f-3c9d5026c79e)
  • Loading branch information
stratoula authored Nov 12, 2024
1 parent e87fbd8 commit dbc9e31
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ function getFunctionDefinition(ESFunctionDefinition: Record<string, any>): Funct
description: ESFunctionDefinition.description,
alias: aliasTable[ESFunctionDefinition.name],
ignoreAsSuggestion: ESFunctionDefinition.snapshot_only,
preview: ESFunctionDefinition.preview,
signatures: _.uniqBy(
ESFunctionDefinition.signatures.map((signature: any) => ({
...signature,
Expand Down Expand Up @@ -334,6 +335,7 @@ function printGeneratedFunctionsFile(
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.${name}', { defaultMessage: ${JSON.stringify(
removeAsciiDocInternalCrossReferences(removeInlineAsciiDocLinks(description), functionNames)
)} }),${functionDefinition.ignoreAsSuggestion ? 'ignoreAsSuggestion: true,\n' : ''}
preview: ${functionDefinition.preview || 'false'},
alias: ${alias ? `['${alias.join("', '")}']` : 'undefined'},
signatures: ${JSON.stringify(signatures, null, 2)},
supportedCommands: ${JSON.stringify(functionDefinition.supportedCommands)},
Expand Down Expand Up @@ -393,6 +395,9 @@ import { isLiteralItem } from '../../shared/helpers';`

(async function main() {
const pathToElasticsearch = process.argv[2];
if (!pathToElasticsearch) {
throw new Error('Path to Elasticsearch is required');
}

const ESFunctionDefinitionsDirectory = join(
pathToElasticsearch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ import { isNumericType } from '../shared/esql_types';
import { getTestFunctions } from '../shared/test_functions';
import { builtinFunctions } from '../definitions/builtin';

const techPreviewLabel = i18n.translate(
'kbn-esql-validation-autocomplete.esql.autocomplete.techPreviewLabel',
{
defaultMessage: `Technical Preview`,
}
);

const allFunctions = memoize(
() =>
aggregationFunctionDefinitions
Expand Down Expand Up @@ -60,13 +67,17 @@ function getSafeInsertSourceText(text: string) {
}

export function getFunctionSuggestion(fn: FunctionDefinition): SuggestionRawDefinition {
let detail = fn.description;
if (fn.preview) {
detail = `[${techPreviewLabel}] ${detail}`;
}
const fullSignatures = getFunctionSignatures(fn, { capitalize: true, withTypes: true });
return {
label: fn.name.toUpperCase(),
text: `${fn.name.toUpperCase()}($0)`,
asSnippet: true,
kind: 'Function',
detail: fn.description,
detail,
documentation: {
value: buildFunctionDocumentation(fullSignatures, fn.examples),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const avgDefinition: FunctionDefinition = {
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.avg', {
defaultMessage: 'The average of a numeric field.',
}),
preview: false,
alias: undefined,
signatures: [
{
Expand Down Expand Up @@ -85,6 +86,7 @@ const countDefinition: FunctionDefinition = {
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.count', {
defaultMessage: 'Returns the total number (count) of input values.',
}),
preview: false,
alias: undefined,
signatures: [
{
Expand Down Expand Up @@ -228,6 +230,7 @@ const countDistinctDefinition: FunctionDefinition = {
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.count_distinct', {
defaultMessage: 'Returns the approximate number of distinct values.',
}),
preview: false,
alias: undefined,
signatures: [
{
Expand Down Expand Up @@ -743,6 +746,7 @@ const maxDefinition: FunctionDefinition = {
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.max', {
defaultMessage: 'The maximum value of a field.',
}),
preview: false,
alias: undefined,
signatures: [
{
Expand Down Expand Up @@ -853,6 +857,7 @@ const medianDefinition: FunctionDefinition = {
defaultMessage:
'The value that is greater than half of all values and less than half of all values, also known as the 50% `PERCENTILE`.',
}),
preview: false,
alias: undefined,
signatures: [
{
Expand Down Expand Up @@ -906,6 +911,7 @@ const medianAbsoluteDeviationDefinition: FunctionDefinition = {
"Returns the median absolute deviation, a measure of variability. It is a robust statistic, meaning that it is useful for describing data that may have outliers, or may not be normally distributed. For such data it can be more descriptive than standard deviation.\n\nIt is calculated as the median of each data point's deviation from the median of the entire sample. That is, for a random variable `X`, the median absolute deviation is `median(|median(X) - X|)`.",
}
),
preview: false,
alias: undefined,
signatures: [
{
Expand Down Expand Up @@ -955,6 +961,7 @@ const minDefinition: FunctionDefinition = {
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.min', {
defaultMessage: 'The minimum value of a field.',
}),
preview: false,
alias: undefined,
signatures: [
{
Expand Down Expand Up @@ -1065,6 +1072,7 @@ const percentileDefinition: FunctionDefinition = {
defaultMessage:
'Returns the value at which a certain percentage of observed values occur. For example, the 95th percentile is the value which is greater than 95% of the observed values and the 50th percentile is the `MEDIAN`.',
}),
preview: false,
alias: undefined,
signatures: [
{
Expand Down Expand Up @@ -1228,6 +1236,7 @@ const stCentroidAggDefinition: FunctionDefinition = {
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.st_centroid_agg', {
defaultMessage: 'Calculate the spatial centroid over a field with spatial point geometry type.',
}),
preview: false,
alias: undefined,
signatures: [
{
Expand Down Expand Up @@ -1264,6 +1273,7 @@ const sumDefinition: FunctionDefinition = {
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.sum', {
defaultMessage: 'The sum of a numeric expression.',
}),
preview: false,
alias: undefined,
signatures: [
{
Expand Down Expand Up @@ -1313,6 +1323,7 @@ const topDefinition: FunctionDefinition = {
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.top', {
defaultMessage: 'Collects the top values for a field. Includes repeated values.',
}),
preview: false,
alias: undefined,
signatures: [
{
Expand Down Expand Up @@ -1510,6 +1521,7 @@ const valuesDefinition: FunctionDefinition = {
defaultMessage:
"Returns all values in a group as a multivalued field. The order of the returned values isn't guaranteed. If you need the values returned in order use esql-mv_sort.",
}),
preview: true,
alias: undefined,
signatures: [
{
Expand Down Expand Up @@ -1618,6 +1630,7 @@ const weightedAvgDefinition: FunctionDefinition = {
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.weighted_avg', {
defaultMessage: 'The weighted average of a numeric expression.',
}),
preview: false,
alias: undefined,
signatures: [
{
Expand Down
Loading

0 comments on commit dbc9e31

Please sign in to comment.