Adds the latest row from the input state as a new composite reference row - LHS must have a valid key,timestep,and latest rows - RHS must have valid data memo'ed for the key
| 835 | // - LHS must have a valid key,timestep,and latest rows |
| 836 | // - RHS must have valid data memo'ed for the key |
| 837 | void Emplace(std::vector<std::unique_ptr<InputState>>& in, TolType tolerance) { |
| 838 | DCHECK_EQ(in.size(), n_tables_); |
| 839 | |
| 840 | // Get the LHS key |
| 841 | ByType key = in[0]->GetLatestKey(); |
| 842 | |
| 843 | // Add row and setup LHS |
| 844 | // (the LHS state comes just from the latest row of the LHS table) |
| 845 | DCHECK(!in[0]->Empty()); |
| 846 | const std::shared_ptr<arrow::RecordBatch>& lhs_latest_batch = in[0]->GetLatestBatch(); |
| 847 | row_index_t lhs_latest_row = in[0]->GetLatestRow(); |
| 848 | OnType lhs_latest_time = in[0]->GetLatestTime(); |
| 849 | if (0 == lhs_latest_row) { |
| 850 | // On the first row of the batch, we resize the destination. |
| 851 | // The destination size is dictated by the size of the LHS batch. |
| 852 | row_index_t new_batch_size = lhs_latest_batch->num_rows(); |
| 853 | row_index_t new_capacity = unmaterialized_table.Size() + new_batch_size; |
| 854 | if (unmaterialized_table.capacity() < new_capacity) { |
| 855 | unmaterialized_table.reserve(new_capacity); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | SliceBuilder new_row{&unmaterialized_table}; |
| 860 | |
| 861 | // Each item represents a portion of the columns of the output table |
| 862 | new_row.AddEntry(lhs_latest_batch, lhs_latest_row, lhs_latest_row + 1); |
| 863 | |
| 864 | DEBUG_SYNC(node_, "Emplace: key=", key, " lhs_latest_row=", lhs_latest_row, |
| 865 | " lhs_latest_time=", lhs_latest_time, DEBUG_MANIP(std::endl)); |
| 866 | |
| 867 | // Get the state for that key from all on the RHS -- assumes it's up to date |
| 868 | // (the RHS state comes from the memoized row references) |
| 869 | for (size_t i = 1; i < in.size(); ++i) { |
| 870 | std::optional<const MemoStore::Entry*> opt_entry = in[i]->GetMemoEntryForKey(key); |
| 871 | #ifndef NDEBUG |
| 872 | { |
| 873 | bool has_entry = opt_entry.has_value(); |
| 874 | OnType entry_time = has_entry ? (*opt_entry)->time : TolType::kMinValue; |
| 875 | row_index_t entry_row = has_entry ? (*opt_entry)->row : 0; |
| 876 | bool accepted = has_entry && tolerance.Accepts(lhs_latest_time, entry_time); |
| 877 | DEBUG_SYNC(node_, " i=", i, " has_entry=", has_entry, " time=", entry_time, |
| 878 | " row=", entry_row, " accepted=", accepted, DEBUG_MANIP(std::endl)); |
| 879 | } |
| 880 | #endif |
| 881 | if (opt_entry.has_value()) { |
| 882 | DCHECK(*opt_entry); |
| 883 | if (tolerance.Accepts(lhs_latest_time, (*opt_entry)->time)) { |
| 884 | // Have a valid entry |
| 885 | const MemoStore::Entry* entry = *opt_entry; |
| 886 | new_row.AddEntry(entry->batch, entry->row, entry->row + 1); |
| 887 | continue; |
| 888 | } |
| 889 | } |
| 890 | new_row.AddEntry(nullptr, 0, 1); |
| 891 | } |
| 892 | new_row.Finalize(); |
| 893 | } |
| 894 |
nothing calls this directly
no test coverage detected