influxdata / influxdata/docs-v2

Provide examples using `time` and aggregate functions in Grafana

Open
#4,838 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
82
Forks
326
Avg merge
1d 1h
Merged PRs (30d)
82

Description

> You can group by columns other than time.

@sanderson True, but Grafana specifically requires a `time` column in the result and Flight SQL (or IOx?) doesn't know how to resolve `iox.[measurement].time` unless you group or partition by time. At least, as far as I can tell.

```sql
-- This works in Grafana:
-- SELECT avg(temp) OVER(PARTITION BY DATE_BIN(INTERVAL '2 hours', time, '1970-01-01T00:00:00Z'::TIMESTAMP)) AS AvgTemp,
-- DATE_BIN(INTERVAL '2 hours', time, '1970-01-01T00:00:00Z'::TIMESTAMP) AS time
-- FROM iox.home

-- So does this:
-- SELECT avg(temp) AS AvgTemp, DATE_BIN(INTERVAL '2 hours', time, '1970-01-01T00:00:00Z'::TIMESTAMP) as time
-- FROM iox.home
-- GROUP BY DATE_BIN(INTERVAL '2 hours', time, '1970-01-01T00:00:00Z'::TIMESTAMP)

-- Grafana doesn't like this; it wants a time column. It works in Superset and other clients.
-- SELECT avg(temp)
-- FROM iox.home

-- IOx (SQL) doesn't like this, as in "what time value am I supposed to return?".
-- SELECT DATE_BIN(INTERVAL '2 hours', time, '1970-01-01T00:00:00Z'::TIMESTAMP) as time, avg(temp) AS AvgTemp
-- FROM iox.home
```

Contributor guide

No contributing guide indexed for this repository

Research direction

No documentation file or test is named in the issue. Start by reviewing the existing SQL and Grafana documentation for query examples, then add examples covering time columns and aggregate functions; done means the examples explain the expected query shape for Grafana and other clients.

Written by the indexing model from the issue text.

Assessment

Tech stack
grafana, sql
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.