Skip to main content
Let’s start with an example table and row of data from a Snowflake destination.
RECORD_METADATAIDFIRST_NAMELAST_NAME_STREAMKAP_SOURCE_TS_MS_STREAMKAP_TS_MS__DELETED_STREAMKAP_OFFSET
1302PaulSmith17277701770001727770177618FALSE309707
In the above example we have 3 data fields that match the source:
  • ID: also the source table’s primary key.
  • FIRST_NAME
  • LAST_NAME
Then we have the additional columns that Streamkap adds:
  • RECORD_METADATA: Metadata such as the origin topic, partition, offset, event type and more. It can be useful for debugging purposes.
  • _STREAMKAP_SOURCE_TS_MS: Timestamp in milliseconds (UTC) for when the event occurred in the source database.
  • _STREAMKAP_TS_MS: Timestamp in milliseconds (UTC) for when Streamkap received the event.
  • __DELETED: Indicates whether this event/row (by its primary key) has been deleted in the source database.
  • _STREAMKAP_OFFSET: This is an offset value in relation to the events we process. It can be useful for debugging purposes.
Why _STREAMKAP_OFFSET must be in the ORDER BY clauseIncluding _STREAMKAP_OFFSET in the ORDER BY is mandatory for correct deduplication. Multiple events for the same primary key can have the same _STREAMKAP_TS_MS timestamp (e.g., rapid successive updates within the same millisecond). Without _STREAMKAP_OFFSET, records with the same timestamp but different offsets may be deduplicated incorrectly, potentially selecting an older event over the latest one.

Snowflake

Task & Merge Statement

SQL

Dynamic Tables

Streamkap supports the auto creation and maintenance of Snowflake Dynamic Tables for this final view but the logic underneath is as follows
SQL

DBT

SQL Example

SQL
This is an example approach whereby we can utilize incremental models (DBT or similar) to only compare data that has recently come into the raw source tables from Streamkap. So during incremental refreshes there is no need to scan over the historical CDC data coming in. The 2nd where clause for incremental logic is in relation to {{ this }} declaration for DBT, since it can use post DBT hook to delete the __deleted columns that are true.

Python Example

This is an example approach for generating the DBT incremental models.
Python