Skip to content

Commit

Permalink
Update function definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Jun 10, 2024
1 parent 4fc13a4 commit dbf6706
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -4795,6 +4841,7 @@ export const evalFunctionDefinitions = [
nowDefinition,
piDefinition,
powDefinition,
repeatDefinition,
replaceDefinition,
rightDefinition,
roundDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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)', []);
});
});
});

Expand Down

0 comments on commit dbf6706

Please sign in to comment.