Asof join

Similar to left-join but matching is done with equality-matching on key-columns and a most-recent-matching on the selected column.

Example

Include required headers and define the columns:

#include <cpptables/table.hh>
#include <iostream>

using namespace tables;
using namespace std;

struct c0{ constexpr static string_view name =  "Col0"; };
struct c1{ constexpr static string_view name =  "Col1"; };
struct c2{ constexpr static string_view name =  "Col2"; };

Construct left table:

  using table0_t = table<
    pair<c0,string_view>,
    pair<c1,unsigned>
  >;

  const table0_t t0(
      {"abc","def","ghi"},
      {0,5,10}
  );
  cout << "t0:\n" << t0 << "\n";

Construct right table:

  using table1_t = table<
    pair<c0,string_view>,
    pair<c1,unsigned>,
    pair<c2,unsigned>
  >;

  const table1_t t1(
    {"abc","def","ghi","abc","def","ghi","abc","def","ghi"},
    {1,2,3,4,5,6,7,8,9},
    {100,200,300,400,500,600,700,800,900}
  );
  cout << "t1:\n" << t1 << "\n";

Do an asof join using c0 as key-column and c1 as column for most-recent matching.

  const table1_t tres = t0.aj<c1>( t1.key_by<c0>() );
  cout << "tres:\n" << tres << "\n";

Output should be:

0:
Col0 Col1
---------
 abc    0
 def    5
 ghi   10

t1:
Col0 Col1 Col2
--------------
 abc    1  100
 def    2  200
 ghi    3  300
 abc    4  400
 def    5  500
 ghi    6  600
 abc    7  700
 def    8  800
 ghi    9  900

tres:
Col0 Col1 Col2
--------------
 abc none none
 def    5  500
 ghi    9  900