@@ -258,9 +258,13 @@ class Window : public MemTimeTableHandler {
258258 bool exclude_current_time () const { return exclude_current_time_; }
259259 void set_exclude_current_time (bool flag) { exclude_current_time_ = flag; }
260260
261+ bool without_order_by () const { return without_order_by_; }
262+ void set_without_order_by (bool flag) { without_order_by_ = flag; }
263+
261264 protected:
262265 bool exclude_current_time_ = false ;
263266 bool instance_not_in_window_ = false ;
267+ bool without_order_by_ = false ;
264268};
265269class WindowRange {
266270 public:
@@ -356,44 +360,13 @@ class HistoryWindow : public Window {
356360 PopFrontRow ();
357361 }
358362 }
363+ bool BufferData (uint64_t key, const Row& row) override ;
359364
360- // aad newer row into window
361- bool BufferData (uint64_t key, const Row& row) override {
362- if (!table_.empty () && GetFrontRow ().first > key) {
363- DLOG (WARNING) << " Fail BufferData: buffer key less than latest key" ;
364- return false ;
365- }
366- auto cur_size = table_.size ();
367- if (cur_size < window_range_.start_row_ ) {
368- // current in the ROWS window
369- int64_t sub = key + window_range_.start_offset_ ;
370- uint64_t start_ts = sub < 0 ? 0u : static_cast <uint64_t >(sub);
371- if (0 == window_range_.end_offset_ ) {
372- return BufferCurrentTimeBuffer (key, row, start_ts);
373- } else {
374- return BufferEffectiveWindow (key, row, start_ts);
375- }
376- } else if (0 == window_range_.end_offset_ ) {
377- // current in the ROWS_RANGE window
378- int64_t sub = (static_cast <int64_t >(key) + window_range_.start_offset_ );
379- uint64_t start_ts = sub < 0 ? 0u : static_cast <uint64_t >(sub);
380- return BufferCurrentTimeBuffer (key, row, start_ts);
381- } else {
382- // current row BeforeWindow
383- int64_t sub = (key + window_range_.end_offset_ );
384- uint64_t end_ts = sub < 0 ? 0u : static_cast <uint64_t >(sub);
385- return BufferCurrentHistoryBuffer (key, row, end_ts);
386- }
387- }
365+ // add newer row into window
366+ bool BufferDataImpl (uint64_t key, const Row& row);
388367
389368 protected:
390- bool BufferCurrentHistoryBuffer (uint64_t key, const Row& row, uint64_t end_ts) {
391- current_history_buffer_.emplace_front (key, row);
392- int64_t sub = (static_cast <int64_t >(key) + window_range_.start_offset_ );
393- uint64_t start_ts = sub < 0 ? 0u : static_cast <uint64_t >(sub);
394- SlideWindow (start_ts, end_ts);
395- return true ;
396- }
369+ bool BufferCurrentHistoryBuffer (uint64_t key, const Row& row, uint64_t end_ts);
397370
398371 // sliding rows data from `current_history_buffer_` into effective window
399372 // by giving the new start_ts and end_ts.
@@ -413,77 +386,18 @@ class HistoryWindow : public Window {
413386 // `start_ts_inclusive` and `end_ts_inclusive` can be empty, which effectively means less than 0.
414387 // if `start_ts_inclusive` is empty, no rows goes out of effective window
415388 // if `end_ts_inclusive` is empty, no rows goes out of history buffer and into effective window
416- void SlideWindow (std::optional<uint64_t > start_ts_inclusive, std::optional<uint64_t > end_ts_inclusive) {
417- // always try to cleanup the stale rows out of effective window
418- if (start_ts_inclusive.has_value ()) {
419- Slide (start_ts_inclusive);
420- }
421-
422- if (!end_ts_inclusive.has_value ()) {
423- return ;
424- }
425-
426- while (!current_history_buffer_.empty () && current_history_buffer_.back ().first <= end_ts_inclusive) {
427- auto & back = current_history_buffer_.back ();
428-
429- BufferEffectiveWindow (back.first , back.second , start_ts_inclusive);
430- current_history_buffer_.pop_back ();
431- }
432- }
389+ void SlideWindow (std::optional<uint64_t > start_ts_inclusive, std::optional<uint64_t > end_ts_inclusive);
433390
434391 // push the row to the start of window
435392 // - pop last elements in window if exceed max window size
436393 // - also pop last elements in window if there ts less than `start_ts`
437394 //
438395 // if `start_ts` is empty, no rows eliminated from window
439- bool BufferEffectiveWindow (uint64_t key, const Row& row, std::optional<uint64_t > start_ts) {
440- AddFrontRow (key, row);
441- return Slide (start_ts);
442- }
396+ bool BufferEffectiveWindow (uint64_t key, const Row& row, std::optional<uint64_t > start_ts);
443397
444- bool Slide (std::optional<uint64_t > start_ts) {
445- auto cur_size = table_.size ();
446- while (window_range_.max_size_ > 0 &&
447- cur_size > window_range_.max_size_ ) {
448- PopBackRow ();
449- --cur_size;
450- }
398+ bool Slide (std::optional<uint64_t > start_ts);
451399
452- // Slide window if window start bound >= rows/range preceding
453- while (cur_size > 0 ) {
454- const auto & pair = GetBackRow ();
455- if ((kFrameRows == window_range_.frame_type_ || kFrameRowsMergeRowsRange == window_range_.frame_type_ ) &&
456- cur_size <= window_range_.start_row_ + 1 ) {
457- // note it is always current rows window
458- break ;
459- }
460- if (kFrameRows == window_range_.frame_type_ || pair.first < start_ts) {
461- PopBackRow ();
462- --cur_size;
463- } else {
464- break ;
465- }
466- }
467- return true ;
468- }
469-
470- bool BufferCurrentTimeBuffer (uint64_t key, const Row& row, uint64_t start_ts) {
471- if (exclude_current_time_) {
472- // except `exclude current_row`, the current row is always added to the effective window
473- // but for next buffer action, previous current row already buffered in `current_history_buffer_`
474- // so the previous current row need eliminated for this next buf action
475- PopEffectiveDataIfAny ();
476- if (key == 0 ) {
477- SlideWindow (start_ts, {});
478- } else {
479- SlideWindow (start_ts, key - 1 );
480- }
481- current_history_buffer_.emplace_front (key, row);
482- }
483-
484- // in queue the current row
485- return BufferEffectiveWindow (key, row, start_ts);
486- }
400+ bool BufferCurrentTimeBuffer (uint64_t key, const Row& row, uint64_t start_ts);
487401
488402 WindowRange window_range_;
489403 MemTimeTable current_history_buffer_;
@@ -512,20 +426,7 @@ class CurrentHistoryWindow : public HistoryWindow {
512426
513427 void PopFrontData () override { PopFrontRow (); }
514428
515- bool BufferData (uint64_t key, const Row& row) override {
516- if (!table_.empty () && GetFrontRow ().first > key) {
517- DLOG (WARNING) << " Fail BufferData: buffer key less than latest key" ;
518- return false ;
519- }
520- int64_t sub = (key + window_range_.start_offset_ );
521- uint64_t start_ts = sub < 0 ? 0u : static_cast <uint64_t >(sub);
522-
523- if (exclude_current_time_) {
524- return BufferCurrentTimeBuffer (key, row, start_ts);
525- } else {
526- return BufferEffectiveWindow (key, row, start_ts);
527- }
528- }
429+ bool BufferData (uint64_t key, const Row& row) override ;
529430};
530431
531432typedef std::map<std::string,
0 commit comments