spec
etl_craft.handlers.sql.spec ¶
A SQL task's parameters, read and checked before anything touches the warehouse.
Every mistake in a task's definition fails the task here with the parameter, its value and the remedy, so no action ever starts on a half-valid definition.
SQL_ACTION: one of the eight actions.TARGET_OBJECT:schema.table, in the active warehouse profile's database, ordatabase.schema.table.SOURCE_SQLorSOURCE_SQL_FILE(every action butDROP_TABLE): the read-only SELECT, inline or as a file undersql_files/; exactly one of them.PIPELINE_RUN_ID_SUBSTITUTION:truereplaces$$pipeline_run_idwith the run id.PIPELINE_RUN_ID_FILTER:truereplaces$$pipeline_run_id_filterwithpipeline_run_id = <id>, or1=1on a FULL refresh.RUN_DATE_SUBSTITUTION:truereplaces$$run_datewith the date the run runs as of,DATE 'YYYY-MM-DD': the day it started, or the date of a backfill run.MERGE_KEY(SCD1_MERGE,SCD2_MERGE,DELETE_ROWS):|-separated key columns.MERGE_COMPARE_COLUMNS(the merges): ordered|-separated scalar columns hashed into version-2HASH_KEY; floating point is refused, and decimals require a declared scale.MERGE_DEDUPE_ORDER(the merges):ORDER BYterms choosing the row kept per key.SCHEMA_EVOLUTION(OVERWRITE_TABLEand the merges):trueadds new SELECT columns to the target.PRESERVE_TARGET(SCD1_MERGE):truekeeps a target value where the source is NULL.HARD_DELETE(DELETE_ROWS):truedeletes rows; otherwise they getDELETE_FLAG='Y'.SETUP_FOR(SETUP_TABLE): the action that writes the table, whose audit columns it gets; needed when no other task in the pipeline writes it.
WRITERS
module-attribute
¶
WRITERS = frozenset({SqlAction.CREATE_TABLE, SqlAction.OVERWRITE_TABLE, SqlAction.APPEND_TABLE, SqlAction.SCD1_MERGE, SqlAction.SCD2_MERGE})
The actions that write rows into their target, and so have audit columns of their own.
PARAMETERS
module-attribute
¶
PARAMETERS = frozenset({'SQL_ACTION', 'TARGET_OBJECT', 'SOURCE_SQL', 'SOURCE_SQL_FILE', 'PIPELINE_RUN_ID_SUBSTITUTION', 'PIPELINE_ID_SUBSTITUTION', 'TASK_RUN_ID_SUBSTITUTION', 'PIPELINE_RUN_ID_FILTER', 'RUN_DATE_SUBSTITUTION', 'MERGE_KEY', 'MERGE_COMPARE_COLUMNS', 'MERGE_DEDUPE_ORDER', 'SETUP_FOR', 'TABLE_FORMAT', *FLAGS, *STORAGE_PARAMETERS})
The task parameters a SQL task reads.
SqlTask
dataclass
¶
A SQL task's checked definition.
select_sql is the SELECT with its tokens replaced, or None for DROP_TABLE;
source names where it came from, for messages.
read_sql_task ¶
Read and check the SQL task's parameters; SqlGuardError or MetadataError if wrong.
parse_flag ¶
Read a yes/no parameter: true or false in any case; absent means false.
resolve_select ¶
resolve_select(config: ConnectorConfig, params: Mapping[str, str], *, pipeline_run_id: int, refresh_type: str, run_date: date = LINEAGE_RUN_DATE, pipeline_id: int = 0, task_run_id: int = 0) -> tuple[str, str]
Return a SQL task's SELECT, inline or from its file, with the tokens replaced.
Also returns where it came from, for messages. SqlGuardError or MetadataError when
the task has no usable single read-only SELECT.