2017-03-29 20:43:20 +02:00
< query-editor-row query-ctrl = "ctrl" can-collapse = "false" >
2017-08-08 18:42:26 +03:00
< div class = "gf-form-inline" >
< div class = "gf-form gf-form--grow" >
2017-09-14 20:30:01 +02:00
< code-editor content = "ctrl.target.rawSql" datasource = "ctrl.datasource" on-change = "ctrl.panelCtrl.refresh()" data-mode = "sql" >
2017-08-08 18:42:26 +03:00
< / code-editor >
2017-03-29 20:43:20 +02:00
< / div >
< / div >
2017-03-31 11:45:25 +02:00
< div class = "gf-form-inline" >
< div class = "gf-form" >
< label class = "gf-form-label query-keyword" > Format as< / label >
< div class = "gf-form-select-wrapper" >
2017-04-20 17:10:09 +02:00
< select class = "gf-form-input gf-size-auto" ng-model = "ctrl.target.format" ng-options = "f.value as f.text for f in ctrl.formats" ng-change = "ctrl.refresh()" > < / select >
2017-03-31 11:45:25 +02:00
< / div >
< / div >
2017-04-21 15:52:42 +02:00
< div class = "gf-form" >
< label class = "gf-form-label query-keyword" ng-click = "ctrl.showHelp = !ctrl.showHelp" >
Show Help
< i class = "fa fa-caret-down" ng-show = "ctrl.showHelp" > < / i >
< i class = "fa fa-caret-right" ng-hide = "ctrl.showHelp" > < / i >
< / label >
2017-03-31 11:45:25 +02:00
< / div >
2017-04-21 15:07:43 +02:00
< div class = "gf-form" ng-show = "ctrl.lastQueryMeta" >
2017-04-20 17:10:09 +02:00
< label class = "gf-form-label query-keyword" ng-click = "ctrl.showLastQuerySQL = !ctrl.showLastQuerySQL" >
Generated SQL
< i class = "fa fa-caret-down" ng-show = "ctrl.showLastQuerySQL" > < / i >
< i class = "fa fa-caret-right" ng-hide = "ctrl.showLastQuerySQL" > < / i >
< / label >
< / div >
2017-04-21 15:07:43 +02:00
< div class = "gf-form gf-form--grow" >
2017-04-20 17:10:09 +02:00
< div class = "gf-form-label gf-form-label--grow" > < / div >
< / div >
2017-04-21 15:07:43 +02:00
< / div >
2017-04-20 17:10:09 +02:00
2017-04-21 15:52:42 +02:00
< div class = "gf-form" ng-show = "ctrl.showLastQuerySQL" >
< pre class = "gf-form-pre" > {{ctrl.lastQueryMeta.sql}}< / pre >
< / div >
< div class = "gf-form" ng-show = "ctrl.showHelp" >
< pre class = "gf-form-pre alert alert-info" > Time series:
- return column named time_sec (UTC in seconds), use UNIX_TIMESTAMP(column)
- return column named value for the time point value
- return column named metric to represent the series name
Table:
- return any set of columns
Macros:
- $__time(column) -> UNIX_TIMESTAMP(column) as time_sec
2017-06-08 14:36:05 -07:00
- $__timeFilter(column) -> UNIX_TIMESTAMP(time_date_time) ≥ 1492750877 AND UNIX_TIMESTAMP(time_date_time) ≤ 1492750877
- $__unixEpochFilter(column) -> time_unix_epoch > 1492750877 AND time_unix_epoch < 1492750877
2017-10-27 11:26:25 +02:00
- $__timeGroup(column,'5m') -> cast(cast(UNIX_TIMESTAMP(column)/(300) as signed)*300 as signed)
Example of group by and order by with $__timeGroup:
SELECT
$__timeGroup(timestamp_col, '1h') AS time,
sum(value_double) as value
FROM yourtable
GROUP BY 1
ORDER BY 1
2017-06-08 14:36:05 -07:00
Or build your own conditionals using these macros which just return the values:
- $__timeFrom() -> FROM_UNIXTIME(1492750877)
- $__timeTo() -> FROM_UNIXTIME(1492750877)
- $__unixEpochFrom() -> 1492750877
- $__unixEpochTo() -> 1492750877
2017-04-21 15:52:42 +02:00
< / pre >
< / div >
< / div >
< div class = "gf-form" ng-show = "ctrl.lastQueryError" >
< pre class = "gf-form-pre alert alert-error" > {{ctrl.lastQueryError}}< / pre >
< / div >
2017-04-20 17:10:09 +02:00
2017-03-29 20:43:20 +02:00
< / query-editor-row >