> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8c05c8a2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 使用 TimeSeries 表中的数据，在一段评估时间范围内对 prometheus 查询求值。

# prometheusQueryRange

使用 TimeSeries 表中的数据，在一段评估时间范围内对 prometheus 查询求值。

<div id="syntax">
  ## 语法
</div>

```sql theme={null}
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)
```

<div id="arguments">
  ## 参数
</div>

* `db_name` - TimeSeries 表所在的数据库名称。
* `time_series_table` - TimeSeries 表的名称。
* `promql_query` - 按 [PromQL 语法](https://prometheus.io/docs/prometheus/latest/querying/basics/) 编写的查询。
* `start_time` - 评估范围的起始时间。
* `end_time` - 评估范围的结束时间。
* `step` - 用于将评估时间从 `start_time` 逐步推进到 `end_time` (含两端) 的步长。

<div id="returned_value">
  ## 返回值
</div>

该函数会根据传递给参数 `promql_query` 的查询结果类型，返回不同的列：

| 结果类型   | 结果列                                                                                    | 示例                                  |
| ------ | -------------------------------------------------------------------------------------- | ----------------------------------- |
| vector | tags Array(Tuple(String, String)), timestamp TimestampType, value ValueType            | prometheusQuery(mytable, 'up')      |
| matrix | tags Array(Tuple(String, String)), time\_series Array(Tuple(TimestampType, ValueType)) | prometheusQuery(mytable, 'up\[1m]') |
| scalar | scalar ValueType                                                                       | prometheusQuery(mytable, '1h30m')   |
| string | string String                                                                          | prometheusQuery(mytable, '"abc"')   |

<div id="supported-promql-features">
  ## 支持的 PromQL 特性
</div>

<div id="selectors">
  ### 选择器
</div>

即时选择器、范围选择器、标签匹配器 (`=`、`!=`、`=~`、`!~`) 、偏移修饰符、`@` 时间戳修饰符，以及子查询。

<div id="functions">
  ### 函数
</div>

| 类别   | 函数                                                                                               |
| ---- | ------------------------------------------------------------------------------------------------ |
| 范围   | `rate`, `irate`, `delta`, `idelta`, `last_over_time`                                             |
| 数学   | `abs`, `sgn`, `floor`, `ceil`, `sqrt`, `exp`, `ln`, `log2`, `log10`, `rad`, `deg`                |
| 三角函数 | `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `sinh`, `cosh`, `tanh`, `asinh`, `acosh`, `atanh`   |
| 日期时间 | `day_of_week`, `day_of_month`, `days_in_month`, `day_of_year`, `minute`, `hour`, `month`, `year` |
| 类型   | `scalar`, `vector`                                                                               |
| 直方图  | `histogram_quantile`                                                                             |
| 其他   | `time`, `pi`                                                                                     |

**注意**：`histogram_quantile` 在经典直方图桶 (由 `le` 标签标识) 上使用线性插值。原生直方图暂不受支持，并且 `phi` (分位数级别) 参数目前必须是常量标量——像 `histogram_quantile(time() / 1000, ...)` 这样在每个 step 上都会变化的表达式，会因 `NOT_IMPLEMENTED` 错误而被拒绝。

<div id="operators">
  ### 运算符
</div>

所有算术 (`+`、`-`、`*`、`/`、`%`、`^`) 、比较 (`==`、`!=`、`<`、`>`、`<=`、`>=`，可选 `bool`) 和逻辑 (`and`、`or`、`unless`) 二元运算符，以及 `on()`/`ignoring()` 和 `group_left()`/`group_right()` 修饰符。

一元运算符 `+` 和 `-`。

<div id="aggregation-operators">
  ### 聚合运算符
</div>

`sum`, `avg`, `min`, `max`, `count`, `stddev`, `stdvar`, `group`, `quantile`, `topk`, `bottomk`, `limitk` —— 可选搭配 `by()` 或 `without()` 修饰符。

暂不支持：`count_values`。

<div id="example">
  ## 示例
</div>

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