본문으로 바로가기
본문으로 바로가기

timeSeriesInstantRateToGrid

timeSeriesInstantRateToGrid

도입 버전: v25.6

타임스탬프와 값의 쌍으로 구성된 시계열 데이터를 입력으로 받아, 시작 타임스탬프, 종료 타임스탬프, 스텝(step)으로 정의되는 일정한 시간 그리드 상에서 이 데이터로부터 PromQL과 유사한 irate를 계산하는 집계 함수입니다. 그리드상의 각 지점마다 지정된 시간 구간 내의 샘플들을 사용하여 irate를 계산합니다.

참고

이 함수는 실험적 기능이므로, allow_experimental_ts_to_grid_aggregate_function=true로 설정하여 활성화해야 합니다.

구문

timeSeriesInstantRateToGrid(start_timestamp, end_timestamp, grid_step, staleness)(timestamp, value)

매개변수

  • start_timestamp — 그리드의 시작 시점을 지정합니다. UInt32 또는 DateTime
  • end_timestamp — 그리드의 종료 시점을 지정합니다. UInt32 또는 DateTime
  • grid_step — 그리드의 간격(초 단위)을 지정합니다. UInt32
  • staleness — 고려 대상 샘플의 최대 staleness(초 단위)를 지정합니다. staleness 윈도우는 왼쪽이 열린 구간, 오른쪽이 닫힌 구간입니다. UInt32

인수

반환 값

지정된 그리드에서 irate 값을 반환합니다. 반환되는 배열에는 각 시간 그리드 지점마다 하나의 값이 포함됩니다. 특정 그리드 지점에 대해 instant rate 값을 계산하기에 윈도우 내 샘플이 충분하지 않은 경우 해당 값은 NULL입니다. Array(Nullable(Float64))

예시

개별 타임스탬프-값 쌍을 사용하는 기본 예시

WITH
    -- NOTE: the gap between 140 and 190 is to show how values are filled for ts = 150, 165, 180 according to window parameter
    [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, -- array of values corresponding to timestamps above
    90 AS start_ts,       -- start of timestamp grid
    90 + 120 AS end_ts,   -- end of timestamp grid
    15 AS step_seconds,   -- step of timestamp grid
    45 AS window_seconds  -- "staleness" window
SELECT timeSeriesInstantRateToGrid(start_ts, end_ts, step_seconds, window_seconds)(timestamp, value)
FROM
(
    -- This subquery converts arrays of timestamps and values into rows of `timestamp`, `value`
    SELECT
        arrayJoin(arrayZip(timestamps, values)) AS ts_and_val,
        ts_and_val.1 AS timestamp,
        ts_and_val.2 AS value
);
┌─timeSeriesInstantRateToGrid(start_ts, end_ts, step_seconds, window_seconds)(timestamp, value)─┐
│ [NULL,NULL,0,0.2,0.1,0.1,NULL,NULL,0.3]                                                      │
└──────────────────────────────────────────────────────────────────────────────────────────────┘

배열 인수 사용하기

-- it is possible to pass multiple samples of timestamps and values as Arrays of equal size
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 timeSeriesInstantRateToGrid(start_ts, end_ts, step_seconds, window_seconds)(timestamps, values);
┌─timeSeriesInstantRateToGrid(start_ts, end_ts, step_seconds, window_seconds)(timestamps, values)─┐
│ [NULL,NULL,0,0.2,0.1,0.1,NULL,NULL,0.3]                                                        │
└────────────────────────────────────────────────────────────────────────────────────────────────┘