
Answer-first summary for fast verification
Answer: Use a sliding window with a duration of 30 seconds and a period of 5 seconds. Emit results by setting the following trigger: AfterWatermark.pastEndOfWindow ()
The correct answer is D: Use a sliding window with a duration of 30 seconds and a period of 5 seconds. Emit results by setting the following trigger: AfterWatermark.pastEndOfWindow(). Explanation: A sliding window is appropriate since we need to compute a moving average of the past 30 seconds' worth of data every 5 seconds. This setup allows overlapping intervals which is necessary for continuous moving average calculations. The window duration is set to 30 seconds to cover the required period, and the period (or sliding interval) of 5 seconds ensures that the window moves and recalculates the moving average every 5 seconds. The trigger, AfterWatermark.pastEndOfWindow, ensures that the results are emitted when the watermark passes the end of the window, providing accurate and timely results.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
You are tasked with analyzing the price of a company's stock in real time. The requirement is to compute a moving average of the stock price based on data from the last 30 seconds, with updates every 5 seconds. The data is being ingested from Pub/Sub and must be processed using DataFlow. How should you configure your windowed pipeline to achieve this?
A
Use a fixed window with a duration of 5 seconds. Emit results by setting the following trigger: AfterProcessingTime.pastFirstElementInPane().plusDelayOf (Duration.standardSeconds(30))
B
Use a fixed window with a duration of 30 seconds. Emit results by setting the following trigger: AfterWatermark.pastEndOfWindow().plusDelayOf (Duration.standardSeconds(5))
C
Use a sliding window with a duration of 5 seconds. Emit results by setting the following trigger: AfterProcessingTime.pastFirstElementInPane().plusDelayOf (Duration.standardSeconds(30))
D
Use a sliding window with a duration of 30 seconds and a period of 5 seconds. Emit results by setting the following trigger: AfterWatermark.pastEndOfWindow ()
No comments yet.