Implementation:173TECH Sayn CopyTask
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Data_Engineering, ETL |
| Last Updated | 2026-10-17 00:00 GMT |
Overview
Concrete tool for copying tables between databases with full, incremental, and append modes, including column mapping and batched merge processing provided by the SAYN framework.
Description
The CopyTask class (inherits from SqlTask) moves data between database connections. It:
- Reads from a source database using SQLAlchemy introspection
- Creates a destination table with validated DDL
- Streams data from source to destination using server-side cursors
- Supports three modes:
full(replace),inc(merge by delete_key),append(add with timestamp) - Supports batched merge via
max_merge_rowsfor large incremental loads - Supports column renaming via
dst_nameand type inference from source
Usage
- Full copy: No
incremental_key— replaces destination table entirely - Incremental merge:
incremental_key+delete_key— only loads new records, merges by delete_key - Incremental append:
incremental_key+append: true— loads new records with_sayn_load_tstimestamp - Batched merge: Set
max_merge_rowsfor large incremental loads
Code Reference
Source Location
- Repository: SAYN
- File:
sayn/tasks/copy.py - Lines: L15-66 (
Source,Destinationmodels), L69-109 (Configmodel), L112-691 (CopyTaskclass)
Signature
class Source(BaseModel):
db_schema: Optional[str] = Field(None, alias="schema")
table: str
db: str
db_name: Optional[str]
class Destination(BaseModel):
tmp_schema: Optional[str]
db_schema: Optional[str] = Field(None, alias="schema")
table: str
db: Optional[str]
db_name: Optional[str]
class Config(BaseModel):
source: Source
destination: Destination
delete_key: Optional[str]
append: bool = False
incremental_key: Optional[str]
max_merge_rows: Optional[int]
max_batch_rows: Optional[int]
columns: Optional[List[Union[str, Dict[str, Any]]]] = list()
table_properties: Optional[List[Dict[str, Any]]] = list()
post_hook: Optional[List[Dict[str, Any]]] = list()
class CopyTask(SqlTask):
def config(self, **config) -> Result
def setup(self) -> Result
def run(self) -> Result
def compile(self) -> Result
def test(self) -> Result
def execute(self, execute: bool, debug: bool, is_full_load: bool, limit: int = None) -> Result[int]
def get_columns(self) -> Result
def get_read_query(self, execute: bool, debug: bool, is_full_load: bool, limit: int = None) -> Result[Select]
Import
from sayn.tasks.copy import CopyTask
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| source | Source | Yes Source db/schema/table configuration | |
| destination | Destination | Yes Destination db/schema/table configuration | |
| delete_key | str | No (required for inc) Merge deduplication key | |
| incremental_key | str | No Column for incremental filtering | |
| append | bool | No Append mode (with incremental_key) | |
| max_merge_rows | int | No Batch size for incremental merge | |
| max_batch_rows | int | No Insert batch size | |
| columns | List | No Column mapping with dst_name, type |
Outputs
| Name | Type | Description |
|---|---|---|
| records loaded | int Number of records loaded (from execute)
| |
| destination table | Database object Created, moved, or merged |
Usage Examples
Full Copy
# tasks/copy.yaml
copy_users:
type: copy
source:
table: users
db: source_db
destination:
table: users
schema: raw
db: warehouse
Incremental Merge
copy_orders:
type: copy
source:
table: orders
db: source_db
destination:
table: orders
db: warehouse
incremental_key: updated_at
delete_key: order_id
max_merge_rows: 100000
Append Mode
copy_events:
type: copy
source:
table: events
db: source_db
destination:
table: events_log
db: warehouse
incremental_key: event_id
append: true
With Column Mapping
copy_users:
type: copy
source:
table: users
db: source_db
destination:
table: users
db: warehouse
columns:
- name: user_id
type: INTEGER
tests:
- unique
- not_null
- name: email_address
dst_name: email
type: VARCHAR
Related Pages
Implements Principle
- Principle:173TECH_Sayn_Cross_Database_Copy
- Principle:173TECH_Sayn_Incremental_Loading
- Principle:173TECH_Sayn_Batch_Processing
- Principle:173TECH_Sayn_Column_DDL_Validation
Requires Environment
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment