Transform actions¶
A transform action reads one or more upstream views and produces a target
view (or, for temp_table, a temporary table). Every transform sets
type: transform and a transform_type of sql, python,
data_quality, temp_table, or schema. Type-specific fields are flat
on the action.
See also
How-to guides: Reshape data with a SQL transform, Reshape data with a Python transform, Enforce a schema on a view, Stage an intermediate result in a temp table, Gate rows with data-quality expectations.
Common fields¶
Fields accepted by every transform_type. Type-specific fields are listed in
each section below.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Action name, unique within the flowgroup. |
|
string |
Yes |
— |
Always |
|
string |
Yes |
— |
One of |
|
string |
Yes |
— |
Name of the produced view (or temporary table). Required for all transforms. |
|
string / list |
Yes |
— |
Upstream view name(s). Accepted shape and requirement vary per type — see each section. |
|
string |
No |
auto |
Comment on the generated view/table. Defaults to an auto-generated string. |
|
bool / list |
No |
— |
Add operational metadata columns; a list selects column names. Honored by |
|
list |
No |
— |
Extra upstream table references ( |
sql¶
Runs a SQL query over the source view(s) and emits a @dp.temporary_view.
Requires exactly one of sql or sql_path.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string / list |
Yes |
— |
Input view name(s). |
|
string |
Cond. |
— |
Inline SQL query. Exactly one of |
|
string |
Cond. |
— |
Path to an external |
Substitution tokens (${token}, ${secret:scope/key}) are resolved in both
inline SQL and external files. Wrap a source in stream(view_name) inside the
query to read it as a stream.
- name: transform_orders
type: transform
transform_type: sql
source: v_orders_raw
target: v_orders
sql: "SELECT * FROM v_orders_raw WHERE amount > 0"
python¶
Calls a function in a project Python module and emits a @dp.temporary_view.
The whole module file is copied to generated/<pipeline>/custom_python_functions/
and imported as from custom_python_functions.<module> import <function>.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string / list |
Yes |
— |
Input view name(s); |
|
string |
Yes |
— |
Path to a |
|
string |
Yes |
— |
Name of the function to call. |
|
dict |
No |
|
Passed to the function as its |
|
string |
No |
|
|
Function signature: single source def fn(df, spark, parameters); list source
def fn(dataframes, spark, parameters); no source def fn(spark, parameters).
- name: transform_enrich
type: transform
transform_type: python
source: v_orders
target: v_orders_enriched
module_path: "transforms/enrich.py"
function_name: enrich
parameters:
lookup: regions
data_quality¶
Applies expectation rules to the source view. mode: dqe emits a
@dp.temporary_view decorated with expectation decorators; mode: quarantine
emits a Delta dead-letter (DLQ) subsystem that routes violating rows to a
quarantine table. readMode must be stream.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Input view name. |
|
string |
Yes |
— |
Path to a YAML expectations file, relative to project root. |
|
string |
No |
|
|
|
object |
Cond. |
— |
Required when |
|
string |
No |
|
Must be |
The expectations file is a YAML mapping. Each key is a boolean SQL expression
the row must satisfy; each value sets a per-rule action and optional name.
Key |
Type |
Default |
Description |
|---|---|---|---|
|
mapping key |
— |
A boolean SQL expression, e.g. |
|
string |
|
|
|
string |
the expression |
Rule name used as the key in the emitted expectation dict. |
Each action maps to a Lakeflow expectation decorator (dqe mode):
|
Decorator |
Behavior |
|---|---|---|
|
|
Logs a warning; keeps violating rows. Default. |
|
|
Drops violating rows. |
|
|
Fails the pipeline on any violation. |
In quarantine mode every rule is coerced to drop regardless of its
configured action; warn / fail rules trigger a validation warning. The
DLQ outbox table is derived as <dlq_table>_outbox.
- name: dq_orders
type: transform
transform_type: data_quality
source: v_orders
target: v_orders_validated
expectations_file: "expectations/orders.yaml"
mode: dqe
readMode: stream
# expectations/orders.yaml
order_id IS NOT NULL:
action: drop
name: valid_order_id
amount >= 0:
action: warn
name: non_negative_amount
Quarantine mode replaces the inline decorators with the DLQ subsystem:
- name: dq_orders
type: transform
transform_type: data_quality
source: v_orders
target: v_orders_validated
expectations_file: "expectations/orders.yaml"
mode: quarantine
readMode: stream
quarantine:
dlq_table: main.ops.orders_dlq
source_table: main.bronze.orders
temp_table¶
Materializes an intermediate temporary table via @dp.table(temporary=True),
cleaned up when the pipeline run completes.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string / dict |
Yes |
— |
Input view name (string), or a dict with a |
|
string |
No |
— |
Optional query. The literal |
|
string |
No |
|
|
- name: stage_orders
type: transform
transform_type: temp_table
source: v_orders
target: tmp_orders
sql: "SELECT * FROM {source} WHERE status = 'open'"
schema¶
Renames, casts, and (in strict mode) filters columns of the source view via a
schema mapping, emitting a @dp.temporary_view. Requires exactly one of
schema_inline or schema_file.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Input view name. Must be a plain string (the nested |
|
string |
Cond. |
— |
Inline schema definition (arrow or structured YAML). Exactly one of |
|
string |
Cond. |
— |
Path to an external schema file. Exactly one of |
|
string |
No |
|
|
|
string |
No |
|
|
Schema definitions use arrow syntax, one entry per column:
old_col -> new_col: BIGINT— rename and cast.old_col -> new_col— rename only.col: DECIMAL(18,2)— cast in place.col— pass through / explicit keep (strictmode).
A $ is allowed in a source-column name (left of ->, a cast-only col,
or a pass-through col). A rename target (right of ->) must be a clean
identifier of letters, digits, and underscores; anything else raises
LHP-VAL-011.
- name: enforce_schema
type: transform
transform_type: schema
source: v_orders
target: v_orders_typed
schema_file: "schemas/orders.yaml"
enforcement: strict