> ## 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 クエリを評価します。

# prometheusQuery

TimeSeriesテーブルのデータを使用して Prometheus クエリを評価します。

<div id="syntax">
  ## 構文
</div>

```sql theme={null}
prometheusQuery('db_name', 'time_series_table', 'promql_query', evaluation_time)
prometheusQuery(db_name.time_series_table, 'promql_query', evaluation_time)
prometheusQuery('time_series_table', 'promql_query', evaluation_time)
```

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

* `db_name` - TimeSeries テーブルが配置されているデータベース名。
* `time_series_table` - TimeSeries テーブルの名前。
* `promql_query` - [PromQL 構文](https://prometheus.io/docs/prometheus/latest/querying/basics/)で記述されたクエリ。
* `evaluation_time - 評価時刻のタイムスタンプ。現在時刻でクエリを評価するには、`evaluation\_time`として`now()\` を使用します。

<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>

インスタントセレクタ、レンジセレクタ、ラベルマッチャー (`=`、`!=`、`=~`、`!~`) 、OFFSET修飾子、`@`タイムスタンプ修飾子、サブクエリ。

<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`   |
| DateTime | `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, ...)` のようにステップごとに変化する式は、`NOT_IMPLEMENTED` エラーで拒否されます。

<div id="operators">
  ### 演算子
</div>

`on()`/`ignoring()` および `group_left()`/`group_right()` 修飾子を含む、すべての算術 (`+`, `-`, `*`, `/`, `%`, `^`) 、比較 (省略可能な `bool` を伴う `==`, `!=`, `<`, `>`, `<=`, `>=`) 、論理 (`and`, `or`, `unless`) 二項演算子。

単項演算子 `+` と `-`。

<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 prometheusQuery(mytable, 'rate(http_requests{job="prometheus"}[10m])[1h:10m]', now())
```
