runtime
CRM + ERP Integration · milestone 05 / 12

milestone 5/12 Quarantine bad rows & reconcile the batch

Separate invalid records and reconcile the whole batch.

CRM + ERP Integration · Follow extraction reconciliation, authoritative integration, date quarantine, quality gates, stable keys, replay-safe loads, and atomic promotion. Finish with a customer-grain capstone and field-level lineage.

approach

Filtering invalid rows is not enough: preserve a reject table with source identity, raw value, and reason. Accepted + rejected must equal source count with no overlap. This lab classifies only dates: missing, format, or calendar errors. Nothing edits the raw input.

worked-example.sql
CREATE TEMP TABLE checked_dates AS
WITH shaped AS(
  SELECT
    row_id,
    raw_date,
    SUBSTR(raw_date,1,4)||'-'||SUBSTR(raw_date,5,2)||'-'||SUBSTR(raw_date,7,2) AS candidate
  FROM raw_dates
)
SELECT
  row_id,
  raw_date,
  CASE
    WHEN raw_date GLOB '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
      AND date(candidate,'+0 days')=candidate
      THEN candidate
    ELSE NULL
  END AS clean_date
FROM shaped;
CREATE TEMP TABLE date_rejects AS
SELECT
  row_id,
  raw_date,
  CASE
    WHEN raw_date IS NULL THEN 'missing'
    WHEN raw_date NOT GLOB '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
      THEN 'format'
    ELSE 'calendar'
  END AS reason
FROM checked_dates
WHERE clean_date IS NULL;
SELECT row_id,raw_date,reason
FROM date_rejects;

data for this milestone

raw_dates2 columns · 8 rows
row_idinteger · keyraw_datetext
120250115
220250230
30
420240229
520251301

showing 5 of 8 rows

challenge 1

Create TEMP checked_dates using the validation rule and TEMP date_rejects with invalid rows.

Return row_id,raw_date,reason: missing for NULL, format for not exactly eight digits, otherwise calendar.

what to return

Columns
row_idraw_datereason in this order
Rows
any order
Also checked
TEMP / table changes from your script
challenge-1.sql
 
3 steps left · check both queries and pass the concept checkOpen the reportNext milestone
Quarantine bad rows & reconcile the batch — CRM + ERP Integration · Runtime