❖ PrimaryToPrimaryKey

SDV Enterprise Bundle. This feature is available as part of the CAG Bundle, an optional add-on to SDV Enterprise. For more information, please visit the CAG Bundle page.

Use the PrimaryToPrimaryKey constraint when you have an exact 1-to-1 connection between the primary keys of two or more tables.

In this example, the table 'Users' has an exact 1-to-1 relationship with the table 'Supplemental Info'. Both tables are connected via the same primary key ID value.

Constraint API

Create a PrimaryToPrimaryKey constraint

Parameters:

  • (required) table_names: A list of strings, representing the table names whose primary keys are all connected. You must provide two or more table names.

from sdv.cag import PrimaryToPrimaryKey

my_constraint = PrimaryToPrimaryKey(
    table_names=['Users', 'Supplemental Info'])

Make sure that all the tables in you provide are in your Metadata, and have a primary key associated with them.

Usage

Apply the constraint to any SDV synthesizer. Then fit and sample as usual.

synthesizer = HSASynthesizer(metadata)
synthesizer.add_constraints([my_constraint])

synthesizer.fit(data)
synthetic_data = synthesizer.sample()

For more information about using predefined constraints, please see the Constraint-Augmented Generation tutorial.

Last updated