정의
The $tumblingWindow stage specifies a tumbling window for aggregation of data. Atlas Stream Processing windows are stateful, can be recovered if interrupted, and have mechanisms for processing late-arriving data. You must apply all other aggregation queries to your streaming data within this window stage.
$tumblingWindow$tumblingWindow파이프라인 단계의 프로토타입 형식은 다음과 같습니다.{ "$tumblingWindow": { "boundary": "eventTime" | "processingTime", "interval": { "size": <int>, "unit": "<unit-of-time>" }, "pipeline" : [ <aggregation-stage-array> ], "offset": { "offsetFromUtc": <int>, "unit": "<unit-of-time>" }, "idleTimeout": { "size": <int>, "unit": "<unit-of-time>" }, "allowedLateness": { size: <int>, unit: "<unit-of-time>" } } } 또는
$tumblingWindow파이프라인 단계는 아래와 같이 정수 값이 0인allowedLateness및idleTimeout필드를 가질 수 있습니다.{ "$tumblingWindow": { "boundary": "eventTime" | "processingTime", "interval": { "size": <int>, "unit": "<unit-of-time>" }, "pipeline" : [ <aggregation-stage-array> ], "offset": { "offsetFromUtc": <int>, "unit": "<unit-of-time>" }, "idleTimeout": 0, "allowedLateness": 0 } }
구문
$tumblingWindow 단계에서는 다음 필드가 있는 문서를 사용합니다.
필드 | 유형 | 필요성 | 설명 |
|---|---|---|---|
| 문자열 | 옵션 | 창 경계를 이벤트 시간으로 결정할지 처리 시간으로 결정할지 지정하는 문자열입니다. 값은
|
| 문서 | 필수 사항 | 크기와 시간 단위의 조합으로 터블링 창 의 간격을 지정하는 문서:
예를 들어 의 |
| 배열 | 필수 사항 | 창 내의 메시지에 대해 평가된 중첩 집계 파이프라인입니다. |
| 문서 | 옵션 | UTC를 기준으로 창 경계의 시간 오프셋을 지정하는 문서입니다. 문서는 크기 필드
예를 들어 |
| 문서 | 옵션 |
예를 들어 12:00 오후부터 1:00 오후 기간과 Alternatively, you can define this setting with an integer value of 0. See the pipeline defintion for more information. 유휴 시간 초과가 창 기간 동안 워터마크와 상호 작용하는 방법은 유휴 시간 초과를 참조하세요. |
| 문서 | 옵션 | 창 종료 시간에 대해 문서를 처리한 후 늦게 도착한 데이터를 받기 위해 소스에서 생성된 창을 얼마나 오래 열어둘지 지정하는 문서입니다. 생략하면 기본값은 3초입니다. Alternatively, you can define this setting with an integer value of 0. See the pipeline defintion for more information. 허용된 지연이 워터마크에 대해 창 닫힘을 지연시키는 방법은 허용된 지연을 참조하세요. |
행동
Atlas Stream Processing은 파이프라인당 하나의 윈도우 단계만 지원합니다.
When you apply the $group stage to your window stage, a single group key has a limit of 100 megabytes of RAM.
특정 집계 단계에 대한 지원은 Windows 내에서 제한되거나 사용할 수 없을 수 있습니다. 자세한 내용은 지원되는 집계 파이프라인 단계를 참조하세요.
서비스 중단 시, 중단 시점에서 창의 내부 파이프라인을 재개할 수 있습니다 자세한 내용은 체크포인트를 참조하세요.
예시
A streaming data source generates detailed weather reports from various locations, conformant to the schema of the Sample Weather Dataset. The following aggregation has three stages:
The
$tumblingWindowstage defines consecutive windows with 30-second duration. Each window executes an internalpipeline, which finds the average, median, maximum, and minimumatmosphericPressureObservation.altimeterSetting.valuefor the duration of that window. Thepipelinethen outputs a single document with an_idequivalent to the start timestamp of the window it represents and the specified values for that window.The
$mergestage writes the output to an Atlas collection namedstreamin thesample_weatherstreamdatabase. If no such database or collection exist, Atlas creates them.
{ '$source': { connectionName: 'sample_weatherdata', topic: 'my_weatherdata', tsFieldName: 'ingestionTime' } }, { '$tumblingWindow': { interval: { size: 30, unit: "second" }, pipeline: [{ $group: { _id: { $meta: "stream.window.start"}, averagePressure: { $avg: "$atmosphericPressureObservation.altimeterSetting.value" }, medianPressure: { $median: { input: "$atmosphericPressureObservation.altimeterSetting.value", method: "approximate" } }, maxPressure: { $max: "$atmosphericPressureObservation.altimeterSetting.value" }, minPressure: { $min: "$atmosphericPressureObservation.altimeterSetting.value" } } }] } }, { '$merge': { into: { connectionName: 'weatherStreamOutput', db: 'sample_weatherstream', coll: 'stream' } } }
결과 sample_weatherstream.stream 컬렉션의 문서를 보려면 Atlas 클러스터에 연결하고 다음 명령을 실행하세요.
db.getSiblingDB("sample_weatherstream").stream.find()
{ _id: ISODate('2024-09-26T16:34:00.000Z'), averagePressure: 5271.47894736842, maxPressure: 9999.9, medianPressure: 1015.9, minPressure: 1015.9 }, { _id: ISODate('2024-09-26T16:34:30.000Z'), averagePressure: 5507.9, maxPressure: 9999.9, medianPressure: 1015.9, minPressure: 1015.9 }
참고
위 사례는 대표적인 예시입니다. 스트리밍 데이터는 정적이지 않으며 각 사용자는 서로 다른 문서를 보게 됩니다.