Class LeaderTableFilter
The Deephaven system does not provide cross table (or partition) transactions. However, you may have a producer that generates more than one table, which you would like to then use in a coordinated fashion. The Deephaven system preserves order within one partition, but the relative order of tables can not be guaranteed. Deephaven infrastructure typically processes each partition independently to provide maximum throughput; and thus a row that was created later may appear in your query before another row that was created earlier within a different partition.
The LeaderTable filter provides a mechanism to write multiple tables with correlated ID values. One table is the "leader" table and contains a row that indicates which rows from the "follower" tables should be considered together. The leader and follower tables perform this calculation by key, which can be zero or more columns. The leader table contains one column with a long ID per follower table which is matched to a long ID in that follower table.
The leader and follower tables must be add only, they are not permitted to modify, shift or remove rows. If you use a simple filter on an add-only source table, then they should remain add only.
In this example, there is a SyncLog table that acts as the leader for the messageLog and trades table. The tables must share keys in common to perform the synchronization. The columns must be the same type, though need not share the same name.
If we assume you have three add-only tables, named "syncLog", "tradeLog", and "messageLog" suitable for use with the LeaderTableFilter, to create the Builder we pass in the leader table with the key columns specified, in this case "client" and "session".
LeaderTableFilter.TableBuilder builder = new LeaderTableFilter.TableBuilder(syncLog, "client", "session");Next, we add each of our follower tables. The third argument is a
JoinMatch in which the
leader table's column name is on the left side and the follower's column name is on the right side. In this case the
syncLog table has a "msgId" column and the messageLog simply has an "id" column. In our result, the table will be
named "messageLog". The key columns are "client" and "SessionId", which must match the "client" and "session" columns
in the leader table.
builder.addTable("messageLog", messageLog, "msgId=id", "client", "SessionId");
If the leader and follower tables have the same column name, then that single column name can be used instead of
duplicating the column name.
builder.addTable("trades", trades, "execId", "client", "SessionId");
After adding all the tables, then the build() method is called to create a Results<Table>,
which implements a LeaderTableFilter.Results.get(String) method to retrieve result tables by name:
Results<Table> result = builder.build();
Table filteredMessageLog = result.get("messageLog");
Table filteredTrades = result.get("trades");
The leader table is also filtered to indicate which IDs are active, and can be retrieved from the Result as well,
either by name or with the LeaderTableFilter.Results.getLeader().
Table filteredLeader = result.get(io.deephaven.engine.util.LeaderTableFilter.DEFAULT_LEADER_NAME);
As an alternative to the TableBuilder you may use the LeaderTableFilter.PartitionedTableBuilder The PartitionedTableBuilder is
very similar to the TableBuilder, but takes PartitionedTables as input and produces a
LeaderTableFilter.Results containing PartitionedTables as output instead of a LeaderTableFilter.Results containing Tables. Entries are
added to the result after all the input PartitionedTables have a matching key. The number of key columns for each
PartitionedTable must be identical, and of compatible types, the underlying tables of constituents are joined
together on the key columns, in order. Each table within the
PartitionedTable must be add-only.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classProduce a Result of synchronized PartitionedTables.static interfaceThe Result class for a LeaderTableFilter, either containingtablesorpartitioned tables.static classProduce a Result of synchronized tables. -
Method Summary