[ES|QL] remove Kibana-side overwrites for mv_dedupe and coalesce (#185901)

With the resolution of
https://github.com/elastic/elasticsearch/issues/108982, we can use the
Elasticsearch definitions for `mv_dedupe` and `coalesce`!

We have also had a couple instances lately of people not noticing the
"auto-generated" warning at the top of the function definitions file. I
have sprinkled warnings throughout so that it's more clear that any
manual changes will be wiped out.
This commit is contained in:
Drew Tate 2024-06-11 08:55:17 -06:00 committed by GitHub
parent da4673ea62
commit a75231ed53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 472 additions and 387 deletions

View file

@ -11,7 +11,7 @@ import { writeFile } from 'fs/promises';
import { join } from 'path';
import _ from 'lodash';
import type { RecursivePartial } from '@kbn/utility-types';
import { FunctionDefinition, supportedFieldTypes } from '../src/definitions/types';
import { FunctionDefinition } from '../src/definitions/types';
const aliasTable: Record<string, string[]> = {
to_version: ['to_ver'],
@ -31,7 +31,7 @@ const evalSupportedCommandsAndOptions = {
// coalesce can be removed when a test is added for version type
// (https://github.com/elastic/elasticsearch/pull/109032#issuecomment-2150033350)
const excludedFunctions = new Set(['bucket', 'case', 'coalesce']);
const excludedFunctions = new Set(['bucket', 'case']);
const extraFunctions: FunctionDefinition[] = [
{
@ -54,48 +54,6 @@ const extraFunctions: FunctionDefinition[] = [
`from index | eval type = case(languages <= 1, "monolingual", languages <= 2, "bilingual", "polyglot")`,
],
},
{
type: 'eval',
name: 'coalesce',
description:
'Returns the first of its arguments that is not null. If all arguments are null, it returns `null`.',
alias: undefined,
signatures: supportedFieldTypes
.map<FunctionDefinition['signatures']>((type) => [
{
params: [
{
name: 'first',
type,
optional: false,
},
],
returnType: type,
minParams: 1,
},
{
params: [
{
name: 'first',
type,
optional: false,
},
{
name: 'rest',
type,
optional: true,
},
],
returnType: type,
minParams: 1,
},
])
.flat(),
supportedCommands: ['stats', 'eval', 'where', 'row', 'sort'],
supportedOptions: ['by'],
validate: undefined,
examples: ['ROW a=null, b="b"\n| EVAL COALESCE(a, b)'],
},
];
const elasticsearchToKibanaType = (elasticsearchType: string) => {
@ -257,19 +215,6 @@ const functionEnrichments: Record<string, RecursivePartial<FunctionDefinition>>
params: [{}, { literalOptions: ['asc', 'desc'] }],
}),
},
// can be removed when https://github.com/elastic/elasticsearch/issues/108982 is complete
mv_dedupe: {
signatures: supportedFieldTypes.map<FunctionDefinition['signatures'][number]>((type) => ({
params: [
{
name: 'field',
type,
optional: false,
},
],
returnType: type,
})),
},
};
/**
@ -356,7 +301,8 @@ function printGeneratedFunctionsFile(functionDefinitions: FunctionDefinition[])
) => {
const { type, name, description, alias, signatures } = functionDefinition;
return `const ${getDefinitionName(name)}: FunctionDefinition = {
return `// Do not edit this manually... generated by scripts/generate_function_definitions.ts
const ${getDefinitionName(name)}: FunctionDefinition = {
type: '${type}',
name: '${name}',
description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.${name}', { defaultMessage: ${JSON.stringify(
@ -371,7 +317,7 @@ function printGeneratedFunctionsFile(functionDefinitions: FunctionDefinition[])
}`;
};
const fileHeader = `// NOTE: This file is generated by the generate_function_definitions.js script
const fileHeader = `// NOTE: This file is generated by the generate_function_definitions.ts script
// Do not edit it manually
import type { ESQLFunction } from '@kbn/esql-ast';

View file

@ -10521,6 +10521,11 @@
"error": [],
"warning": []
},
{
"query": "from a_index | sort coalesce(booleanField)",
"error": [],
"warning": []
},
{
"query": "row var = concat(\"a\", \"a\")",
"error": [],
@ -15976,6 +15981,47 @@
"error": [],
"warning": []
},
{
"query": "row var = mv_zip(to_string(true), to_string(true))",
"error": [],
"warning": []
},
{
"query": "from a_index | where length(mv_zip(stringField, stringField)) > 0",
"error": [],
"warning": []
},
{
"query": "from a_index | where length(mv_zip(booleanField, booleanField)) > 0",
"error": [
"Argument of [mv_zip] must be [string], found value [booleanField] type [boolean]",
"Argument of [mv_zip] must be [string], found value [booleanField] type [boolean]"
],
"warning": []
},
{
"query": "from a_index | eval var = mv_zip(stringField, stringField)",
"error": [],
"warning": []
},
{
"query": "from a_index | eval var = mv_zip(to_string(booleanField), to_string(booleanField))",
"error": [],
"warning": []
},
{
"query": "from a_index | eval mv_zip(booleanField, booleanField)",
"error": [
"Argument of [mv_zip] must be [string], found value [booleanField] type [boolean]",
"Argument of [mv_zip] must be [string], found value [booleanField] type [boolean]"
],
"warning": []
},
{
"query": "from a_index | sort mv_zip(stringField, stringField)",
"error": [],
"warning": []
},
{
"query": "row var = now()",
"error": [],
@ -25644,6 +25690,87 @@
"query": "row nullVar = null | eval mv_append(nullVar, nullVar)",
"error": [],
"warning": []
},
{
"query": "row var = repeat(\"a\", 5)",
"error": [],
"warning": []
},
{
"query": "row repeat(\"a\", 5)",
"error": [],
"warning": []
},
{
"query": "row var = repeat(to_string(true), to_integer(true))",
"error": [],
"warning": []
},
{
"query": "row var = repeat(true, true)",
"error": [
"Argument of [repeat] must be [string], found value [true] type [boolean]",
"Argument of [repeat] must be [number], found value [true] type [boolean]"
],
"warning": []
},
{
"query": "from a_index | where length(repeat(stringField, numberField)) > 0",
"error": [],
"warning": []
},
{
"query": "from a_index | where length(repeat(booleanField, booleanField)) > 0",
"error": [
"Argument of [repeat] must be [string], found value [booleanField] type [boolean]",
"Argument of [repeat] must be [number], found value [booleanField] type [boolean]"
],
"warning": []
},
{
"query": "from a_index | eval var = repeat(stringField, numberField)",
"error": [],
"warning": []
},
{
"query": "from a_index | eval repeat(stringField, numberField)",
"error": [],
"warning": []
},
{
"query": "from a_index | eval var = repeat(to_string(booleanField), to_integer(booleanField))",
"error": [],
"warning": []
},
{
"query": "from a_index | eval repeat(booleanField, booleanField)",
"error": [
"Argument of [repeat] must be [string], found value [booleanField] type [boolean]",
"Argument of [repeat] must be [number], found value [booleanField] type [boolean]"
],
"warning": []
},
{
"query": "from a_index | eval repeat(stringField, numberField, extraArg)",
"error": [
"Error: [repeat] function expects exactly 2 arguments, got 3."
],
"warning": []
},
{
"query": "from a_index | sort repeat(stringField, numberField)",
"error": [],
"warning": []
},
{
"query": "from a_index | eval repeat(null, null)",
"error": [],
"warning": []
},
{
"query": "row nullVar = null | eval repeat(nullVar, nullVar)",
"error": [],
"warning": []
}
]
}

View file

@ -2690,6 +2690,7 @@ describe('validation logic', () => {
testErrorsAndWarnings('from a_index | sort coalesce(numberField)', []);
testErrorsAndWarnings('from a_index | eval coalesce(null)', []);
testErrorsAndWarnings('row nullVar = null | eval coalesce(nullVar)', []);
testErrorsAndWarnings('from a_index | sort coalesce(booleanField)', []);
});
describe('concat', () => {