Skip to content

Commit

Permalink
[8.x] [ES|QL] Fixes inline casting wrong validation (elastic#196489) (e…
Browse files Browse the repository at this point in the history
…lastic#196573)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ES|QL] Fixes inline casting wrong validation
(elastic#196489)](elastic#196489)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Stratoula
Kalafateli","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-16T16:01:48Z","message":"[ES|QL]
Fixes inline casting wrong validation
(elastic#196489)","sha":"40f95132e8032787b995bd68d8f265fffea2760e","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","Feature:ES|QL","Team:ESQL","v8.16.0"],"title":"[ES|QL]
Fixes inline casting wrong
validation","number":196489,"url":"https://github.com/elastic/kibana/pull/196489","mergeCommit":{"message":"[ES|QL]
Fixes inline casting wrong validation
(elastic#196489)","sha":"40f95132e8032787b995bd68d8f265fffea2760e"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196489","number":196489,"mergeCommit":{"message":"[ES|QL]
Fixes inline casting wrong validation
(elastic#196489)","sha":"40f95132e8032787b995bd68d8f265fffea2760e"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Stratoula Kalafateli <[email protected]>
  • Loading branch information
kibanamachine and stratoula authored Oct 16, 2024
1 parent c8b5129 commit 17c8168
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 17c8168

Please sign in to comment.