The first template of the source-aligned family: one data product per source system, capturing a database by CDC and turning what it emits into what a canonical product accepts. It runs on the Integration Bus, not in a domain, and is deployed with the `data-bus` CLI. What it produces, and what its tests hold it to: raw topics in the source's own shape; deterministic identity, so a re-snapshot upserts rather than duplicating; validation against the canonical product's rules before publishing, with what fails going to the product's own dead-letter topic with the reason; keying by the canonical identifier; provenance in headers; and an archive in the bus object store that can be replayed back onto the raw topic. The worked example captures an ERP customer table and delivers into Canonical Party in the digital-core domain: 12 smoke checks, 37 unit tests, including a poison record that is quarantined while the next record still arrives. The canonical template's topics now declare the key producers must set, which is the other half of that contract. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
61 lines
2.0 KiB
SQL
61 lines
2.0 KiB
SQL
-- {{product_name}}: replay.
|
|
--
|
|
-- Reads the product's raw archive out of the bus object store and publishes it back onto the
|
|
-- raw topic, exactly as the capture connector wrote it — same records, same keys — so the
|
|
-- transform runs again and the canonical product is upserted under the same identifiers.
|
|
--
|
|
-- Submitted by `data-bus replay <product dir> [--since] [--until]`, which substitutes the
|
|
-- path, the topic and the date range. It runs in batch mode, so it ends when the archive has
|
|
-- been read rather than waiting for more.
|
|
|
|
SET 'pipeline.name' = '{{slug}}-replay';
|
|
SET 'execution.runtime-mode' = 'batch';
|
|
SET 'table.local-time-zone' = 'UTC';
|
|
|
|
CREATE TABLE {{system}}_{{source_object}}_archive (
|
|
id INT,
|
|
cust_name STRING,
|
|
cust_type STRING,
|
|
status_code STRING,
|
|
birth_date INT,
|
|
trading_name STRING,
|
|
`updated` STRING,
|
|
__op STRING,
|
|
__lsn BIGINT,
|
|
__source_ts_ms BIGINT,
|
|
dt STRING
|
|
) PARTITIONED BY (dt) WITH (
|
|
'connector' = 'filesystem',
|
|
'path' = '${ARCHIVE_PATH}',
|
|
'format' = 'json'
|
|
);
|
|
|
|
-- The raw topic, keyed the way the CDC connector keys it: the source key, as JSON.
|
|
CREATE TABLE {{system}}_{{source_object}}_raw (
|
|
id INT,
|
|
cust_name STRING,
|
|
cust_type STRING,
|
|
status_code STRING,
|
|
birth_date INT,
|
|
trading_name STRING,
|
|
`updated` STRING,
|
|
__op STRING,
|
|
__lsn BIGINT,
|
|
__source_ts_ms BIGINT
|
|
) WITH (
|
|
'connector' = 'kafka',
|
|
'topic' = '${RAW_TOPIC}',
|
|
'properties.bootstrap.servers' = '${BUS_KAFKA}',
|
|
'format' = 'json',
|
|
'key.format' = 'json',
|
|
'key.fields' = 'id',
|
|
'value.fields-include' = 'ALL'
|
|
);
|
|
|
|
INSERT INTO {{system}}_{{source_object}}_raw
|
|
SELECT
|
|
id, cust_name, cust_type, status_code, birth_date, trading_name, `updated`,
|
|
__op, __lsn, __source_ts_ms
|
|
FROM {{system}}_{{source_object}}_archive
|
|
WHERE dt >= '${SINCE}' AND dt <= '${UNTIL}';
|