
Answer-first summary for fast verification
Answer: SELECT Country, Count(*) AS Count FROM ClickStream TIMESTAMP BY CreatedAt GROUP BY Country, TumblingWindow(second, 10)
## Analysis of Window Types for Click Counting The key requirements are: 1. Count clicks in 10-second windows grouped by country 2. Ensure each click is counted only once (no overlaps) ### Window Type Evaluation: **Tumbling Window (Option B):** - Creates non-overlapping, contiguous time intervals - Each event belongs to exactly one window - Perfect for counting distinct events without duplication - 10-second tumbling windows ensure each click is counted exactly once **Sliding Window (Option A):** - Produces output at every point in time when events enter or exit - Windows overlap, causing events to be counted multiple times - Violates the "not counted more than once" requirement **Hopping Window (Option C):** - Windows overlap by design (hops smaller than window size) - With 10-second window and 2-second hop, events appear in multiple windows - Causes duplicate counting of clicks **Session Window (Option D):** - Groups events based on activity gaps - Window sizes vary based on user behavior - Cannot guarantee fixed 10-second intervals - May count events across multiple sessions ### Why Option B is Optimal: - **TumblingWindow(second, 10)** creates perfect 10-second non-overlapping intervals - **Count(*)** accurately counts clicks within each window - **GROUP BY Country** provides the required grouping - **TIMESTAMP BY CreatedAt** ensures proper event time processing - The combination guarantees each click is counted exactly once in its respective 10-second window ### Why Other Options Fail: - **A & C**: Use overlapping windows (Sliding/Hopping) that violate the single-count requirement - **D**: Uses variable-sized Session windows that don't guarantee fixed 10-second intervals - **A & C**: Also incorrectly use Avg(*) instead of Count(*) for counting operations
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
You have an Azure Stream Analytics job that ingests clickstream data from an Azure Event Hub. You must define a query for this job that meets the following requirements:
How should you complete the query?
A
SELECT Country, Avg(*) AS Average FROM ClickStream TIMESTAMP BY CreatedAt GROUP BY Country, SlidingWindow(second, 10)
B
SELECT Country, Count(*) AS Count FROM ClickStream TIMESTAMP BY CreatedAt GROUP BY Country, TumblingWindow(second, 10)
C
SELECT Country, Avg(*) AS Average FROM ClickStream TIMESTAMP BY CreatedAt GROUP BY Country, HoppingWindow(second, 10, 2)
D
SELECT Country, Count(*) AS Count FROM ClickStream TIMESTAMP BY CreatedAt GROUP BY Country, SessionWindow(second, 5, 10)
No comments yet.