In order for :autoGroupBy: and :dashboardTime: to co-exist in a query,
it's necessary to introduce template variable precedence to the backend.
This is done by adding a `Precedence()` method to the TemplateVariable
interface that returns an ordinal indicating the precedence level of the
template variable. Precedence starts from 0 (highest) proceeding to the
maximum that a `uint` can represent.
A template variable at a given precedence level can expect that all
template variables with higher precedence will have already been
replaced in the query that is passed to its `Exec` call.
For example, :autoGroupBy: has lower precedence than :dashboardTime:
because it needs to know the selected time range for the query. When the
`Exec` method of `GroupByVar` is invoked, it will see the query after
:dashboardTime: has already been replaced, allowing it to extract the
duration successfully.
In order for automatic group by to be remotely useful, we need to parse
out the selected duration of time from the query itself. The problem
with doing this is that using the existing machinery for parsing
InfluxQL requires having valid InfluxQL, which InfluxQL+Template
Variables is not. To break this chicken-and-egg problem, the duration is
directly extracted from the query using regular string processing.