tiler-project / tiler

Plugable dashboard framework
MIT License
1 stars 0 forks source link

Improve the query language #1

Open simondean opened 8 years ago

simondean commented 8 years ago

Current query language looks like this:

{
  metric: {label: {'name': {$replace: {$pattern: '(One)', $replacement: 'Hello $1'}}}},
  point: {time: 'time', value: {value: '$mean'}},
  from: 'examples.random-numbers',
  where: {time: {$gte: {$minus: ['$now', '5m']}}, name: {$regex: {$pattern: '^One|Two|Three|Four$'}}},
  group: ['name'],
  aggregate: {time: {$intervals: {$size: '10s', $offset: {$minus: ['$now', '5m']}}}}
}

It would be great to improve the language so that it is clearer which parts of a query apply to the metrics and which parts apply to the points.

From the example above, the follow parts apply to the metrics:

{
  metric: {label: {'name': {$replace: {$pattern: '(One)', $replacement: 'Hello $1'}}}},
  from: 'examples.random-numbers',
}

These parts apply to the points:

{
  point: {time: 'time', value: {value: '$mean'}},
  where: {time: {$gte: {$minus: ['$now', '5m']}}, name: {$regex: {$pattern: '^One|Two|Three|Four$'}}},
  group: ['name'],
  aggregate: {time: {$intervals: {$size: '10s', $offset: {$minus: ['$now', '5m']}}}}
}

Approach 1 could look like this:

{
  metrics: {
    select: {label: {'name': {$replace: {$pattern: '(One)', $replacement: 'Hello $1'}}}},
    from: 'examples.random-numbers',
  }
  points: {
    select: {time: 'time', value: {value: '$mean'}},
    where: {time: {$gte: {$minus: ['$now', '5m']}}, name: {$regex: {$pattern: '^One|Two|Three|Four$'}}},
    group: ['name'],
    aggregate: {time: {$intervals: {$size: '10s', $offset: {$minus: ['$now', '5m']}}}}
  }
}

Approach 2 could look like this:

FROM examples.random-numbers
WHERE time >= now() - 5m AND name ~= /^One|Two|Three|Four$/
GROUP name
AGGREGATE intervals(time, 10s, now() - 5m)
POINT time, mean(value) AS value
METRIC replace(name, '(one)', 'Hello $1') AS label

Alternative names for AGGREGATE could be: COMBINE

Approach 3 could look like this:

from examples.random-numbers
where time >= now() - 5m and name ~= /^One|Two|Three|Four$/
group name
aggregate intervals(time, 10s, now() - 5m)
point time, mean(value) as value
metric replace(name, /(one)/, 'Hello $1') as label
simondean commented 8 years ago

New options:

Option 1

Sort clause under both the metric clause and the point clause.

from metric.name
where fieldName == 1
group fieldName
aggregate all() as all
metric fieldName
sort fieldName
point fieldName
sort fieldName

Option 2

Section names for metric and point clauses

metrics:
from metric.name
points:
where fieldName == 1
group fieldName
aggregate all() as all
metrics:
metric fieldName
points:
point fieldName
sort fieldName asc

Option 3

Include the words "metrics" and "points" in all the clause names.

from metrics metric.name
where points fieldName == 1
group points fieldName
aggregate points all() as all
select metrics fieldName
select points fieldName
sort metrics fieldName asc
sort points fieldName asc

Option 4

Include "metrics" and "points" in only some of the clause names.

from metric.name
where fieldName == 1
group fieldName
aggregate all() as all
select metric fieldName
select point fieldName
sort metric fieldName
sort point fieldName