Download presentation
Presentation is loading. Please wait.
Published byΟὐλιξεύς Γκόφας Modified over 5 years ago
1
CS240B, Spring 2014 Task 2.2: Using a syntax based on that of notes and reference 3 above, express a user-defined aggregate d_count to perform the exact count of distinct values in a window on a data stream. Your window aggregate could, e.g., be called as follows: SELECT col_name1, d_count(col_name2)OVER (ROWS PRECEDING) FROM my_stream;
2
d_count exact count of distinct values in a window
Increase the count only if this is not a duplicate; WINDOW AGGREGATE d_count(next Real) : Real { TABLE state(cnt Int); TABLE inwindow(wnext Real); INITIALIZE : {INSERT INTO state VALUES (1)} ITERATE : {/*the system inserts the new tuple in invindow at the end of iterate*/ UPDATE state SET cnt=cnt WHERE next NOT IN (SELECT wnext FROM inwindow) INSERT INTO RETURN SELECT cnt FROM state} EXPIRE: { /* this is processed before ITERATE for each expired tuple */ UPDATE state SET cnt= cnt WHERE next NOT IN (SELECT wnext FROM inwindow} }
3
d_count exact count: optimize inwindow
Increase the count only if this is not a duplicate; to avoid duplicates in invindow delete the old occurrences WINDOW AGGREGATE d_count(next Real) : Real { TABLE state(cnt Int); TABLE inwindow(wnext Real); INITIALIZE : {INSERT INTO state VALUES (1)} ITERATE : {/*the system inserts the new tuple in invindow at the end of iterate*/ UPDATE state SET cnt=cnt WHERE next NOT IN (SELECT wnext FROM inwindow); DELETE FROM inwindow WHERE Wnext=next; INSERT INTO RETURN SELECT cnt FROM state} EXPIRE: { /* this is processed before ITERATE for each expired tuple */ UPDATE state SET cnt= cnt-1} }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.