Skip to content

Commit

Permalink
[ES|QL] improve test case generator script (elastic#190441)
Browse files Browse the repository at this point in the history
## Summary

Fixes a bug I introduced in
elastic#189941

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
drewdaemon and elasticmachine authored Aug 15, 2024
1 parent da1db2c commit bb2cc70
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
SupportedDataType,
FunctionDefinition,
dataTypes,
isSupportedDataType,
fieldTypes,
isFieldType,
} from '../src/definitions/types';
import { FUNCTION_DESCRIBE_BLOCK_NAME } from '../src/validation/function_describe_block_name';
import { getMaxMinNumberOfParams } from '../src/validation/helpers';
Expand Down Expand Up @@ -1110,7 +1110,7 @@ function getFieldMapping(

return params.map(({ name: _name, type, constantOnly, literalOptions, ...rest }) => {
const typeString: string = type as string;
if (isSupportedDataType(typeString)) {
if (isFieldType(typeString)) {
if (useLiterals && literalOptions) {
return {
name: `"${literalOptions[0]}"`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31920,6 +31920,62 @@
],
"warning": []
},
{
"query": "from a_index | stats var = max(textField)",
"error": [
"Argument of [max] must be [double], found value [textField] type [text]"
],
"warning": []
},
{
"query": "from a_index | stats max(textField)",
"error": [
"Argument of [max] must be [double], found value [textField] type [text]"
],
"warning": []
},
{
"query": "from a_index | where max(textField)",
"error": [
"WHERE does not support function max"
],
"warning": []
},
{
"query": "from a_index | where max(textField) > 0",
"error": [
"WHERE does not support function max"
],
"warning": []
},
{
"query": "from a_index | eval var = max(textField)",
"error": [
"EVAL does not support function max"
],
"warning": []
},
{
"query": "from a_index | eval var = max(textField) > 0",
"error": [
"EVAL does not support function max"
],
"warning": []
},
{
"query": "from a_index | eval max(textField)",
"error": [
"EVAL does not support function max"
],
"warning": []
},
{
"query": "from a_index | eval max(textField) > 0",
"error": [
"EVAL does not support function max"
],
"warning": []
},
{
"query": "from a_index | stats var = min(doubleField)",
"error": [],
Expand Down Expand Up @@ -32504,6 +32560,62 @@
],
"warning": []
},
{
"query": "from a_index | stats var = min(textField)",
"error": [
"Argument of [min] must be [double], found value [textField] type [text]"
],
"warning": []
},
{
"query": "from a_index | stats min(textField)",
"error": [
"Argument of [min] must be [double], found value [textField] type [text]"
],
"warning": []
},
{
"query": "from a_index | where min(textField)",
"error": [
"WHERE does not support function min"
],
"warning": []
},
{
"query": "from a_index | where min(textField) > 0",
"error": [
"WHERE does not support function min"
],
"warning": []
},
{
"query": "from a_index | eval var = min(textField)",
"error": [
"EVAL does not support function min"
],
"warning": []
},
{
"query": "from a_index | eval var = min(textField) > 0",
"error": [
"EVAL does not support function min"
],
"warning": []
},
{
"query": "from a_index | eval min(textField)",
"error": [
"EVAL does not support function min"
],
"warning": []
},
{
"query": "from a_index | eval min(textField) > 0",
"error": [
"EVAL does not support function min"
],
"warning": []
},
{
"query": "from a_index | stats var = count(textField)",
"error": [],
Expand Down Expand Up @@ -34937,6 +35049,42 @@
],
"warning": []
},
{
"query": "from a_index | stats by bucket(dateField, textField)",
"error": [
"Argument of [bucket] must be a constant, received [textField]"
],
"warning": []
},
{
"query": "from a_index | stats by bin(dateField, textField)",
"error": [
"Argument of [bin] must be a constant, received [textField]"
],
"warning": []
},
{
"query": "from a_index | sort bucket(dateField, textField)",
"error": [
"SORT does not support function bucket"
],
"warning": []
},
{
"query": "from a_index | stats bucket(\"2022\", textField)",
"error": [
"Argument of [bucket] must be a constant, received [textField]"
],
"warning": []
},
{
"query": "from a_index | stats bucket(concat(\"20\", \"22\"), textField)",
"error": [
"Argument of [bucket] must be [date], found value [concat(\"20\",\"22\")] type [keyword]",
"Argument of [bucket] must be a constant, received [textField]"
],
"warning": []
},
{
"query": "from a_index | stats var = percentile(doubleField, doubleField)",
"error": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12284,6 +12284,38 @@ describe('validation logic', () => {
testErrorsAndWarnings('from a_index | stats max(concat("20", "22"))', [
'Argument of [max] must be [double], found value [concat("20","22")] type [keyword]',
]);

testErrorsAndWarnings('from a_index | stats var = max(textField)', [
'Argument of [max] must be [double], found value [textField] type [text]',
]);

testErrorsAndWarnings('from a_index | stats max(textField)', [
'Argument of [max] must be [double], found value [textField] type [text]',
]);

testErrorsAndWarnings('from a_index | where max(textField)', [
'WHERE does not support function max',
]);

testErrorsAndWarnings('from a_index | where max(textField) > 0', [
'WHERE does not support function max',
]);

testErrorsAndWarnings('from a_index | eval var = max(textField)', [
'EVAL does not support function max',
]);

testErrorsAndWarnings('from a_index | eval var = max(textField) > 0', [
'EVAL does not support function max',
]);

testErrorsAndWarnings('from a_index | eval max(textField)', [
'EVAL does not support function max',
]);

testErrorsAndWarnings('from a_index | eval max(textField) > 0', [
'EVAL does not support function max',
]);
});

describe('min', () => {
Expand Down Expand Up @@ -12606,6 +12638,38 @@ describe('validation logic', () => {
testErrorsAndWarnings('from a_index | stats min(concat("20", "22"))', [
'Argument of [min] must be [double], found value [concat("20","22")] type [keyword]',
]);

testErrorsAndWarnings('from a_index | stats var = min(textField)', [
'Argument of [min] must be [double], found value [textField] type [text]',
]);

testErrorsAndWarnings('from a_index | stats min(textField)', [
'Argument of [min] must be [double], found value [textField] type [text]',
]);

testErrorsAndWarnings('from a_index | where min(textField)', [
'WHERE does not support function min',
]);

testErrorsAndWarnings('from a_index | where min(textField) > 0', [
'WHERE does not support function min',
]);

testErrorsAndWarnings('from a_index | eval var = min(textField)', [
'EVAL does not support function min',
]);

testErrorsAndWarnings('from a_index | eval var = min(textField) > 0', [
'EVAL does not support function min',
]);

testErrorsAndWarnings('from a_index | eval min(textField)', [
'EVAL does not support function min',
]);

testErrorsAndWarnings('from a_index | eval min(textField) > 0', [
'EVAL does not support function min',
]);
});

describe('count', () => {
Expand Down Expand Up @@ -14564,6 +14628,26 @@ describe('validation logic', () => {
'Argument of [bin] must be a constant, received [longField]',
]
);

testErrorsAndWarnings('from a_index | stats by bucket(dateField, textField)', [
'Argument of [bucket] must be a constant, received [textField]',
]);

testErrorsAndWarnings('from a_index | stats by bin(dateField, textField)', [
'Argument of [bin] must be a constant, received [textField]',
]);

testErrorsAndWarnings('from a_index | sort bucket(dateField, textField)', [
'SORT does not support function bucket',
]);

testErrorsAndWarnings('from a_index | stats bucket("2022", textField)', [
'Argument of [bucket] must be a constant, received [textField]',
]);
testErrorsAndWarnings('from a_index | stats bucket(concat("20", "22"), textField)', [
'Argument of [bucket] must be [date], found value [concat("20","22")] type [keyword]',
'Argument of [bucket] must be a constant, received [textField]',
]);
});

describe('percentile', () => {
Expand Down

0 comments on commit bb2cc70

Please sign in to comment.