Skip to main content
Skip to main content

prometheusQueryRange

Evaluates a prometheus query using data from a TimeSeries table over a range of evaluation times.

Syntax

prometheusQueryRange('db_name', 'time_series_table', 'promql_query', start_time, end_time, step)
prometheusQueryRange(db_name.time_series_table, 'promql_query', start_time, end_time, step)
prometheusQueryRange('time_series_table', 'promql_query', start_time, end_time, step)

Arguments

  • db_name - The name of the database where a TimeSeries table is located.
  • time_series_table - The name of a TimeSeries table.
  • promql_query - A query written in PromQL syntax.
  • start_time - The start time of the evaluation range.
  • end_time - The end time of the evaluation range.
  • step - The step used to iterate the evaluation time from start_time to end_time (inclusively).

Returned value

The function can returns different columns depending on the result type of the query passed to parameter promql_query:

Result TypeResult ColumnsExample
vectortags Array(Tuple(String, String)), timestamp TimestampType, value ValueTypeprometheusQuery(mytable, 'up')
matrixtags Array(Tuple(String, String)), time_series Array(Tuple(TimestampType, ValueType))prometheusQuery(mytable, 'up[1m]')
scalarscalar ValueTypeprometheusQuery(mytable, '1h30m')
stringstring StringprometheusQuery(mytable, '"abc"')

Supported PromQL Features

Selectors

Instant selectors, range selectors, label matchers (=, !=, =~, !~), offset modifiers, @ timestamp modifiers, and subqueries.

Functions

CategoryFunctions
Rangerate, irate, delta, idelta, last_over_time
Mathabs, sgn, floor, ceil, sqrt, exp, ln, log2, log10, rad, deg
Trigsin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh
DateTimeday_of_week, day_of_month, days_in_month, day_of_year, minute, hour, month, year
Typescalar, vector
Histogramhistogram_quantile
Othertime, pi

Note: histogram_quantile uses linear interpolation on classic histogram buckets (identified by the le label). Native histograms are not yet supported, and the phi (quantile level) argument must currently be a constant scalar — expressions that vary per step such as histogram_quantile(time() / 1000, ...) are rejected with a NOT_IMPLEMENTED error.

Operators

All arithmetic (+, -, *, /, %, ^), comparison (==, !=, <, >, <=, >= with optional bool), and logical (and, or, unless) binary operators, with on()/ignoring() and group_left()/group_right() modifiers.

Unary operators + and -.

Aggregation Operators

sum, avg, min, max, count, stddev, stdvar, group, quantile, topk, bottomk, limitk — with optional by() or without() modifiers.

Not yet supported: count_values.

Example

SELECT * FROM prometheusQueryRange(mytable, 'rate(http_requests{job="prometheus"}[10m])[1h:10m]', now() - INTERVAL 10 MINUTES, now(), INTERVAL 1 MINUTE)