MCPcopy Create free account
hub / github.com/apache/arrow / AdvanceAndMemoize

Method AdvanceAndMemoize

cpp/src/arrow/acero/asof_join_node.cc:658–702  ·  view source on GitHub ↗

Advance the data to be immediately past the tolerance's horizon for the specified timestamp, update latest_time and latest_ref_row to the value that immediately pass the horizon. Update the memo-store with any entries or future entries so observed. Returns true if updates were made, false if not. NOTE: The emptiness must be decided by a single call to Empty() in caller, due to the potential race w

Source from the content-addressed store, hash-verified

656 // NOTE: The emptiness must be decided by a single call to Empty() in caller, due to the
657 // potential race with Push(), see GH-41614.
658 Result<bool> AdvanceAndMemoize(OnType ts, bool empty) {
659 // Advance the right side row index until we reach the latest right row (for each key)
660 // for the given left timestamp.
661 DEBUG_SYNC(node_, "Advancing input ", index_, DEBUG_MANIP(std::endl));
662
663 // Check if already updated for TS (or if there is no latest)
664 if (empty) { // can't advance if empty and no future entries
665 return memo_.no_future_ ? false : memo_.RemoveEntriesWithLesserTime(ts);
666 }
667
668 // Not updated. Try to update and possibly advance.
669 bool advanced, updated = false;
670 OnType latest_time;
671 do {
672 latest_time = GetLatestTime();
673 // if Advance() returns true, then the latest_ts must also be valid
674 // Keep advancing right table until we hit the latest row that has
675 // timestamp <= ts. This is because we only need the latest row for the
676 // match given a left ts.
677 if (latest_time > tolerance_.Horizon(ts)) { // hit a distant timestamp
678 DEBUG_SYNC(node_, "Advancing input ", index_, " hit distant time=", latest_time,
679 " at=", ts, DEBUG_MANIP(std::endl));
680 // if no future entries, which would have been earlier than the distant time, no
681 // need to queue it
682 if (memo_.future_entries_.empty()) break;
683 }
684 auto rb = GetLatestBatch();
685 if (may_rehash_ && rb->column_data(key_col_index_[0])->GetNullCount() > 0) {
686 must_hash_ = true;
687 may_rehash_ = false;
688 Rehash();
689 }
690 memo_.Store(rb, latest_ref_row_, latest_time, DEBUG_ADD(GetLatestKey(), ts));
691 // negative tolerance means a last-known entry was stored - set `updated` to `true`
692 updated = memo_.no_future_;
693 ARROW_ASSIGN_OR_RAISE(advanced, Advance());
694 } while (advanced);
695 if (!memo_.no_future_ && latest_time >= ts) {
696 // `updated` was not modified in the loop from the initial `false` value; set it now
697 updated = memo_.RemoveEntriesWithLesserTime(ts);
698 }
699 DEBUG_SYNC(node_, "Advancing input ", index_, " updated=", updated,
700 DEBUG_MANIP(std::endl));
701 return updated;
702 }
703 Status InsertBatch(ExecBatch batch) {
704 return sequencer_->InsertBatch(std::move(batch));
705 }

Callers

nothing calls this directly

Calls 8

AdvanceFunction · 0.85
HorizonMethod · 0.80
GetNullCountMethod · 0.80
column_dataMethod · 0.80
StoreMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected