Skip to content

Commit

Permalink
[ES|QL] Fixes inline casting wrong validation (#196489)
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula authored Oct 16, 2024
1 parent f8d2fff commit 40f9513
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
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

0 comments on commit 40f9513

Please sign in to comment.