Write a SQL query to compare batch-loaded and streaming-loaded records and identify mismatches.
Compare the latest version of each record_id from both tables. Include records present in only one source, and identify differences in entity, event type, event value, event timestamp, or payload hash.
record_id.record_id ascending.record_id, comparison_status, mismatch_fields, batch_entity_id, stream_entity_id, batch_event_type, stream_event_type, batch_event_value, stream_event_value, batch_event_ts, stream_event_ts, batch_payload_hash, stream_payload_hash.loaded_at descending, breaking ties with ingestion_id descending.MATCH, MISMATCH, BATCH_ONLY, and STREAM_ONLY exactly as spelled.NULL values as equal, but treat NULL and any non-NULL value as different when comparing fields.entity_id, event_type, event_value, event_ts, payload_hash, separated by comma-space.missing_batch_record and missing_stream_record for one-sided rows, and an empty value for matching rows' mismatch_fields field.| Column | Type | Description |
|---|---|---|
| ingestion_idPK | INT | Unique batch ingestion row identifier |
| record_id | INT | Business identifier of the loaded record |
| entity_id | INT | Identifier of the related entity |
| event_type | VARCHAR(30) | Type of business event |
| event_value | DECIMAL(12,2) | Numeric value associated with the event |
| event_ts | TIMESTAMP | Timestamp at which the event occurred |
| payload_hash | VARCHAR(64) | Hash of the source payload |
| loaded_at | TIMESTAMP | Timestamp when the batch row was loaded |
| Column | Type | Description |
|---|---|---|
| ingestion_idPK | INT | Unique streaming ingestion row identifier |
| record_id | INT | Business identifier of the streamed record |
| entity_id | INT | Identifier of the related entity |
| event_type | VARCHAR(30) | Type of business event |
| event_value | DECIMAL(12,2) | Numeric value associated with the event |
| event_ts | TIMESTAMP | Timestamp at which the event occurred |
| payload_hash | VARCHAR(64) | Hash of the source payload |
| loaded_at | TIMESTAMP | Timestamp when the streaming row was loaded |