diff --git a/packages/kbn-esql-validation-autocomplete/scripts/generate_function_validation_tests.ts b/packages/kbn-esql-validation-autocomplete/scripts/generate_function_validation_tests.ts index b7cc5c4481e660..0ace35433b67e3 100644 --- a/packages/kbn-esql-validation-autocomplete/scripts/generate_function_validation_tests.ts +++ b/packages/kbn-esql-validation-autocomplete/scripts/generate_function_validation_tests.ts @@ -15,7 +15,7 @@ import { statsAggregationFunctionDefinitions } from '../src/definitions/aggs'; import { evalFunctionDefinitions } from '../src/definitions/functions'; import { groupingFunctionDefinitions } from '../src/definitions/grouping'; import { getFunctionSignatures } from '../src/definitions/helpers'; -import { chronoLiterals, timeLiterals } from '../src/definitions/literals'; +import { timeUnits, chronoLiterals } from '../src/definitions/literals'; import { nonNullable } from '../src/shared/helpers'; import { SupportedFieldType, @@ -1046,7 +1046,7 @@ function getFieldName( const literals = { chrono_literal: chronoLiterals[0].name, - time_literal: timeLiterals[0].name, + time_literal: timeUnits[0], }; function getLiteralType(typeString: 'chrono_literal' | 'time_literal') { diff --git a/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts b/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts index 828511762a5f40..8edbcd54725934 100644 --- a/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts @@ -10,7 +10,7 @@ import { suggest } from './autocomplete'; import { evalFunctionDefinitions } from '../definitions/functions'; import { builtinFunctions } from '../definitions/builtin'; import { statsAggregationFunctionDefinitions } from '../definitions/aggs'; -import { chronoLiterals, timeLiterals } from '../definitions/literals'; +import { chronoLiterals, timeUnitsToSuggest } from '../definitions/literals'; import { commandDefinitions } from '../definitions/commands'; import { getUnitDuration, TRIGGER_SUGGESTION_COMMAND } from './factories'; import { camelCase, partition } from 'lodash'; @@ -203,7 +203,7 @@ function getLiteralsByType(_type: string | string[]) { const type = Array.isArray(_type) ? _type : [_type]; if (type.includes('time_literal')) { // return only singular - return timeLiterals.map(({ name }) => `1 ${name}`).filter((s) => !/s$/.test(s)); + return timeUnitsToSuggest.map(({ name }) => `1 ${name}`).filter((s) => !/s$/.test(s)); } if (type.includes('chrono_literal')) { return chronoLiterals.map(({ name }) => name); @@ -1238,7 +1238,7 @@ describe('autocomplete', () => { testSuggestions('from a | eval var0 = bucket(@timestamp,', getUnitDuration(1)); describe('date math', () => { - const dateSuggestions = timeLiterals.map(({ name }) => name); + const dateSuggestions = timeUnitsToSuggest.map(({ name }) => name); // If a literal number is detected then suggest also date period keywords testSuggestions('from a | eval a = 1 ', [ ...dateSuggestions, diff --git a/packages/kbn-esql-validation-autocomplete/src/autocomplete/factories.ts b/packages/kbn-esql-validation-autocomplete/src/autocomplete/factories.ts index 34c28b4b50d094..1bc93193bd39aa 100644 --- a/packages/kbn-esql-validation-autocomplete/src/autocomplete/factories.ts +++ b/packages/kbn-esql-validation-autocomplete/src/autocomplete/factories.ts @@ -12,7 +12,7 @@ import { groupingFunctionDefinitions } from '../definitions/grouping'; import { statsAggregationFunctionDefinitions } from '../definitions/aggs'; import { evalFunctionDefinitions } from '../definitions/functions'; import { getFunctionSignatures, getCommandSignature } from '../definitions/helpers'; -import { chronoLiterals, timeLiterals } from '../definitions/literals'; +import { chronoLiterals, timeUnitsToSuggest } from '../definitions/literals'; import { FunctionDefinition, CommandDefinition, @@ -298,7 +298,7 @@ export const buildNoPoliciesAvailableDefinition = (): SuggestionRawDefinition => }); export function getUnitDuration(unit: number = 1) { - const filteredTimeLiteral = timeLiterals.filter(({ name }) => { + const filteredTimeLiteral = timeUnitsToSuggest.filter(({ name }) => { const result = /s$/.test(name); return unit > 1 ? result : !result; }); @@ -332,7 +332,7 @@ export function getCompatibleLiterals(commandName: string, types: string[], name } // this is a special type built from the suggestion system, not inherited from the AST if (types.includes('time_literal_unit')) { - suggestions.push(...buildConstantsDefinitions(timeLiterals.map(({ name }) => name))); // i.e. year, month, ... + suggestions.push(...buildConstantsDefinitions(timeUnitsToSuggest.map(({ name }) => name))); // i.e. year, month, ... } if (types.includes('chrono_literal')) { suggestions.push(...buildConstantsDefinitions(chronoLiterals.map(({ name }) => name))); // i.e. EPOC_DAY, ... diff --git a/packages/kbn-esql-validation-autocomplete/src/definitions/literals.ts b/packages/kbn-esql-validation-autocomplete/src/definitions/literals.ts index 9369414378385b..45c41476f04e9a 100644 --- a/packages/kbn-esql-validation-autocomplete/src/definitions/literals.ts +++ b/packages/kbn-esql-validation-autocomplete/src/definitions/literals.ts @@ -9,7 +9,7 @@ import { i18n } from '@kbn/i18n'; import type { Literals } from './types'; -export const timeLiterals: Literals[] = [ +export const timeUnitsToSuggest: Literals[] = [ { name: 'year', description: i18n.translate( @@ -28,6 +28,24 @@ export const timeLiterals: Literals[] = [ } ), }, + { + name: 'quarter', + description: i18n.translate( + 'kbn-esql-validation-autocomplete.esql.definitions.dateDurationDefinition.quarter', + { + defaultMessage: 'Quarter', + } + ), + }, + { + name: 'quarters', + description: i18n.translate( + 'kbn-esql-validation-autocomplete.esql.definitions.dateDurationDefinition.quarters', + { + defaultMessage: 'Quarters (Plural)', + } + ), + }, { name: 'month', description: i18n.translate( @@ -156,6 +174,20 @@ export const timeLiterals: Literals[] = [ }, ]; +export const timeUnits: string[] = [ + ...timeUnitsToSuggest.map((literal) => literal.name), + 'ms', + 's', + 'm', + 'h', + 'd', + 'w', + 'mo', + 'q', + 'y', + 'yr', +]; + export const chronoLiterals: Literals[] = [ 'ALIGNED_DAY_OF_WEEK_IN_MONTH', 'ALIGNED_DAY_OF_WEEK_IN_YEAR', diff --git a/packages/kbn-esql-validation-autocomplete/src/shared/helpers.ts b/packages/kbn-esql-validation-autocomplete/src/shared/helpers.ts index b7ef6e0ba9e880..4a89a6b72d166e 100644 --- a/packages/kbn-esql-validation-autocomplete/src/shared/helpers.ts +++ b/packages/kbn-esql-validation-autocomplete/src/shared/helpers.ts @@ -24,7 +24,7 @@ import { commandDefinitions } from '../definitions/commands'; import { evalFunctionDefinitions } from '../definitions/functions'; import { groupingFunctionDefinitions } from '../definitions/grouping'; import { getFunctionSignatures } from '../definitions/helpers'; -import { chronoLiterals, timeLiterals } from '../definitions/literals'; +import { timeUnits, chronoLiterals } from '../definitions/literals'; import { byOption, metadataOption, @@ -376,7 +376,7 @@ export function getAllArrayTypes( } export function inKnownTimeInterval(item: ESQLTimeInterval): boolean { - return timeLiterals.some(({ name }) => name === item.unit.toLowerCase()); + return timeUnits.some((unit) => unit === item.unit.toLowerCase()); } /** 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 9b03737786c12c..0c84fe2bf113da 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 @@ -1052,6 +1052,136 @@ ], "warning": [] }, + { + "query": "row 1 quarter", + "error": [ + "ROW does not support [date_period] in expression [1 quarter]" + ], + "warning": [] + }, + { + "query": "row 1 quarter", + "error": [ + "ROW does not support [date_period] in expression [1 quarter]" + ], + "warning": [] + }, + { + "query": "row var = now() - 1 quarter", + "error": [], + "warning": [] + }, + { + "query": "row var = now() - 1 QUARTER", + "error": [], + "warning": [] + }, + { + "query": "row var = now() - 1 Quarter", + "error": [], + "warning": [] + }, + { + "query": "row var = now() + 1 quarter", + "error": [], + "warning": [] + }, + { + "query": "row 1 quarter + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 quarter] type [duration]" + ], + "warning": [] + }, + { + "query": "row var = now() * 1 quarter", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 quarter] type [duration]" + ], + "warning": [] + }, + { + "query": "row var = now() / 1 quarter", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 quarter] type [duration]" + ], + "warning": [] + }, + { + "query": "row var = now() % 1 quarter", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 quarter] type [duration]" + ], + "warning": [] + }, + { + "query": "row 1 quarters", + "error": [ + "ROW does not support [date_period] in expression [1 quarters]" + ], + "warning": [] + }, + { + "query": "row 1 quarters", + "error": [ + "ROW does not support [date_period] in expression [1 quarters]" + ], + "warning": [] + }, + { + "query": "row var = now() - 1 quarters", + "error": [], + "warning": [] + }, + { + "query": "row var = now() - 1 QUARTERS", + "error": [], + "warning": [] + }, + { + "query": "row var = now() - 1 Quarters", + "error": [], + "warning": [] + }, + { + "query": "row var = now() + 1 quarters", + "error": [], + "warning": [] + }, + { + "query": "row 1 quarters + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 quarters] type [duration]" + ], + "warning": [] + }, + { + "query": "row var = now() * 1 quarters", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 quarters] type [duration]" + ], + "warning": [] + }, + { + "query": "row var = now() / 1 quarters", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 quarters] type [duration]" + ], + "warning": [] + }, + { + "query": "row var = now() % 1 quarters", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 quarters] type [duration]" + ], + "warning": [] + }, { "query": "row 1 month", "error": [ @@ -6479,6 +6609,146 @@ ], "warning": [] }, + { + "query": "from a_index | eval 1 quarter", + "error": [ + "EVAL does not support [date_period] in expression [1 quarter]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 quarter", + "error": [ + "EVAL does not support [date_period] in expression [1 quarter]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() - 1 quarter", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 quarter", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 QUARTER", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 Quarter", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField + 1 quarter", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 quarter + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 quarter] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() * 1 quarter", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 quarter] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() / 1 quarter", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 quarter] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() % 1 quarter", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 quarter] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 quarters", + "error": [ + "EVAL does not support [date_period] in expression [1 quarters]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 quarters", + "error": [ + "EVAL does not support [date_period] in expression [1 quarters]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() - 1 quarters", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 quarters", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 QUARTERS", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 Quarters", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField + 1 quarters", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 quarters + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 quarters] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() * 1 quarters", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 quarters] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() / 1 quarters", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 quarters] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() % 1 quarters", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 quarters] type [duration]" + ], + "warning": [] + }, { "query": "from a_index | eval 1 month", "error": [ @@ -7459,6 +7729,706 @@ ], "warning": [] }, + { + "query": "from a_index | eval 1 ms", + "error": [ + "EVAL does not support [date_period] in expression [1 ms]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 ms", + "error": [ + "EVAL does not support [date_period] in expression [1 ms]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() - 1 ms", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 ms", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 MS", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 Ms", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField + 1 ms", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 ms + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 ms] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() * 1 ms", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 ms] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() / 1 ms", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 ms] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() % 1 ms", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 ms] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 s", + "error": [ + "EVAL does not support [date_period] in expression [1 s]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 s", + "error": [ + "EVAL does not support [date_period] in expression [1 s]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() - 1 s", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 s", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 S", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 S", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField + 1 s", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 s + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 s] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() * 1 s", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 s] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() / 1 s", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 s] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() % 1 s", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 s] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 m", + "error": [ + "EVAL does not support [date_period] in expression [1 m]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 m", + "error": [ + "EVAL does not support [date_period] in expression [1 m]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() - 1 m", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 m", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 M", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 M", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField + 1 m", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 m + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 m] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() * 1 m", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 m] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() / 1 m", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 m] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() % 1 m", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 m] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 h", + "error": [ + "EVAL does not support [date_period] in expression [1 h]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 h", + "error": [ + "EVAL does not support [date_period] in expression [1 h]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() - 1 h", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 h", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 H", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 H", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField + 1 h", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 h + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 h] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() * 1 h", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 h] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() / 1 h", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 h] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() % 1 h", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 h] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 d", + "error": [ + "EVAL does not support [date_period] in expression [1 d]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 d", + "error": [ + "EVAL does not support [date_period] in expression [1 d]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() - 1 d", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 d", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 D", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 D", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField + 1 d", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 d + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 d] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() * 1 d", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 d] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() / 1 d", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 d] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() % 1 d", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 d] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 w", + "error": [ + "EVAL does not support [date_period] in expression [1 w]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 w", + "error": [ + "EVAL does not support [date_period] in expression [1 w]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() - 1 w", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 w", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 W", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 W", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField + 1 w", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 w + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 w] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() * 1 w", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 w] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() / 1 w", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 w] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() % 1 w", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 w] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 mo", + "error": [ + "EVAL does not support [date_period] in expression [1 mo]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 mo", + "error": [ + "EVAL does not support [date_period] in expression [1 mo]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() - 1 mo", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 mo", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 MO", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 Mo", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField + 1 mo", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 mo + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 mo] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() * 1 mo", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 mo] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() / 1 mo", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 mo] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() % 1 mo", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 mo] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 q", + "error": [ + "EVAL does not support [date_period] in expression [1 q]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 q", + "error": [ + "EVAL does not support [date_period] in expression [1 q]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() - 1 q", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 q", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 Q", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 Q", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField + 1 q", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 q + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 q] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() * 1 q", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 q] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() / 1 q", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 q] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() % 1 q", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 q] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 y", + "error": [ + "EVAL does not support [date_period] in expression [1 y]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 y", + "error": [ + "EVAL does not support [date_period] in expression [1 y]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() - 1 y", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 y", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 Y", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 Y", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField + 1 y", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 y + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 y] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() * 1 y", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 y] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() / 1 y", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 y] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() % 1 y", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 y] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 yr", + "error": [ + "EVAL does not support [date_period] in expression [1 yr]" + ], + "warning": [] + }, + { + "query": "from a_index | eval 1 yr", + "error": [ + "EVAL does not support [date_period] in expression [1 yr]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() - 1 yr", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 yr", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 YR", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField - 1 Yr", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval var = dateField + 1 yr", + "error": [], + "warning": [] + }, + { + "query": "from a_index | eval 1 yr + 1 year", + "error": [ + "Argument of [+] must be [date], found value [1 yr] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() * 1 yr", + "error": [ + "Argument of [*] must be [number], found value [now()] type [date]", + "Argument of [*] must be [number], found value [1 yr] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() / 1 yr", + "error": [ + "Argument of [/] must be [number], found value [now()] type [date]", + "Argument of [/] must be [number], found value [1 yr] type [duration]" + ], + "warning": [] + }, + { + "query": "from a_index | eval var = now() % 1 yr", + "error": [ + "Argument of [%] must be [number], found value [now()] type [date]", + "Argument of [%] must be [number], found value [1 yr] type [duration]" + ], + "warning": [] + }, { "query": "from a_index | sort ", "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 86e8c216946f62..f866d82767890d 100644 --- a/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts +++ b/packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts @@ -12,7 +12,7 @@ import { ignoreErrorsMap, validateQuery } from './validation'; import { evalFunctionDefinitions } from '../definitions/functions'; import { getFunctionSignatures } from '../definitions/helpers'; import { FunctionDefinition, SupportedFieldType, supportedFieldTypes } from '../definitions/types'; -import { chronoLiterals, timeLiterals } from '../definitions/literals'; +import { chronoLiterals, timeUnits, timeUnitsToSuggest } from '../definitions/literals'; import { statsAggregationFunctionDefinitions } from '../definitions/aggs'; import capitalize from 'lodash/capitalize'; import { camelCase } from 'lodash'; @@ -59,7 +59,7 @@ const nestedFunctions = { const literals = { chrono_literal: chronoLiterals[0].name, - time_literal: timeLiterals[0].name, + time_literal: timeUnitsToSuggest[0].name, }; function getLiteralType(typeString: 'chrono_literal' | 'time_literal') { if (typeString === 'chrono_literal') { @@ -421,7 +421,7 @@ describe('validation logic', () => { ]); testErrorsAndWarnings('row var = 1 anno', ["Unexpected time interval qualifier: 'anno'"]); testErrorsAndWarnings('row now() + 1 anno', ["Unexpected time interval qualifier: 'anno'"]); - for (const timeLiteral of timeLiterals) { + for (const timeLiteral of timeUnitsToSuggest) { testErrorsAndWarnings(`row 1 ${timeLiteral.name}`, [ `ROW does not support [date_period] in expression [1 ${timeLiteral.name}]`, ]); @@ -1247,36 +1247,33 @@ describe('validation logic', () => { testErrorsAndWarnings('from a_index | eval now() + 1 anno', [ "Unexpected time interval qualifier: 'anno'", ]); - for (const timeLiteral of timeLiterals) { - testErrorsAndWarnings(`from a_index | eval 1 ${timeLiteral.name}`, [ - `EVAL does not support [date_period] in expression [1 ${timeLiteral.name}]`, + for (const unit of timeUnits) { + testErrorsAndWarnings(`from a_index | eval 1 ${unit}`, [ + `EVAL does not support [date_period] in expression [1 ${unit}]`, ]); - testErrorsAndWarnings(`from a_index | eval 1 ${timeLiteral.name}`, [ - `EVAL does not support [date_period] in expression [1 ${timeLiteral.name}]`, + testErrorsAndWarnings(`from a_index | eval 1 ${unit}`, [ + `EVAL does not support [date_period] in expression [1 ${unit}]`, ]); // this is not possible for now // testErrorsAndWarnings(`from a_index | eval var = 1 ${timeLiteral.name}`, [ // `Eval does not support [date_period] in expression [1 ${timeLiteral.name}]`, // ]); - testErrorsAndWarnings(`from a_index | eval var = now() - 1 ${timeLiteral.name}`, []); - testErrorsAndWarnings(`from a_index | eval var = dateField - 1 ${timeLiteral.name}`, []); + testErrorsAndWarnings(`from a_index | eval var = now() - 1 ${unit}`, []); + testErrorsAndWarnings(`from a_index | eval var = dateField - 1 ${unit}`, []); testErrorsAndWarnings( - `from a_index | eval var = dateField - 1 ${timeLiteral.name.toUpperCase()}`, + `from a_index | eval var = dateField - 1 ${unit.toUpperCase()}`, [] ); - testErrorsAndWarnings( - `from a_index | eval var = dateField - 1 ${capitalize(timeLiteral.name)}`, - [] - ); - testErrorsAndWarnings(`from a_index | eval var = dateField + 1 ${timeLiteral.name}`, []); - testErrorsAndWarnings(`from a_index | eval 1 ${timeLiteral.name} + 1 year`, [ - `Argument of [+] must be [date], found value [1 ${timeLiteral.name}] type [duration]`, + testErrorsAndWarnings(`from a_index | eval var = dateField - 1 ${capitalize(unit)}`, []); + testErrorsAndWarnings(`from a_index | eval var = dateField + 1 ${unit}`, []); + testErrorsAndWarnings(`from a_index | eval 1 ${unit} + 1 year`, [ + `Argument of [+] must be [date], found value [1 ${unit}] type [duration]`, ]); for (const op of ['*', '/', '%']) { - testErrorsAndWarnings(`from a_index | eval var = now() ${op} 1 ${timeLiteral.name}`, [ + testErrorsAndWarnings(`from a_index | eval var = now() ${op} 1 ${unit}`, [ `Argument of [${op}] must be [number], found value [now()] type [date]`, - `Argument of [${op}] must be [number], found value [1 ${timeLiteral.name}] type [duration]`, + `Argument of [${op}] must be [number], found value [1 ${unit}] type [duration]`, ]); } }