diff --git a/packages/kbn-esql-validation-autocomplete/src/definitions/functions.ts b/packages/kbn-esql-validation-autocomplete/src/definitions/functions.ts index 930e8b0c30837..2eb40e5821a19 100644 --- a/packages/kbn-esql-validation-autocomplete/src/definitions/functions.ts +++ b/packages/kbn-esql-validation-autocomplete/src/definitions/functions.ts @@ -2449,6 +2449,21 @@ const mvZipDefinition: FunctionDefinition = { }), alias: undefined, signatures: [ + { + params: [ + { + name: 'string1', + type: 'string', + optional: false, + }, + { + name: 'string2', + type: 'string', + optional: false, + }, + ], + returnType: 'string', + }, { params: [ { @@ -2549,6 +2564,37 @@ const powDefinition: FunctionDefinition = { ], }; +const repeatDefinition: FunctionDefinition = { + type: 'eval', + name: 'repeat', + description: i18n.translate('kbn-esql-validation-autocomplete.esql.definitions.repeat', { + defaultMessage: + 'Returns a string constructed by concatenating `string` with itself the specified `number` of times.', + }), + alias: undefined, + signatures: [ + { + params: [ + { + name: 'string', + type: 'string', + optional: false, + }, + { + name: 'number', + type: 'number', + optional: false, + }, + ], + returnType: 'string', + }, + ], + supportedCommands: ['stats', 'eval', 'where', 'row', 'sort'], + supportedOptions: ['by'], + validate: undefined, + examples: ['ROW a = "Hello!"\n| EVAL triple_a = REPEAT(a, 3);'], +}; + const replaceDefinition: FunctionDefinition = { type: 'eval', name: 'replace', @@ -4795,6 +4841,7 @@ export const evalFunctionDefinitions = [ nowDefinition, piDefinition, powDefinition, + repeatDefinition, replaceDefinition, rightDefinition, roundDefinition, 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 88e84aa66f2c8..5bf73462202d7 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts @@ -5077,6 +5077,33 @@ describe('validation logic', () => { ); testErrorsAndWarnings('from a_index | eval mv_zip(null, null, null)', []); testErrorsAndWarnings('row nullVar = null | eval mv_zip(nullVar, nullVar, nullVar)', []); + testErrorsAndWarnings('row var = mv_zip(to_string(true), to_string(true))', []); + testErrorsAndWarnings( + 'from a_index | where length(mv_zip(stringField, stringField)) > 0', + [] + ); + + testErrorsAndWarnings( + 'from a_index | where length(mv_zip(booleanField, booleanField)) > 0', + [ + 'Argument of [mv_zip] must be [string], found value [booleanField] type [boolean]', + 'Argument of [mv_zip] must be [string], found value [booleanField] type [boolean]', + ] + ); + + testErrorsAndWarnings('from a_index | eval var = mv_zip(stringField, stringField)', []); + + testErrorsAndWarnings( + 'from a_index | eval var = mv_zip(to_string(booleanField), to_string(booleanField))', + [] + ); + + testErrorsAndWarnings('from a_index | eval mv_zip(booleanField, booleanField)', [ + 'Argument of [mv_zip] must be [string], found value [booleanField] type [boolean]', + 'Argument of [mv_zip] must be [string], found value [booleanField] type [boolean]', + ]); + + testErrorsAndWarnings('from a_index | sort mv_zip(stringField, stringField)', []); }); describe('now', () => { @@ -10334,6 +10361,51 @@ describe('validation logic', () => { testErrorsAndWarnings('from a_index | eval mv_append(null, null)', []); testErrorsAndWarnings('row nullVar = null | eval mv_append(nullVar, nullVar)', []); }); + + describe('repeat', () => { + testErrorsAndWarnings('row var = repeat("a", 5)', []); + testErrorsAndWarnings('row repeat("a", 5)', []); + testErrorsAndWarnings('row var = repeat(to_string(true), to_integer(true))', []); + + testErrorsAndWarnings('row var = repeat(true, true)', [ + 'Argument of [repeat] must be [string], found value [true] type [boolean]', + 'Argument of [repeat] must be [number], found value [true] type [boolean]', + ]); + + testErrorsAndWarnings( + 'from a_index | where length(repeat(stringField, numberField)) > 0', + [] + ); + + testErrorsAndWarnings( + 'from a_index | where length(repeat(booleanField, booleanField)) > 0', + [ + 'Argument of [repeat] must be [string], found value [booleanField] type [boolean]', + 'Argument of [repeat] must be [number], found value [booleanField] type [boolean]', + ] + ); + + testErrorsAndWarnings('from a_index | eval var = repeat(stringField, numberField)', []); + testErrorsAndWarnings('from a_index | eval repeat(stringField, numberField)', []); + + testErrorsAndWarnings( + 'from a_index | eval var = repeat(to_string(booleanField), to_integer(booleanField))', + [] + ); + + testErrorsAndWarnings('from a_index | eval repeat(booleanField, booleanField)', [ + 'Argument of [repeat] must be [string], found value [booleanField] type [boolean]', + 'Argument of [repeat] must be [number], found value [booleanField] type [boolean]', + ]); + + testErrorsAndWarnings('from a_index | eval repeat(stringField, numberField, extraArg)', [ + 'Error: [repeat] function expects exactly 2 arguments, got 3.', + ]); + + testErrorsAndWarnings('from a_index | sort repeat(stringField, numberField)', []); + testErrorsAndWarnings('from a_index | eval repeat(null, null)', []); + testErrorsAndWarnings('row nullVar = null | eval repeat(nullVar, nullVar)', []); + }); }); });