Skip to content

computed

sqllocks_spindle.engine.strategies.computed

Computed strategy — aggregate from child table (filled in post-processing).

Classes

ComputedStrategy

Bases: Strategy

Placeholder for computed columns that depend on child table data.

These columns are initially filled with NaN/placeholder values during the main generation pass, then back-filled during the compute phase after child tables are generated.

Examples:

order.order_total = sum(order_line.line_total) per order_id

Methods:
backfill(parent_df, child_df, parent_pk, child_fk, child_column, target_column, rule='sum_children') staticmethod

Back-fill computed column from child table aggregation.

Parameters:

Name Type Description Default
parent_df

Parent DataFrame to update (the table owning target_column).

required
child_df

DataFrame to aggregate/lookup from.

required
parent_pk str

PK column name in parent_df.

required
child_fk str

FK column in child_df referencing parent_pk.

required
child_column str

Column in child_df to aggregate or copy.

required
target_column str

Column in parent_df to fill.

required
rule str

Aggregation rule. See below for supported values.

'sum_children'

Child-aggregation rules (parent_df is the parent, child_df is the child): sum_children, count_children, avg_children, min_children, max_children

Parent-lookup rule (parent_df is the child, child_df is the parent): lookup_parent — copy a value from parent_df[child_fk] → child_df[parent_pk] into target_column. Used when the "computed" column lives on the child table and copies a value from the parent.