Principle:173TECH Sayn Batch Processing
| Knowledge Sources | |
|---|---|
| Domains | Data_Engineering, ETL |
| Last Updated | 2026-10-17 00:00 GMT |
Overview
Technique for processing large incremental loads in bounded batches to control memory usage and enable resumable merge operations.
Description
Batch processing in SAYN applies to incremental copy tasks with max_merge_rows. Instead of loading and merging the entire incremental dataset at once, the task:
- Loads a batch of
max_merge_rowsrecords - Merges the batch into the destination
- Repeats until fewer than
max_merge_rowsrecords are returned (indicating the last batch) - Capped at 100 iterations to prevent infinite loops
This solves the problem of large incremental loads that would exceed memory or transaction limits. Additionally, max_batch_rows controls the INSERT batch size within each load operation.
Usage
Use this principle when incremental datasets are too large for a single merge operation. Set max_merge_rows for the outer merge loop and max_batch_rows for the inner insert batching.
Theoretical Basis
The batched merge loop:
# Abstract algorithm (NOT real implementation)
for _ in range(100): # Safety cap
count = execute(limit=max_merge_rows)
if count < max_merge_rows:
break # Last batch
Each batch:
- Query source with
LIMIT max_merge_rowsordered by incremental_key - Load into temp table
- Merge temp into destination by delete_key
- Drop temp table
Practical Guide
# tasks/copy.yaml
copy_large_table:
type: copy
source:
table: events
db: source_db
destination:
table: events
db: warehouse
incremental_key: event_id
delete_key: event_id
max_merge_rows: 100000 # Merge in batches of 100k
max_batch_rows: 5000 # Insert in batches of 5k