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

> 지정된 그리드에서 시계열 데이터의 PromQL과 유사한 rate를 계산하는 집계 함수입니다.

# timeSeriesRateToGrid

<div id="timeSeriesRateToGrid">
  ## timeSeriesRateToGrid
</div>

도입 버전: v25.6.0

타임스탬프와 값의 쌍으로 이루어진 시계열 데이터를 입력받아, 시작 타임스탬프, 종료 타임스탬프, 간격으로 정의된 규칙적인 시간 그리드에서 이 데이터의 [PromQL과 유사한 rate](https://prometheus.io/docs/prometheus/latest/querying/functions/#rate)를 계산하는 집계 함수입니다. 그리드의 각 지점에 대해 `rate` 계산에 사용할 샘플은 지정된 시간 윈도우 내에서 고려됩니다.

<Warning>
  이 함수는 실험적 기능이므로 `allow_experimental_ts_to_grid_aggregate_function=true`를 설정하여 활성화하십시오.
</Warning>

**구문**

```sql theme={null}
timeSeriesRateToGrid(start_timestamp, end_timestamp, grid_step, staleness)(timestamp, value)
```

**매개변수**

* `start_timestamp` — 그리드의 시작 시점을 지정합니다. [`UInt32`](/ko/reference/data-types/int-uint) 또는 [`DateTime`](/ko/reference/data-types/datetime)
* `end_timestamp` — 그리드의 종료 시점을 지정합니다. [`UInt32`](/ko/reference/data-types/int-uint) 또는 [`DateTime`](/ko/reference/data-types/datetime)
* `grid_step` — 그리드의 간격을 초 단위로 지정합니다. [`UInt32`](/ko/reference/data-types/int-uint)
* `staleness` — 고려할 샘플의 최대 허용 지연 시간을 초 단위로 지정합니다. staleness 윈도우는 왼쪽이 열린 구간, 오른쪽이 닫힌 구간입니다. [`UInt32`](/ko/reference/data-types/int-uint)

**인수**

* `timestamp` — 샘플의 timestamp입니다. 단일 값 또는 배열일 수 있습니다. [`UInt32`](/ko/reference/data-types/int-uint) 또는 [`DateTime`](/ko/reference/data-types/datetime) 또는 [`Array(UInt32)`](/ko/reference/data-types/array) 또는 [`Array(DateTime)`](/ko/reference/data-types/array)
* `value` — timestamp에 해당하는 시계열 값입니다. 단일 값 또는 배열일 수 있습니다. [`Float*`](/ko/reference/data-types/float) 또는 [`Array(Float*)`](/ko/reference/data-types/array)

**반환 값**

지정한 그리드의 rate 값을 반환합니다. 반환되는 배열에는 각 시간 그리드 지점마다 하나의 값이 포함됩니다. 특정 그리드 지점의 rate 값을 계산하기에 윈도우 내 샘플이 충분하지 않으면 해당 값은 NULL입니다. [`Array(Nullable(Float64))`](/ko/reference/data-types/array)

**예시**

**개별 timestamp-value 쌍을 사용한 기본 사용법**

```sql title=Query theme={null}
WITH
    -- 참고: 140과 190 사이의 간격은 window 매개변수에 따라 ts = 150, 165, 180의 값이 어떻게 채워지는지 보여줍니다
    [110, 120, 130, 140, 190, 200, 210, 220, 230]::Array(DateTime) AS timestamps,
    [1, 1, 3, 4, 5, 5, 8, 12, 13]::Array(Float32) AS values, -- 위 타임스탬프에 대응하는 값 배열
    90 AS start_ts,       -- 타임스탬프 그리드 시작
    90 + 120 AS end_ts,   -- 타임스탬프 그리드 끝
    15 AS step_seconds,   -- 타임스탬프 그리드 간격
    45 AS window_seconds  -- "staleness" 윈도우
SELECT timeSeriesRateToGrid(start_ts, end_ts, step_seconds, window_seconds)(timestamp, value)
FROM
(
    -- 이 서브쿼리는 타임스탬프와 값의 배열을 `timestamp`, `value` 행으로 변환합니다
    SELECT
        arrayJoin(arrayZip(timestamps, values)) AS ts_and_val,
        ts_and_val.1 AS timestamp,
        ts_and_val.2 AS value
);
```

```response title=Response theme={null}
┌─timeSeriesRateToGrid(start_ts, end_ts, step_seconds, window_seconds)(timestamp, value)─┐
│ [NULL,NULL,0,0.06666667,0.1,0.083333336,NULL,NULL,0.083333336]                        │
└───────────────────────────────────────────────────────────────────────────────────────┘
```

**배열 인수 사용하기**

```sql title=Query theme={null}
WITH
    [110, 120, 130, 140, 190, 200, 210, 220, 230]::Array(DateTime) AS timestamps,
    [1, 1, 3, 4, 5, 5, 8, 12, 13]::Array(Float32) AS values,
    90 AS start_ts,
    90 + 120 AS end_ts,
    15 AS step_seconds,
    45 AS window_seconds
SELECT timeSeriesRateToGrid(start_ts, end_ts, step_seconds, window_seconds)(timestamps, values);
```

```response title=Response theme={null}
┌─timeSeriesRateToGrid(start_ts, end_ts, step_seconds, window_seconds)(timestamps, values)─┐
│ [NULL,NULL,0,0.06666667,0.1,0.083333336,NULL,NULL,0.083333336]                          │
└─────────────────────────────────────────────────────────────────────────────────────────┘
```
