From 17c8168db941a0740b75b22877f2db1d9f493e8e Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 17 Oct 2024 04:45:29 +1100 Subject: [PATCH] [8.x] [ES|QL] Fixes inline casting wrong validation (#196489) (#196573) # Backport This will backport the following commits from `main` to `8.x`: - [[ES|QL] Fixes inline casting wrong validation (#196489)](https://github.com/elastic/kibana/pull/196489) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Stratoula Kalafateli --- .../kbn-esql-validation-autocomplete/src/shared/helpers.ts | 4 ++-- .../src/validation/esql_validation_meta_tests.json | 5 +++++ .../src/validation/validation.test.ts | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/kbn-esql-validation-autocomplete/src/shared/helpers.ts b/packages/kbn-esql-validation-autocomplete/src/shared/helpers.ts index ce9cec58575fc..e3e3da4277344 100644 --- a/packages/kbn-esql-validation-autocomplete/src/shared/helpers.ts +++ b/packages/kbn-esql-validation-autocomplete/src/shared/helpers.ts @@ -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'; @@ -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)) ); diff --git a/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json b/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json index 736159b36384d..a646c0323a76f 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json +++ b/packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json @@ -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": [ 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 66de6c7fc70ad..dd04f0e506fe8 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts @@ -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]',