Skip to content

composite_foreign_key

sqllocks_spindle.engine.strategies.composite_foreign_key

Composite foreign key strategy — reference tables with multi-column PKs.

Use this when the parent table has a composite primary key and the child table needs FK columns that together point to a valid parent row.

Schema example — SalesReturn referencing FactInternetSales.(SalesOrderNumber, Line):

"SalesOrderNumber": {
    "generator": {
        "strategy": "composite_foreign_key",
        "ref_table": "FactInternetSales",
        "ref_columns": ["SalesOrderNumber", "SalesOrderLineNumber"],
        "distribution": "uniform"
    }
},
"SalesOrderLineNumber": {
    "generator": {
        "strategy": "composite_fk_field",
        "source_column": "SalesOrderNumber",
        "ref_column": "SalesOrderLineNumber"
    }
}

composite_foreign_key samples rows from the parent table and returns a dict mapping each ref_column to its value array. TableGenerator detects this dict return and writes each key to ctx.current_table so subsequent composite_fk_field columns can read them.

composite_fk_field reads one key from the dict stashed by the primary composite_foreign_key column. The two strategies are always used together.

Classes

CompositeForeignKeyStrategy

Bases: Strategy

Sample rows from a parent table with a composite PK.

Returns a dict {ref_column: ndarray} which TableGenerator expands into multiple ctx.current_table entries. The first ref_column is stored under the triggering column name; all columns are also stored under internal cache keys so CompositeFKFieldStrategy can retrieve them.

CompositeFKFieldStrategy

Bases: Strategy

Read one column from the dict stashed by CompositeForeignKeyStrategy.

Must come after the triggering composite_foreign_key column in the schema.