diff --git a/cspell.config.json b/cspell.config.json index c8e9fbeb..9699c674 100644 --- a/cspell.config.json +++ b/cspell.config.json @@ -57,6 +57,7 @@ "TINYINT", "tokenprovider", "typecheck", + "UNIXTIME", "uuidv", "vectorator" ], diff --git a/src/components/query-editor-raw/bigqueryCompletionProvider.ts b/src/components/query-editor-raw/bigqueryCompletionProvider.ts index 7e733d82..970acdb5 100644 --- a/src/components/query-editor-raw/bigqueryCompletionProvider.ts +++ b/src/components/query-editor-raw/bigqueryCompletionProvider.ts @@ -15,6 +15,7 @@ import { import { PartitioningType, TableSchema } from 'api'; import { BQ_AGGREGATE_FNS } from './bigQueryFunctions'; import { BQ_OPERATORS } from './bigQueryOperators'; +import { MACROS } from './macros'; interface CompletionProviderGetterArgs { getColumns: React.MutableRefObject<(t: string) => Promise>; @@ -56,6 +57,7 @@ export const getBigQueryCompletionProvider: (args: CompletionProviderGetterArgs) supportedOperators: () => BQ_OPERATORS, customSuggestionKinds: customSuggestionKinds(getTables, getTableSchema), customStatementPlacement, + supportedMacros: () => MACROS, }); export enum CustomStatementPlacement { diff --git a/src/components/query-editor-raw/macros.ts b/src/components/query-editor-raw/macros.ts new file mode 100644 index 00000000..c9cba648 --- /dev/null +++ b/src/components/query-editor-raw/macros.ts @@ -0,0 +1,40 @@ +import { MacroType } from '@grafana/experimental'; + +export const MACROS = [ + { + id: '$__timeFilter(dateColumn)', + name: '$__timeFilter(dateColumn)', + text: '$__timeFilter', + args: ['dateColumn'], + type: MacroType.Filter, + description: + 'Will be replaced by a time range filter using the specified column name. For example, dateColumn BETWEEN FROM_UNIXTIME(1494410783) AND FROM_UNIXTIME(1494410983)', + }, + { + id: '$__timeFrom()', + name: '$__timeFrom()', + text: '$__timeFrom', + args: [], + type: MacroType.Filter, + description: + 'Will be replaced by the start of the currently active time selection. For example, FROM_UNIXTIME(1494410783)', + }, + { + id: '$__timeTo()', + name: '$__timeTo()', + text: '$__timeTo', + args: [], + type: MacroType.Filter, + description: + 'Will be replaced by the end of the currently active time selection. For example, FROM_UNIXTIME(1494410983)', + }, + { + id: "$__timeGroup(dateColumn, '5m')", + name: "$__timeGroup(dateColumn, '5m')", + text: '$__timeGroup', + args: ['dateColumn', "'5m'"], + type: MacroType.Value, + description: + 'Will be replaced by an expression usable in GROUP BY clause. For example, *cast(cast(UNIX_TIMESTAMP(dateColumn)/(300) as signed)*300 as signed),*', + }, +];