Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ES|QL] Fixes inline casting wrong validation #196489

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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 @@ -46,7 +46,7 @@ import {
} from '../definitions/types';
import type { ESQLRealField, ESQLVariable, ReferenceMaps } from '../validation/types';
import { removeMarkerArgFromArgsList } from './context';
import { isNumericDecimalType } from './esql_types';
import { compareTypesWithLiterals, isNumericDecimalType } from './esql_types';
import type { ReasonTypes } from './types';
import { DOUBLE_TICKS_REGEX, EDITOR_MARKER, SINGLE_BACKTICK } from './constants';
import type { EditorContext } from '../autocomplete/types';
Expand Down Expand Up @@ -473,7 +473,7 @@ export function checkFunctionArgMatchesDefinition(
const lowerArgType = argType?.toLowerCase();
const lowerArgCastType = arg.castType?.toLowerCase();
return (
lowerArgType === lowerArgCastType ||
compareTypesWithLiterals(lowerArgCastType, lowerArgType) ||
// for valid shorthand casts like 321.12::int or "false"::bool
(['int', 'bool'].includes(lowerArgCastType) && argType.startsWith(lowerArgCastType))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9546,6 +9546,11 @@
"error": [],
"warning": []
},
{
"query": "from a_index | where 1::string==\"keyword\"",
"error": [],
"warning": []
},
{
"query": "from a_index | eval trim(\"23\"::double)",
"error": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,8 @@ describe('validation logic', () => {
// accepts casting with multiple types
testErrorsAndWarnings('from a_index | eval 1::keyword::long::double', []);

testErrorsAndWarnings('from a_index | where 1::string=="keyword"', []);

// takes into account casting in function arguments
testErrorsAndWarnings('from a_index | eval trim("23"::double)', [
'Argument of [trim] must be [keyword], found value ["23"::double] type [double]',
Expand Down