From eb3c8b7c870bd1fd61b67de9500884662230105a Mon Sep 17 00:00:00 2001 From: Drew Tate Date: Wed, 8 May 2024 09:39:16 -0600 Subject: [PATCH 1/6] string-to-number casting no longer valid --- .../src/definitions/builtin.ts | 32 +- .../esql_validation_meta_tests.json | 462 ++++-------------- .../src/validation/validation.test.ts | 41 +- 3 files changed, 112 insertions(+), 423 deletions(-) diff --git a/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts b/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts index 20adda63602df..b80dc9314098d 100644 --- a/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts +++ b/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts @@ -91,22 +91,22 @@ function createComparisonDefinition( ], returnType: 'boolean', }, - ...['date', 'number'].flatMap((type) => [ - { - params: [ - { name: 'left', type }, - { name: 'right', type: 'string', constantOnly: true }, - ], - returnType: 'boolean', - }, - { - params: [ - { name: 'right', type: 'string', constantOnly: true }, - { name: 'right', type }, - ], - returnType: 'boolean', - }, - ]), + // ...['date', 'number'].flatMap((type) => [ + // { + // params: [ + // { name: 'left', type }, + // { name: 'right', type: 'string', constantOnly: true }, + // ], + // returnType: 'boolean', + // }, + // { + // params: [ + // { name: 'right', type: 'string', constantOnly: true }, + // { name: 'right', type }, + // ], + // returnType: 'boolean', + // }, + // ]), ...extraSignatures, ], }; 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 660fff0bb7d8f..bb1355d710a1c 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 @@ -2916,16 +2916,6 @@ "error": [], "warning": [] }, - { - "query": "row var = 42 > \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "row var = \"2022\" > 42", - "error": [], - "warning": [] - }, { "query": "row var = 5 >= 0", "error": [], @@ -2976,16 +2966,6 @@ "error": [], "warning": [] }, - { - "query": "row var = 42 >= \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "row var = \"2022\" >= 42", - "error": [], - "warning": [] - }, { "query": "row var = 5 < 0", "error": [], @@ -3036,16 +3016,6 @@ "error": [], "warning": [] }, - { - "query": "row var = 42 < \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "row var = \"2022\" < 42", - "error": [], - "warning": [] - }, { "query": "row var = 5 <= 0", "error": [], @@ -3096,16 +3066,6 @@ "error": [], "warning": [] }, - { - "query": "row var = 42 <= \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "row var = \"2022\" <= 42", - "error": [], - "warning": [] - }, { "query": "row var = 5 == 0", "error": [], @@ -3153,16 +3113,6 @@ "error": [], "warning": [] }, - { - "query": "row var = 42 == \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "row var = \"2022\" == 42", - "error": [], - "warning": [] - }, { "query": "row var = 5 != 0", "error": [], @@ -3210,16 +3160,6 @@ "error": [], "warning": [] }, - { - "query": "row var = 42 != \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "row var = \"2022\" != 42", - "error": [], - "warning": [] - }, { "query": "row var = 1 + 1", "error": [], @@ -5343,58 +5283,6 @@ "error": [], "warning": [] }, - { - "query": "from a_index | where numberField > stringField", - "error": [ - "Argument of [>] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField > numberField", - "error": [ - "Argument of [>] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where numberField > \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where dateField > stringField", - "error": [ - "Argument of [>] must be [string], found value [dateField] type [date]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField > dateField", - "error": [ - "Argument of [>] must be [string], found value [dateField] type [date]" - ], - "warning": [] - }, - { - "query": "from a_index | where dateField > \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where stringField > 0", - "error": [ - "Argument of [>] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField > now()", - "error": [ - "Argument of [>] must be [string], found value [now()] type [date]" - ], - "warning": [] - }, { "query": "from a_index | where numberField >= 0", "error": [], @@ -5448,58 +5336,6 @@ "error": [], "warning": [] }, - { - "query": "from a_index | where numberField >= stringField", - "error": [ - "Argument of [>=] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField >= numberField", - "error": [ - "Argument of [>=] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where numberField >= \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where dateField >= stringField", - "error": [ - "Argument of [>=] must be [string], found value [dateField] type [date]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField >= dateField", - "error": [ - "Argument of [>=] must be [string], found value [dateField] type [date]" - ], - "warning": [] - }, - { - "query": "from a_index | where dateField >= \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where stringField >= 0", - "error": [ - "Argument of [>=] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField >= now()", - "error": [ - "Argument of [>=] must be [string], found value [now()] type [date]" - ], - "warning": [] - }, { "query": "from a_index | where numberField < 0", "error": [], @@ -5553,58 +5389,6 @@ "error": [], "warning": [] }, - { - "query": "from a_index | where numberField < stringField", - "error": [ - "Argument of [<] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField < numberField", - "error": [ - "Argument of [<] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where numberField < \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where dateField < stringField", - "error": [ - "Argument of [<] must be [string], found value [dateField] type [date]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField < dateField", - "error": [ - "Argument of [<] must be [string], found value [dateField] type [date]" - ], - "warning": [] - }, - { - "query": "from a_index | where dateField < \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where stringField < 0", - "error": [ - "Argument of [<] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField < now()", - "error": [ - "Argument of [<] must be [string], found value [now()] type [date]" - ], - "warning": [] - }, { "query": "from a_index | where numberField <= 0", "error": [], @@ -5658,58 +5442,6 @@ "error": [], "warning": [] }, - { - "query": "from a_index | where numberField <= stringField", - "error": [ - "Argument of [<=] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField <= numberField", - "error": [ - "Argument of [<=] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where numberField <= \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where dateField <= stringField", - "error": [ - "Argument of [<=] must be [string], found value [dateField] type [date]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField <= dateField", - "error": [ - "Argument of [<=] must be [string], found value [dateField] type [date]" - ], - "warning": [] - }, - { - "query": "from a_index | where dateField <= \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where stringField <= 0", - "error": [ - "Argument of [<=] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField <= now()", - "error": [ - "Argument of [<=] must be [string], found value [now()] type [date]" - ], - "warning": [] - }, { "query": "from a_index | where numberField == 0", "error": [], @@ -5760,58 +5492,6 @@ "error": [], "warning": [] }, - { - "query": "from a_index | where numberField == stringField", - "error": [ - "Argument of [==] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField == numberField", - "error": [ - "Argument of [==] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where numberField == \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where dateField == stringField", - "error": [ - "Argument of [==] must be [string], found value [dateField] type [date]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField == dateField", - "error": [ - "Argument of [==] must be [string], found value [dateField] type [date]" - ], - "warning": [] - }, - { - "query": "from a_index | where dateField == \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where stringField == 0", - "error": [ - "Argument of [==] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField == now()", - "error": [ - "Argument of [==] must be [string], found value [now()] type [date]" - ], - "warning": [] - }, { "query": "from a_index | where numberField != 0", "error": [], @@ -5862,58 +5542,6 @@ "error": [], "warning": [] }, - { - "query": "from a_index | where numberField != stringField", - "error": [ - "Argument of [!=] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField != numberField", - "error": [ - "Argument of [!=] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where numberField != \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where dateField != stringField", - "error": [ - "Argument of [!=] must be [string], found value [dateField] type [date]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField != dateField", - "error": [ - "Argument of [!=] must be [string], found value [dateField] type [date]" - ], - "warning": [] - }, - { - "query": "from a_index | where dateField != \"2022\"", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where stringField != 0", - "error": [ - "Argument of [!=] must be [number], found value [stringField] type [string]" - ], - "warning": [] - }, - { - "query": "from a_index | where stringField != now()", - "error": [ - "Argument of [!=] must be [string], found value [now()] type [date]" - ], - "warning": [] - }, { "query": "from a_index | where - numberField > 0", "error": [], @@ -12001,7 +11629,9 @@ }, { "query": "from a_index | eval numberField > \"2022\"", - "error": [], + "error": [ + "Argument of [>] must be [number], found value [\"2022\"] type [string]" + ], "warning": [] }, { @@ -12106,7 +11736,9 @@ }, { "query": "from a_index | eval numberField >= \"2022\"", - "error": [], + "error": [ + "Argument of [>=] must be [number], found value [\"2022\"] type [string]" + ], "warning": [] }, { @@ -12211,7 +11843,9 @@ }, { "query": "from a_index | eval numberField < \"2022\"", - "error": [], + "error": [ + "Argument of [<] must be [number], found value [\"2022\"] type [string]" + ], "warning": [] }, { @@ -12316,7 +11950,9 @@ }, { "query": "from a_index | eval numberField <= \"2022\"", - "error": [], + "error": [ + "Argument of [<=] must be [number], found value [\"2022\"] type [string]" + ], "warning": [] }, { @@ -12418,7 +12054,9 @@ }, { "query": "from a_index | eval numberField == \"2022\"", - "error": [], + "error": [ + "Argument of [==] must be [number], found value [\"2022\"] type [string]" + ], "warning": [] }, { @@ -12476,6 +12114,20 @@ ], "warning": [] }, + { + "query": "from a_index | eval 1 + \"1\"", + "error": [ + "Argument of [+] must be [number], found value [\"1\"] type [string]" + ], + "warning": [] + }, + { + "query": "from a_index | eval \"1\" + 1", + "error": [ + "Argument of [+] must be [number], found value [\"1\"] type [string]" + ], + "warning": [] + }, { "query": "from a_index | eval numberField - 1", "error": [], @@ -12498,6 +12150,20 @@ ], "warning": [] }, + { + "query": "from a_index | eval 1 - \"1\"", + "error": [ + "Argument of [-] must be [number], found value [\"1\"] type [string]" + ], + "warning": [] + }, + { + "query": "from a_index | eval \"1\" - 1", + "error": [ + "Argument of [-] must be [number], found value [\"1\"] type [string]" + ], + "warning": [] + }, { "query": "from a_index | eval numberField * 1", "error": [], @@ -12521,6 +12187,20 @@ ], "warning": [] }, + { + "query": "from a_index | eval 1 * \"1\"", + "error": [ + "Argument of [*] must be [number], found value [\"1\"] type [string]" + ], + "warning": [] + }, + { + "query": "from a_index | eval \"1\" * 1", + "error": [ + "Argument of [*] must be [number], found value [\"1\"] type [string]" + ], + "warning": [] + }, { "query": "from a_index | eval numberField / 1", "error": [], @@ -12544,6 +12224,20 @@ ], "warning": [] }, + { + "query": "from a_index | eval 1 / \"1\"", + "error": [ + "Argument of [/] must be [number], found value [\"1\"] type [string]" + ], + "warning": [] + }, + { + "query": "from a_index | eval \"1\" / 1", + "error": [ + "Argument of [/] must be [number], found value [\"1\"] type [string]" + ], + "warning": [] + }, { "query": "from a_index | eval numberField % 1", "error": [], @@ -12567,6 +12261,20 @@ ], "warning": [] }, + { + "query": "from a_index | eval 1 % \"1\"", + "error": [ + "Argument of [%] must be [number], found value [\"1\"] type [string]" + ], + "warning": [] + }, + { + "query": "from a_index | eval \"1\" % 1", + "error": [ + "Argument of [%] must be [number], found value [\"1\"] type [string]" + ], + "warning": [] + }, { "query": "from a_index | eval 1/0", "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 1d7d080b6c5c0..adcb4a8e38ac8 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts @@ -688,10 +688,7 @@ describe('validation logic', () => { `Argument of [${op}] must be [number], found value [false] type [boolean]`, ] ); - for (const [valueTypeA, valueTypeB] of [ - ['now()', '"2022"'], - ['42', '"2022"'], - ]) { + for (const [valueTypeA, valueTypeB] of [['now()', '"2022"']]) { testErrorsAndWarnings(`row var = ${valueTypeA} ${op} ${valueTypeB}`, []); testErrorsAndWarnings(`row var = ${valueTypeB} ${op} ${valueTypeA}`, []); } @@ -1122,31 +1119,6 @@ describe('validation logic', () => { ] ); } - - // Implicit casting of literal values tests - testErrorsAndWarnings(`from a_index | where numberField ${op} stringField`, [ - `Argument of [${op}] must be [number], found value [stringField] type [string]`, - ]); - testErrorsAndWarnings(`from a_index | where stringField ${op} numberField`, [ - `Argument of [${op}] must be [number], found value [stringField] type [string]`, - ]); - testErrorsAndWarnings(`from a_index | where numberField ${op} "2022"`, []); - - testErrorsAndWarnings(`from a_index | where dateField ${op} stringField`, [ - `Argument of [${op}] must be [string], found value [dateField] type [date]`, - ]); - testErrorsAndWarnings(`from a_index | where stringField ${op} dateField`, [ - `Argument of [${op}] must be [string], found value [dateField] type [date]`, - ]); - testErrorsAndWarnings(`from a_index | where dateField ${op} "2022"`, []); - - // Check that the implicit cast doesn't apply for fields - testErrorsAndWarnings(`from a_index | where stringField ${op} 0`, [ - `Argument of [${op}] must be [number], found value [stringField] type [string]`, - ]); - testErrorsAndWarnings(`from a_index | where stringField ${op} now()`, [ - `Argument of [${op}] must be [string], found value [now()] type [date]`, - ]); } for (const nesting of NESTED_DEPTHS) { @@ -1732,7 +1704,9 @@ describe('validation logic', () => { testErrorsAndWarnings(`from a_index | eval stringField ${op} numberField`, [ `Argument of [${op}] must be [number], found value [stringField] type [string]`, ]); - testErrorsAndWarnings(`from a_index | eval numberField ${op} "2022"`, []); + testErrorsAndWarnings(`from a_index | eval numberField ${op} "2022"`, [ + `Argument of [${op}] must be [number], found value ["2022"] type [string]`, + ]); testErrorsAndWarnings(`from a_index | eval dateField ${op} stringField`, [ `Argument of [${op}] must be [string], found value [dateField] type [date]`, @@ -1763,6 +1737,13 @@ describe('validation logic', () => { `Argument of [${op}] must be [number], found value [now()] type [date]`, ] ); + + testErrorsAndWarnings(`from a_index | eval 1 ${op} "1"`, [ + `Argument of [${op}] must be [number], found value [\"1\"] type [string]`, + ]); + testErrorsAndWarnings(`from a_index | eval "1" ${op} 1`, [ + `Argument of [${op}] must be [number], found value [\"1\"] type [string]`, + ]); } for (const divideByZeroExpr of ['1/0', 'var = 1/0', '1 + 1/0']) { testErrorsAndWarnings( From af3b5d3cfa956146358f8e106c86072289e7d78d Mon Sep 17 00:00:00 2001 From: Drew Tate Date: Wed, 8 May 2024 09:50:17 -0600 Subject: [PATCH 2/6] implicit casting for comparing booleans --- .../src/definitions/builtin.ts | 62 +++-- .../esql_validation_meta_tests.json | 250 ++++++++++++++++-- .../src/validation/validation.test.ts | 48 +++- 3 files changed, 322 insertions(+), 38 deletions(-) diff --git a/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts b/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts index b80dc9314098d..218bf264e2564 100644 --- a/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts +++ b/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts @@ -91,22 +91,22 @@ function createComparisonDefinition( ], returnType: 'boolean', }, - // ...['date', 'number'].flatMap((type) => [ - // { - // params: [ - // { name: 'left', type }, - // { name: 'right', type: 'string', constantOnly: true }, - // ], - // returnType: 'boolean', - // }, - // { - // params: [ - // { name: 'right', type: 'string', constantOnly: true }, - // { name: 'right', type }, - // ], - // returnType: 'boolean', - // }, - // ]), + ...[].flatMap((type) => [ + { + params: [ + { name: 'left', type }, + { name: 'right', type: 'string', constantOnly: true }, + ], + returnType: 'boolean', + }, + { + params: [ + { name: 'right', type: 'string', constantOnly: true }, + { name: 'right', type }, + ], + returnType: 'boolean', + }, + ]), ...extraSignatures, ], }; @@ -214,6 +214,21 @@ export const builtinFunctions: FunctionDefinition[] = [ ], returnType: 'boolean', }, + // constant strings okay because of implicit casting + { + params: [ + { name: 'left', type: 'boolean' }, + { name: 'right', type: 'string', constantOnly: true }, + ], + returnType: 'boolean', + }, + { + params: [ + { name: 'right', type: 'string', constantOnly: true }, + { name: 'right', type: 'boolean' }, + ], + returnType: 'boolean', + }, ], }, { @@ -232,6 +247,21 @@ export const builtinFunctions: FunctionDefinition[] = [ ], returnType: 'boolean', }, + // constant strings okay because of implicit casting + { + params: [ + { name: 'left', type: 'boolean' }, + { name: 'right', type: 'string', constantOnly: true }, + ], + returnType: 'boolean', + }, + { + params: [ + { name: 'right', type: 'string', constantOnly: true }, + { name: 'right', type: 'boolean' }, + ], + returnType: 'boolean', + }, ], }, { 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 bb1355d710a1c..89594e5b055e7 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 @@ -11648,22 +11648,41 @@ ], "warning": [] }, + { + "query": "from a_index | eval stringField > 0", + "error": [ + "Argument of [>] must be [number], found value [stringField] type [string]" + ], + "warning": [] + }, + { + "query": "from a_index | eval stringField > now()", + "error": [ + "Argument of [>] must be [string], found value [now()] type [date]" + ], + "warning": [] + }, { "query": "from a_index | eval dateField > \"2022\"", "error": [], "warning": [] }, { - "query": "from a_index | eval stringField > 0", + "query": "from a_index | eval \"2022\" > dateField", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval booleanField > \"true\"", "error": [ - "Argument of [>] must be [number], found value [stringField] type [string]" + "Argument of [>] must be [string], found value [booleanField] type [boolean]" ], "warning": [] }, { - "query": "from a_index | eval stringField > now()", + "query": "from a_index | eval \"true\" > booleanField", "error": [ - "Argument of [>] must be [string], found value [now()] type [date]" + "Argument of [>] must be [string], found value [booleanField] type [boolean]" ], "warning": [] }, @@ -11755,22 +11774,41 @@ ], "warning": [] }, + { + "query": "from a_index | eval stringField >= 0", + "error": [ + "Argument of [>=] must be [number], found value [stringField] type [string]" + ], + "warning": [] + }, + { + "query": "from a_index | eval stringField >= now()", + "error": [ + "Argument of [>=] must be [string], found value [now()] type [date]" + ], + "warning": [] + }, { "query": "from a_index | eval dateField >= \"2022\"", "error": [], "warning": [] }, { - "query": "from a_index | eval stringField >= 0", + "query": "from a_index | eval \"2022\" >= dateField", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval booleanField >= \"true\"", "error": [ - "Argument of [>=] must be [number], found value [stringField] type [string]" + "Argument of [>=] must be [string], found value [booleanField] type [boolean]" ], "warning": [] }, { - "query": "from a_index | eval stringField >= now()", + "query": "from a_index | eval \"true\" >= booleanField", "error": [ - "Argument of [>=] must be [string], found value [now()] type [date]" + "Argument of [>=] must be [string], found value [booleanField] type [boolean]" ], "warning": [] }, @@ -11862,22 +11900,41 @@ ], "warning": [] }, + { + "query": "from a_index | eval stringField < 0", + "error": [ + "Argument of [<] must be [number], found value [stringField] type [string]" + ], + "warning": [] + }, + { + "query": "from a_index | eval stringField < now()", + "error": [ + "Argument of [<] must be [string], found value [now()] type [date]" + ], + "warning": [] + }, { "query": "from a_index | eval dateField < \"2022\"", "error": [], "warning": [] }, { - "query": "from a_index | eval stringField < 0", + "query": "from a_index | eval \"2022\" < dateField", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval booleanField < \"true\"", "error": [ - "Argument of [<] must be [number], found value [stringField] type [string]" + "Argument of [<] must be [string], found value [booleanField] type [boolean]" ], "warning": [] }, { - "query": "from a_index | eval stringField < now()", + "query": "from a_index | eval \"true\" < booleanField", "error": [ - "Argument of [<] must be [string], found value [now()] type [date]" + "Argument of [<] must be [string], found value [booleanField] type [boolean]" ], "warning": [] }, @@ -11969,22 +12026,41 @@ ], "warning": [] }, + { + "query": "from a_index | eval stringField <= 0", + "error": [ + "Argument of [<=] must be [number], found value [stringField] type [string]" + ], + "warning": [] + }, + { + "query": "from a_index | eval stringField <= now()", + "error": [ + "Argument of [<=] must be [string], found value [now()] type [date]" + ], + "warning": [] + }, { "query": "from a_index | eval dateField <= \"2022\"", "error": [], "warning": [] }, { - "query": "from a_index | eval stringField <= 0", + "query": "from a_index | eval \"2022\" <= dateField", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval booleanField <= \"true\"", "error": [ - "Argument of [<=] must be [number], found value [stringField] type [string]" + "Argument of [<=] must be [string], found value [booleanField] type [boolean]" ], "warning": [] }, { - "query": "from a_index | eval stringField <= now()", + "query": "from a_index | eval \"true\" <= booleanField", "error": [ - "Argument of [<=] must be [string], found value [now()] type [date]" + "Argument of [<=] must be [string], found value [booleanField] type [boolean]" ], "warning": [] }, @@ -12073,25 +12149,159 @@ ], "warning": [] }, + { + "query": "from a_index | eval stringField == 0", + "error": [ + "Argument of [==] must be [number], found value [stringField] type [string]" + ], + "warning": [] + }, + { + "query": "from a_index | eval stringField == now()", + "error": [ + "Argument of [==] must be [string], found value [now()] type [date]" + ], + "warning": [] + }, { "query": "from a_index | eval dateField == \"2022\"", "error": [], "warning": [] }, { - "query": "from a_index | eval stringField == 0", + "query": "from a_index | eval \"2022\" == dateField", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval booleanField == \"true\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"true\" == booleanField", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval numberField != 0", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval NOT numberField != 0", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval (numberField != 0)", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval (NOT (numberField != 0))", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 != 0", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval stringField != stringField", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval numberField != numberField", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval dateField != dateField", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval booleanField != booleanField", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval ipField != ipField", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval numberField != stringField", "error": [ - "Argument of [==] must be [number], found value [stringField] type [string]" + "Argument of [!=] must be [number], found value [stringField] type [string]" ], "warning": [] }, { - "query": "from a_index | eval stringField == now()", + "query": "from a_index | eval stringField != numberField", "error": [ - "Argument of [==] must be [string], found value [now()] type [date]" + "Argument of [!=] must be [number], found value [stringField] type [string]" + ], + "warning": [] + }, + { + "query": "from a_index | eval numberField != \"2022\"", + "error": [ + "Argument of [!=] must be [number], found value [\"2022\"] type [string]" ], "warning": [] }, + { + "query": "from a_index | eval dateField != stringField", + "error": [ + "Argument of [!=] must be [string], found value [dateField] type [date]" + ], + "warning": [] + }, + { + "query": "from a_index | eval stringField != dateField", + "error": [ + "Argument of [!=] must be [string], found value [dateField] type [date]" + ], + "warning": [] + }, + { + "query": "from a_index | eval stringField != 0", + "error": [ + "Argument of [!=] must be [number], found value [stringField] type [string]" + ], + "warning": [] + }, + { + "query": "from a_index | eval stringField != now()", + "error": [ + "Argument of [!=] must be [string], found value [now()] type [date]" + ], + "warning": [] + }, + { + "query": "from a_index | eval dateField != \"2022\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"2022\" != dateField", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval booleanField != \"true\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"true\" != booleanField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval numberField + 1", "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 adcb4a8e38ac8..374310e00b88c 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts @@ -1680,7 +1680,7 @@ describe('validation logic', () => { 'Log of a negative number results in null: -20', ] ); - for (const op of ['>', '>=', '<', '<=', '==']) { + for (const op of ['>', '>=', '<', '<=', '==', '!=']) { testErrorsAndWarnings(`from a_index | eval numberField ${op} 0`, []); testErrorsAndWarnings(`from a_index | eval NOT numberField ${op} 0`, []); testErrorsAndWarnings(`from a_index | eval (numberField ${op} 0)`, []); @@ -1714,7 +1714,6 @@ describe('validation logic', () => { testErrorsAndWarnings(`from a_index | eval stringField ${op} dateField`, [ `Argument of [${op}] must be [string], found value [dateField] type [date]`, ]); - testErrorsAndWarnings(`from a_index | eval dateField ${op} "2022"`, []); // Check that the implicit cast doesn't apply for fields testErrorsAndWarnings(`from a_index | eval stringField ${op} 0`, [ @@ -1723,7 +1722,45 @@ describe('validation logic', () => { testErrorsAndWarnings(`from a_index | eval stringField ${op} now()`, [ `Argument of [${op}] must be [string], found value [now()] type [date]`, ]); + + testErrorsAndWarnings(`from a_index | eval dateField ${op} "2022"`, []); + testErrorsAndWarnings(`from a_index | eval "2022" ${op} dateField`, []); + + // testErrorsAndWarnings(`from a_index | eval versionField ${op} "1.2.3"`, []); + // testErrorsAndWarnings(`from a_index | eval "1.2.3" ${op} versionField`, []); + + testErrorsAndWarnings( + `from a_index | eval booleanField ${op} "true"`, + ['==', '!='].includes(op) + ? [] + : [`Argument of [${op}] must be [string], found value [booleanField] type [boolean]`] + ); + testErrorsAndWarnings( + `from a_index | eval "true" ${op} booleanField`, + ['==', '!='].includes(op) + ? [] + : [`Argument of [${op}] must be [string], found value [booleanField] type [boolean]`] + ); + + // testErrorsAndWarnings(`from a_index | eval ipField ${op} "136.36.3.205"`, []); + // testErrorsAndWarnings(`from a_index | eval "136.36.3.205" ${op} ipField`, []); } + + // // casting for IN for version, date, boolean, ip + // testErrorsAndWarnings( + // 'from a_index | eval versionField in ("1.2.3", "4.5.6", to_version("2.3.2"))', + // [] + // ); + // testErrorsAndWarnings( + // 'from a_index | eval dateField in ("2023-12-12", "2024-12-12", date_parse("2025-12-12"))', + // [] + // ); + // testErrorsAndWarnings('from a_index | eval booleanField in ("true", "false", false)', []); + // testErrorsAndWarnings( + // 'from a_index | eval ipField in ("136.36.3.205", "136.36.3.206", to_ip("136.36.3.207"))', + // [] + // ); + for (const op of ['+', '-', '*', '/', '%']) { testErrorsAndWarnings(`from a_index | eval numberField ${op} 1`, []); testErrorsAndWarnings(`from a_index | eval (numberField ${op} 1)`, []); @@ -1744,6 +1781,13 @@ describe('validation logic', () => { testErrorsAndWarnings(`from a_index | eval "1" ${op} 1`, [ `Argument of [${op}] must be [number], found value [\"1\"] type [string]`, ]); + // check implicit casting for version, boolean, ip + // testErrorsAndWarnings(`from a_index | eval versionField ${op} "1.2.3"`, []); + // testErrorsAndWarnings(`from a_index | eval "1.2.3" ${op} versionField`, []); + // testErrorsAndWarnings(`from a_index | eval booleanField ${op} "true"`, []); + // testErrorsAndWarnings(`from a_index | eval "true" ${op} booleanField`, []); + // testErrorsAndWarnings(`from a_index | eval ipField ${op} "136.36.3.205"`, []); + // testErrorsAndWarnings(`from a_index | eval "136.36.3.205" ${op} ipField`, []); } for (const divideByZeroExpr of ['1/0', 'var = 1/0', '1 + 1/0']) { testErrorsAndWarnings( From 07b38b753d120645fd401c415621ee89ede47d25 Mon Sep 17 00:00:00 2001 From: Drew Tate Date: Wed, 8 May 2024 10:27:06 -0600 Subject: [PATCH 3/6] implicit casting when comparing versions --- .../src/definitions/builtin.ts | 11 +- .../src/definitions/functions.ts | 2 +- .../esql_validation_meta_tests.json | 151 ++++++++++++++++-- .../src/validation/validation.test.ts | 5 +- 4 files changed, 153 insertions(+), 16 deletions(-) diff --git a/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts b/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts index 218bf264e2564..5947dc54cf7e4 100644 --- a/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts +++ b/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts @@ -91,7 +91,16 @@ function createComparisonDefinition( ], returnType: 'boolean', }, - ...[].flatMap((type) => [ + { + params: [ + { name: 'left', type: 'version' }, + { name: 'right', type: 'version' }, + ], + returnType: 'boolean', + }, + // constant strings okay because of implicit casting for + // string to version + ...['version'].flatMap((type) => [ { params: [ { name: 'left', type }, diff --git a/packages/kbn-esql-validation-autocomplete/src/definitions/functions.ts b/packages/kbn-esql-validation-autocomplete/src/definitions/functions.ts index 205b2d158fd05..e55ddf9f92a27 100644 --- a/packages/kbn-esql-validation-autocomplete/src/definitions/functions.ts +++ b/packages/kbn-esql-validation-autocomplete/src/definitions/functions.ts @@ -557,7 +557,7 @@ export const evalFunctionsDefinitions: FunctionDefinition[] = [ signatures: [ { params: [{ name: 'field', type: 'string' }], - returnType: 'string', + returnType: 'version', examples: [`from index | EVAL version = to_version(stringField)`], }, ], 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 89594e5b055e7..dbfdc13a7b755 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 @@ -20,6 +20,10 @@ "name": "booleanField", "type": "boolean" }, + { + "name": "versionField", + "type": "version" + }, { "name": "ipField", "type": "ip" @@ -6178,6 +6182,46 @@ "error": [], "warning": [] }, + { + "query": "from a_index | where versionField IS NULL", + "error": [], + "warning": [] + }, + { + "query": "from a_index | where versionField IS null", + "error": [], + "warning": [] + }, + { + "query": "from a_index | where versionField is null", + "error": [], + "warning": [] + }, + { + "query": "from a_index | where versionField is NULL", + "error": [], + "warning": [] + }, + { + "query": "from a_index | where versionField IS NOT NULL", + "error": [], + "warning": [] + }, + { + "query": "from a_index | where versionField IS NOT null", + "error": [], + "warning": [] + }, + { + "query": "from a_index | where versionField IS not NULL", + "error": [], + "warning": [] + }, + { + "query": "from a_index | where versionField Is nOt NuLL", + "error": [], + "warning": [] + }, { "query": "from a_index | where ipField IS NULL", "error": [], @@ -7065,18 +7109,6 @@ ], "warning": [] }, - { - "query": "from a_index | where length(to_version(stringField)) > 0", - "error": [], - "warning": [] - }, - { - "query": "from a_index | where length(to_version(numberField)) > 0", - "error": [ - "Argument of [to_version] must be [string], found value [numberField] type [number]" - ], - "warning": [] - }, { "query": "from a_index | where length(trim(stringField)) > 0", "error": [], @@ -7320,6 +7352,41 @@ "error": [], "warning": [] }, + { + "query": "from a_index | eval versionField IS NULL", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval versionField IS null", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval versionField is null", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval versionField is NULL", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval versionField IS NOT NULL", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval versionField IS NOT null", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval versionField IS not NULL", + "error": [], + "warning": [] + }, { "query": "from a_index | eval ipField IS NULL", "error": [], @@ -11672,6 +11739,16 @@ "error": [], "warning": [] }, + { + "query": "from a_index | eval versionField > \"1.2.3\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"1.2.3\" > versionField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval booleanField > \"true\"", "error": [ @@ -11798,6 +11875,16 @@ "error": [], "warning": [] }, + { + "query": "from a_index | eval versionField >= \"1.2.3\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"1.2.3\" >= versionField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval booleanField >= \"true\"", "error": [ @@ -11924,6 +12011,16 @@ "error": [], "warning": [] }, + { + "query": "from a_index | eval versionField < \"1.2.3\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"1.2.3\" < versionField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval booleanField < \"true\"", "error": [ @@ -12050,6 +12147,16 @@ "error": [], "warning": [] }, + { + "query": "from a_index | eval versionField <= \"1.2.3\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"1.2.3\" <= versionField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval booleanField <= \"true\"", "error": [ @@ -12173,6 +12280,16 @@ "error": [], "warning": [] }, + { + "query": "from a_index | eval versionField == \"1.2.3\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"1.2.3\" == versionField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval booleanField == \"true\"", "error": [], @@ -12292,6 +12409,16 @@ "error": [], "warning": [] }, + { + "query": "from a_index | eval versionField != \"1.2.3\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"1.2.3\" != versionField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval booleanField != \"true\"", "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 374310e00b88c..1a5b4a2ad2cf4 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts @@ -24,6 +24,7 @@ const fieldTypes = [ 'number', 'date', 'boolean', + 'version', 'ip', 'string', 'cartesian_point', @@ -1726,8 +1727,8 @@ describe('validation logic', () => { testErrorsAndWarnings(`from a_index | eval dateField ${op} "2022"`, []); testErrorsAndWarnings(`from a_index | eval "2022" ${op} dateField`, []); - // testErrorsAndWarnings(`from a_index | eval versionField ${op} "1.2.3"`, []); - // testErrorsAndWarnings(`from a_index | eval "1.2.3" ${op} versionField`, []); + testErrorsAndWarnings(`from a_index | eval versionField ${op} "1.2.3"`, []); + testErrorsAndWarnings(`from a_index | eval "1.2.3" ${op} versionField`, []); testErrorsAndWarnings( `from a_index | eval booleanField ${op} "true"`, From 4f816ab5e5ca22841e5444811e0dfbe3601beaf2 Mon Sep 17 00:00:00 2001 From: Drew Tate Date: Wed, 8 May 2024 10:33:44 -0600 Subject: [PATCH 4/6] implicit casting while comparing IPs --- .../src/definitions/builtin.ts | 10 +++- .../esql_validation_meta_tests.json | 60 +++++++++++++++++++ .../src/validation/validation.test.ts | 4 +- 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts b/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts index 5947dc54cf7e4..34647f6e4812b 100644 --- a/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts +++ b/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts @@ -99,8 +99,14 @@ function createComparisonDefinition( returnType: 'boolean', }, // constant strings okay because of implicit casting for - // string to version - ...['version'].flatMap((type) => [ + // string to version and ip + // + // boolean casting is handled on the specific comparison function + // that support booleans + // + // date casting is handled in the validation routine since it's a + // general rule. Look in compareLiteralType() + ...['ip', 'version'].flatMap((type) => [ { params: [ { name: 'left', type }, 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 dbfdc13a7b755..efc063ca3b57b 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 @@ -11763,6 +11763,16 @@ ], "warning": [] }, + { + "query": "from a_index | eval ipField > \"136.36.3.205\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"136.36.3.205\" > ipField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval numberField >= 0", "error": [], @@ -11899,6 +11909,16 @@ ], "warning": [] }, + { + "query": "from a_index | eval ipField >= \"136.36.3.205\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"136.36.3.205\" >= ipField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval numberField < 0", "error": [], @@ -12035,6 +12055,16 @@ ], "warning": [] }, + { + "query": "from a_index | eval ipField < \"136.36.3.205\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"136.36.3.205\" < ipField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval numberField <= 0", "error": [], @@ -12171,6 +12201,16 @@ ], "warning": [] }, + { + "query": "from a_index | eval ipField <= \"136.36.3.205\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"136.36.3.205\" <= ipField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval numberField == 0", "error": [], @@ -12300,6 +12340,16 @@ "error": [], "warning": [] }, + { + "query": "from a_index | eval ipField == \"136.36.3.205\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"136.36.3.205\" == ipField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval numberField != 0", "error": [], @@ -12429,6 +12479,16 @@ "error": [], "warning": [] }, + { + "query": "from a_index | eval ipField != \"136.36.3.205\"", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval \"136.36.3.205\" != ipField", + "error": [], + "warning": [] + }, { "query": "from a_index | eval numberField + 1", "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 1a5b4a2ad2cf4..930866a5cffef 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts @@ -1743,8 +1743,8 @@ describe('validation logic', () => { : [`Argument of [${op}] must be [string], found value [booleanField] type [boolean]`] ); - // testErrorsAndWarnings(`from a_index | eval ipField ${op} "136.36.3.205"`, []); - // testErrorsAndWarnings(`from a_index | eval "136.36.3.205" ${op} ipField`, []); + testErrorsAndWarnings(`from a_index | eval ipField ${op} "136.36.3.205"`, []); + testErrorsAndWarnings(`from a_index | eval "136.36.3.205" ${op} ipField`, []); } // // casting for IN for version, date, boolean, ip From e31ed9d0a14c0d00f5f3bab4e511ec26237e5485 Mon Sep 17 00:00:00 2001 From: Drew Tate Date: Wed, 8 May 2024 11:13:31 -0600 Subject: [PATCH 5/6] turn off array validation for now --- .../src/definitions/builtin.ts | 32 ++++++++++-- .../esql_validation_meta_tests.json | 52 ++++++++++--------- .../src/validation/validation.test.ts | 44 ++++++++-------- 3 files changed, 78 insertions(+), 50 deletions(-) diff --git a/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts b/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts index 34647f6e4812b..5910237ba893e 100644 --- a/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts +++ b/packages/kbn-esql-validation-autocomplete/src/definitions/builtin.ts @@ -363,6 +363,15 @@ export const builtinFunctions: FunctionDefinition[] = [ }, { name: 'not_in', description: '' }, ].map(({ name, description }) => ({ + // set all arrays to type "any" for now + // this only applies to the "in" operator + // e.g. "foo" in ( "foo", "bar" ) + // + // we did this because the "in" operator now supports + // mixed-type arrays like ( "1.2.3", versionVar ) + // because of implicit casting. + // + // we need to revisit with more robust validation type: 'builtin', ignoreAsSuggestion: /not/.test(name), name, @@ -372,28 +381,43 @@ export const builtinFunctions: FunctionDefinition[] = [ { params: [ { name: 'left', type: 'number' }, - { name: 'right', type: 'number[]' }, + + { name: 'right', type: 'any[]' }, ], returnType: 'boolean', }, { params: [ { name: 'left', type: 'string' }, - { name: 'right', type: 'string[]' }, + { name: 'right', type: 'any[]' }, ], returnType: 'boolean', }, { params: [ { name: 'left', type: 'boolean' }, - { name: 'right', type: 'boolean[]' }, + { name: 'right', type: 'any[]' }, ], returnType: 'boolean', }, { params: [ { name: 'left', type: 'date' }, - { name: 'right', type: 'date[]' }, + { name: 'right', type: 'any[]' }, + ], + returnType: 'boolean', + }, + { + params: [ + { name: 'left', type: 'version' }, + { name: 'right', type: 'any[]' }, + ], + returnType: 'boolean', + }, + { + params: [ + { name: 'left', type: 'ip' }, + { name: 'right', type: 'any[]' }, ], returnType: 'boolean', }, 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 efc063ca3b57b..206f43718f341 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 @@ -638,30 +638,22 @@ }, { "query": "row var = 1 in (\"a\", \"b\", \"c\")", - "error": [ - "Argument of [in] must be [number[]], found value [(\"a\", \"b\", \"c\")] type [(string, string, string)]" - ], + "error": [], "warning": [] }, { "query": "row var = 5 in (\"a\", \"b\", \"c\")", - "error": [ - "Argument of [in] must be [number[]], found value [(\"a\", \"b\", \"c\")] type [(string, string, string)]" - ], + "error": [], "warning": [] }, { "query": "row var = 5 not in (\"a\", \"b\", \"c\")", - "error": [ - "Argument of [not_in] must be [number[]], found value [(\"a\", \"b\", \"c\")] type [(string, string, string)]" - ], + "error": [], "warning": [] }, { "query": "row var = 5 not in (1, 2, 3, \"a\")", - "error": [ - "Argument of [not_in] must be [number[]], found value [(1, 2, 3, \"a\")] type [(number, number, number, string)]" - ], + "error": [], "warning": [] }, { @@ -12489,6 +12481,26 @@ "error": [], "warning": [] }, + { + "query": "from a_index | eval versionField in (\"1.2.3\", \"4.5.6\", to_version(\"2.3.2\"))", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval dateField in (\"2023-12-12\", \"2024-12-12\", date_parse(\"yyyy-MM-dd\", \"2025-12-12\"))", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval booleanField in (\"true\", \"false\", false)", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval ipField in (\"136.36.3.205\", \"136.36.3.206\", to_ip(\"136.36.3.207\"))", + "error": [], + "warning": [] + }, { "query": "from a_index | eval numberField + 1", "error": [], @@ -12857,30 +12869,22 @@ }, { "query": "from a_index | eval 1 in (\"a\", \"b\", \"c\")", - "error": [ - "Argument of [in] must be [number[]], found value [(\"a\", \"b\", \"c\")] type [(string, string, string)]" - ], + "error": [], "warning": [] }, { "query": "from a_index | eval numberField in (\"a\", \"b\", \"c\")", - "error": [ - "Argument of [in] must be [number[]], found value [(\"a\", \"b\", \"c\")] type [(string, string, string)]" - ], + "error": [], "warning": [] }, { "query": "from a_index | eval numberField not in (\"a\", \"b\", \"c\")", - "error": [ - "Argument of [not_in] must be [number[]], found value [(\"a\", \"b\", \"c\")] type [(string, string, string)]" - ], + "error": [], "warning": [] }, { "query": "from a_index | eval numberField not in (1, 2, 3, stringField)", - "error": [ - "Argument of [not_in] must be [number[]], found value [(1, 2, 3, stringField)] type [(number, number, number, string)]" - ], + "error": [], "warning": [] }, { 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 930866a5cffef..31394617b78eb 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts @@ -549,16 +549,16 @@ describe('validation logic', () => { testErrorsAndWarnings('row var = "a" in ("a", "b", "c")', []); testErrorsAndWarnings('row var = "a" not in ("a", "b", "c")', []); testErrorsAndWarnings('row var = 1 in ("a", "b", "c")', [ - 'Argument of [in] must be [number[]], found value [("a", "b", "c")] type [(string, string, string)]', + // 'Argument of [in] must be [number[]], found value [("a", "b", "c")] type [(string, string, string)]', ]); testErrorsAndWarnings('row var = 5 in ("a", "b", "c")', [ - 'Argument of [in] must be [number[]], found value [("a", "b", "c")] type [(string, string, string)]', + // 'Argument of [in] must be [number[]], found value [("a", "b", "c")] type [(string, string, string)]', ]); testErrorsAndWarnings('row var = 5 not in ("a", "b", "c")', [ - 'Argument of [not_in] must be [number[]], found value [("a", "b", "c")] type [(string, string, string)]', + // 'Argument of [not_in] must be [number[]], found value [("a", "b", "c")] type [(string, string, string)]', ]); testErrorsAndWarnings('row var = 5 not in (1, 2, 3, "a")', [ - 'Argument of [not_in] must be [number[]], found value [(1, 2, 3, "a")] type [(number, number, number, string)]', + // 'Argument of [not_in] must be [number[]], found value [(1, 2, 3, "a")] type [(number, number, number, string)]', ]); // test that "and" and "or" accept null... not sure if this is the best place or not... @@ -1747,20 +1747,20 @@ describe('validation logic', () => { testErrorsAndWarnings(`from a_index | eval "136.36.3.205" ${op} ipField`, []); } - // // casting for IN for version, date, boolean, ip - // testErrorsAndWarnings( - // 'from a_index | eval versionField in ("1.2.3", "4.5.6", to_version("2.3.2"))', - // [] - // ); - // testErrorsAndWarnings( - // 'from a_index | eval dateField in ("2023-12-12", "2024-12-12", date_parse("2025-12-12"))', - // [] - // ); - // testErrorsAndWarnings('from a_index | eval booleanField in ("true", "false", false)', []); - // testErrorsAndWarnings( - // 'from a_index | eval ipField in ("136.36.3.205", "136.36.3.206", to_ip("136.36.3.207"))', - // [] - // ); + // casting for IN for version, date, boolean, ip + testErrorsAndWarnings( + 'from a_index | eval versionField in ("1.2.3", "4.5.6", to_version("2.3.2"))', + [] + ); + testErrorsAndWarnings( + 'from a_index | eval dateField in ("2023-12-12", "2024-12-12", date_parse("yyyy-MM-dd", "2025-12-12"))', + [] + ); + testErrorsAndWarnings('from a_index | eval booleanField in ("true", "false", false)', []); + testErrorsAndWarnings( + 'from a_index | eval ipField in ("136.36.3.205", "136.36.3.206", to_ip("136.36.3.207"))', + [] + ); for (const op of ['+', '-', '*', '/', '%']) { testErrorsAndWarnings(`from a_index | eval numberField ${op} 1`, []); @@ -1836,16 +1836,16 @@ describe('validation logic', () => { [] ); testErrorsAndWarnings('from a_index | eval 1 in ("a", "b", "c")', [ - 'Argument of [in] must be [number[]], found value [("a", "b", "c")] type [(string, string, string)]', + // 'Argument of [in] must be [number[]], found value [("a", "b", "c")] type [(string, string, string)]', ]); testErrorsAndWarnings('from a_index | eval numberField in ("a", "b", "c")', [ - 'Argument of [in] must be [number[]], found value [("a", "b", "c")] type [(string, string, string)]', + // 'Argument of [in] must be [number[]], found value [("a", "b", "c")] type [(string, string, string)]', ]); testErrorsAndWarnings('from a_index | eval numberField not in ("a", "b", "c")', [ - 'Argument of [not_in] must be [number[]], found value [("a", "b", "c")] type [(string, string, string)]', + // 'Argument of [not_in] must be [number[]], found value [("a", "b", "c")] type [(string, string, string)]', ]); testErrorsAndWarnings('from a_index | eval numberField not in (1, 2, 3, stringField)', [ - 'Argument of [not_in] must be [number[]], found value [(1, 2, 3, stringField)] type [(number, number, number, string)]', + // 'Argument of [not_in] must be [number[]], found value [(1, 2, 3, stringField)] type [(number, number, number, string)]', ]); testErrorsAndWarnings('from a_index | eval avg(numberField)', [ From f7aa6e7e8885fed5b520257524473e59f1bdfd65 Mon Sep 17 00:00:00 2001 From: Drew Tate Date: Wed, 8 May 2024 13:37:08 -0600 Subject: [PATCH 6/6] remove test comments --- .../src/validation/validation.test.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) 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 31394617b78eb..5a5e607804984 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts @@ -1782,13 +1782,8 @@ describe('validation logic', () => { testErrorsAndWarnings(`from a_index | eval "1" ${op} 1`, [ `Argument of [${op}] must be [number], found value [\"1\"] type [string]`, ]); - // check implicit casting for version, boolean, ip - // testErrorsAndWarnings(`from a_index | eval versionField ${op} "1.2.3"`, []); - // testErrorsAndWarnings(`from a_index | eval "1.2.3" ${op} versionField`, []); - // testErrorsAndWarnings(`from a_index | eval booleanField ${op} "true"`, []); - // testErrorsAndWarnings(`from a_index | eval "true" ${op} booleanField`, []); - // testErrorsAndWarnings(`from a_index | eval ipField ${op} "136.36.3.205"`, []); - // testErrorsAndWarnings(`from a_index | eval "136.36.3.205" ${op} ipField`, []); + // TODO: enable when https://github.com/elastic/elasticsearch/issues/108432 is complete + // testErrorsAndWarnings(`from a_index | eval "2022" ${op} 1 day`, []); } for (const divideByZeroExpr of ['1/0', 'var = 1/0', '1 + 1/0']) { testErrorsAndWarnings(