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

timeSeriesInstantDeltaToGrid

timeSeriesInstantDeltaToGrid

도입 버전: v25.6

타임스탬프와 값의 쌍으로 구성된 시계열 데이터를 입력으로 받아, 시작 타임스탬프, 종료 타임스탬프, 스텝으로 정의된 일정 간격의 시간 그리드에서 이 데이터로부터 PromQL과 유사한 idelta를 계산하는 집계 함수입니다. 그리드의 각 지점에 대해 idelta를 계산하기 위한 샘플은 지정된 시간 윈도우 내에서 선택됩니다.

참고

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

구문

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

매개변수

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

인수

반환 값

지정된 그리드에 대한 idelta 값을 반환합니다. 반환되는 배열은 각 시간 그리드 지점마다 하나의 값을 포함합니다. 특정 그리드 지점에 대해 instant delta 값을 계산할 수 있을 만큼 윈도우 내에 샘플이 충분하지 않으면 값은 NULL입니다. Array(Nullable(Float64)) — 널 허용(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 timeSeriesInstantDeltaToGrid(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
);
┌─timeSeriesInstantDeltaToGrid(start_ts, end_ts, step_seconds, window_seconds)(timestamp, value)─┐
│ [NULL,NULL,0,2,1,1,NULL,NULL,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 timeSeriesInstantDeltaToGrid(start_ts, end_ts, step_seconds, window_seconds)(timestamps, values);
┌─timeSeriesInstantDeltaToGrid(start_ts, end_ts, step_seconds, window_seconds)(timestamps, values)─┐
│ [NULL,NULL,0,2,1,1,NULL,NULL,3]                                                                 │
└─────────────────────────────────────────────────────────────────────────────────────────────────┘