Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0e937a9
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 6, 2025
7ffbf4c
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 10, 2025
b426318
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 13, 2025
511ccaa
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 14, 2025
2d71300
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 18, 2025
0076de9
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 21, 2025
2898ce1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 24, 2025
ace0009
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 3, 2025
6cdd8c1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 4, 2025
98616e9
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 6, 2025
64e40fd
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 7, 2025
1e3f8d1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 11, 2025
afd5630
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 13, 2025
31c6cb3
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 18, 2025
08f4b1b
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 18, 2025
0c11f55
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 20, 2025
de2bc7a
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 21, 2025
828d142
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 25, 2025
34bd1ef
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 1, 2025
f0070c6
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 3, 2025
16a27c7
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 3, 2025
cde697e
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 8, 2025
8b66178
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 10, 2025
3555b0c
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 14, 2025
57a5f4a
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 16, 2025
420eb2b
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 29, 2025
8e5e4a8
Merge branch 'main' of github.com:elastic/kibana
drewdaemon May 5, 2025
141765f
Merge branch 'main' of github.com:elastic/kibana
drewdaemon May 21, 2025
cdf4d20
Merge branch 'main' of github.com:elastic/kibana
drewdaemon May 23, 2025
d177eb1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon May 28, 2025
0ef65f9
Merge branch 'main' of github.com:elastic/kibana into fix-coalesce
drewdaemon Jun 3, 2025
609f6fb
add validation test
drewdaemon Jun 3, 2025
d88ed08
Add autocomplete test
drewdaemon Jun 3, 2025
c685106
add function autocomplete tests
drewdaemon Jun 3, 2025
9722857
loosen validation
drewdaemon Jun 3, 2025
46c0adc
remove autocomplete test
drewdaemon Jun 4, 2025
d8f6c04
Merge branch 'main' into fix-coalesce
stratoula Jun 4, 2025
93e1dc6
use a helper function
drewdaemon Jun 4, 2025
e493832
Merge branch 'fix-coalesce' of github.com:drewdaemon/kibana into fix-…
drewdaemon Jun 4, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ function doesLiteralMatchParameterType(argType: FunctionParameterType, item: ESQ
return true;
}

if (bothStringTypes(argType, item.literalType)) {
// all functions accept keyword literals for text parameters
return true;
}

if (item.literalType === 'null') {
// all parameters accept null, but this is not yet reflected
// in our function definitions so we let it through here
Expand Down Expand Up @@ -443,6 +448,18 @@ export function isValidLiteralOption(arg: ESQLLiteral, argDef: FunctionParameter
);
}

/**
* Checks if both types are string types.
*
* Functions in ES|QL accept `text` and `keyword` types interchangeably.
* @param type1
* @param type2
* @returns
*/
function bothStringTypes(type1: string, type2: string): boolean {
return (type1 === 'text' || type1 === 'keyword') && (type2 === 'text' || type2 === 'keyword');
}

/**
* Checks if an AST function argument is of the correct type
* given the definition.
Expand All @@ -468,7 +485,10 @@ export function checkFunctionArgMatchesDefinition(
if (isSupportedFunction(arg.name, parentCommand).supported) {
const fnDef = buildFunctionLookup().get(arg.name)!;
return fnDef.signatures.some(
(signature) => signature.returnType === 'unknown' || argType === signature.returnType
(signature) =>
signature.returnType === 'unknown' ||
argType === signature.returnType ||
bothStringTypes(argType, signature.returnType)
);
}
}
Expand All @@ -485,7 +505,9 @@ export function checkFunctionArgMatchesDefinition(
? validHit.type
: [validHit.type];

return wrappedTypes.some((ct) => ct === argType || ct === 'null' || ct === 'unknown');
return wrappedTypes.some(
(ct) => ct === argType || bothStringTypes(ct, argType) || ct === 'null' || ct === 'unknown'
);
}
if (arg.type === 'inlineCast') {
const lowerArgType = argType?.toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,60 @@ describe('function validation', () => {
await expectErrors('FROM a_index | EVAL TEST("2024-09-09", "2024-09-09")', []);
});

it('treats text and keyword as interchangeable', async () => {
setTestFunctions([
{
name: 'accepts_text',
type: FunctionDefinitionTypes.SCALAR,
description: '',
locationsAvailable: [Location.EVAL],
signatures: [
{
params: [{ name: 'arg1', type: 'text' }],
returnType: 'keyword',
},
],
},
{
name: 'accepts_keyword',
type: FunctionDefinitionTypes.SCALAR,
description: '',
locationsAvailable: [Location.EVAL],
signatures: [
{
params: [{ name: 'arg1', type: 'keyword' }],
returnType: 'keyword',
},
],
},
{
name: 'returns_keyword',
type: FunctionDefinitionTypes.SCALAR,
description: '',
locationsAvailable: [Location.EVAL],
signatures: [
{
params: [],
returnType: 'keyword',
},
],
},
]);

const { expectErrors } = await setup();

// literals — all string literals are keywords
await expectErrors('FROM a_index | EVAL ACCEPTS_TEXT("keyword literal")', []);

// fields
await expectErrors('FROM a_index | EVAL ACCEPTS_KEYWORD(textField)', []);
await expectErrors('FROM a_index | EVAL ACCEPTS_TEXT(keywordField)', []);

// functions
// no need to test a function that returns text, because they no longer exist: https://github.com/elastic/elasticsearch/pull/114334
await expectErrors('FROM a_index | EVAL ACCEPTS_TEXT(RETURNS_KEYWORD())', []);
});

it('enforces constant-only parameters', async () => {
setTestFunctions([
{
Expand Down