StreamBase supports table delta streams, which are special-purpose output streams that track changes to Query Tables. Users can enable or disable a table delta stream on an active or replica node. Delta stream tuples on the active node are delivered in the same transaction that caused the query table change. Delta stream tuples on a replica node are delivered in a separate transaction that caused the replicated query table change. If you enable a table delta stream for a Query Table, then every insert, update, or delete operation on the data in the table causes the delta stream to emit a tuple that represents the change.
Enable a delta stream with these steps:
Double-click the Query Table icon to open its Properties view.
In the Table Settings tab, select Yes for the Enable Delta Stream Port control.
Save the EventFlow module or click anywhere in the canvas. The Query Table now shows a connection port on its right corner.
Connect an Output Stream or other operator to this connection port to consume the table change information.
Studio assigns a name for the delta stream based on the pattern
num is the number of the table's output ports, which is almost always 1.
A table delta stream's schema has four fields:
|The operation type, one of
|An incrementing number that keeps a count of modifications to the Query Table since the module containing this table was started.
Each modification attempt causes the number to increment.
A failed modification (such as an update that results in no row changes) still increments the modification count. Thus, the
|For delete and insert operations, a tuple showing the contents of the row deleted or the row before an update operation.
|For insert and update operations, a tuple showing the contents of the row inserted or the row after an update operation.
When you enable a delta stream for a table, the schema for the delta stream's
new fields is automatically set the same as the schema of the table itself:
If the table's schema is defined with a named schema or table schema, the
newtuples are defined with those schemas. If you change the named or table schema, the Query Table and its delta stream tuples update at the same time.
If your Query Table is defined with an unnamed schema, and you later change the schema of the Query Table, you must explicitly update the fields in the table delta stream to match.