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

timeSeriesResampleToGridWithStaleness

timeSeriesResampleToGridWithStaleness

도입 버전: v25.6

타임스탬프와 값의 쌍으로 구성된 시계열 데이터를 입력으로 받아, 시작 타임스탬프, 종료 타임스탬프 및 스텝(step)으로 정의되는 규칙적인 시간 그리드에 맞춰 이 데이터를 리샘플링하는 집계 함수입니다. 그리드의 각 지점에 대해 지정된 시간 구간 내에서 가장 최근 샘플이 선택됩니다.

별칭: timeSeriesLastToGrid.

참고

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

문법

timeSeriesResampleToGridWithStaleness(start_timestamp, end_timestamp, grid_step, staleness_window)(timestamp, value)

별칭: timeSeriesLastToGrid

매개변수

  • start_timestamp — 그리드의 시작 지점을 지정합니다. UInt32 또는 DateTime
  • end_timestamp — 그리드의 끝 지점을 지정합니다. UInt32 또는 DateTime
  • grid_step — 그리드 간격(초 단위)을 지정합니다. UInt32
  • staleness_window — 가장 최근 샘플의 최대 허용 지연 시간(초 단위)을 지정합니다. UInt32

인수

반환 값

지정된 그리드에 맞춰 재샘플링된 시계열 값을 반환합니다. 반환되는 배열에는 각 시간 그리드 시점마다 하나의 값이 포함됩니다. 특정 그리드 시점에 대한 샘플이 없으면 해당 값은 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 staleness 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
    30 AS window_seconds  -- "staleness" window
SELECT timeSeriesResampleToGridWithStaleness(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
);
┌─timeSeriesResampleToGridWithStaleness(start_ts, end_ts, step_seconds, window_seconds)(timestamp, value)─┐
│ [NULL,NULL,1,3,4,4,NULL,5,8]                                                                           │
└────────────────────────────────────────────────────────────────────────────────────────────────────┘

배열 인수 사용

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,
    30 AS window_seconds
SELECT timeSeriesResampleToGridWithStaleness(start_ts, end_ts, step_seconds, window_seconds)(timestamps, values);
┌─timeSeriesResampleToGridWithStaleness(start_ts, end_ts, step_seconds, window_seconds)(timestamps, values)─┐
│ [NULL,NULL,1,3,4,4,NULL,5,8]                                                                             │
└──────────────────────────────────────────────────────────────────────────────────────────────────────┘