Synthetic Data Vault
GitHubSlackDataCebo
  • Welcome to the SDV!
  • Tutorials
  • Explore SDV
    • SDV Community
    • SDV Enterprise
      • ⭐Compare Features
    • SDV Bundles
      • ❖ AI Connectors
      • ❖ CAG
      • ❖ Differential Privacy
      • ❖ XSynthesizers
  • Single Table Data
    • Data Preparation
      • Loading Data
      • Creating Metadata
    • Modeling
      • Synthesizers
        • GaussianCopulaSynthesizer
        • CTGANSynthesizer
        • TVAESynthesizer
        • ❖ XGCSynthesizer
        • ❖ SegmentSynthesizer
        • * DayZSynthesizer
        • ❖ DPGCSynthesizer
        • ❖ DPGCFlexSynthesizer
        • CopulaGANSynthesizer
      • Customizations
        • Constraints
        • Preprocessing
    • Sampling
      • Sample Realistic Data
      • Conditional Sampling
    • Evaluation
      • Diagnostic
      • Data Quality
      • Visualization
  • Multi Table Data
    • Data Preparation
      • Loading Data
        • Demo Data
        • CSV
        • Excel
        • ❖ AlloyDB
        • ❖ BigQuery
        • ❖ MSSQL
        • ❖ Oracle
        • ❖ Spanner
      • Cleaning Your Data
      • Creating Metadata
    • Modeling
      • Synthesizers
        • * DayZSynthesizer
        • * IndependentSynthesizer
        • HMASynthesizer
        • * HSASynthesizer
      • Customizations
        • Constraints
        • Preprocessing
      • * Performance Estimates
    • Sampling
    • Evaluation
      • Diagnostic
      • Data Quality
      • Visualization
  • Sequential Data
    • Data Preparation
      • Loading Data
      • Cleaning Your Data
      • Creating Metadata
    • Modeling
      • PARSynthesizer
      • Customizations
    • Sampling
      • Sample Realistic Data
      • Conditional Sampling
    • Evaluation
  • Concepts
    • Metadata
      • Sdtypes
      • Metadata API
      • Metadata JSON
    • Constraints
      • Predefined Constraints
        • Positive
        • Negative
        • ScalarInequality
        • ScalarRange
        • FixedIncrements
        • FixedCombinations
        • ❖ FixedNullCombinations
        • ❖ MixedScales
        • OneHotEncoding
        • Inequality
        • Range
        • * ChainedInequality
      • Custom Logic
        • Example: IfTrueThenZero
      • ❖ Constraint Augmented Generation (CAG)
        • ❖ CarryOverColumns
        • ❖ CompositeKey
        • ❖ ForeignToForeignKey
        • ❖ ForeignToPrimaryKeySubset
        • ❖ PrimaryToPrimaryKey
        • ❖ PrimaryToPrimaryKeySubset
        • ❖ SelfReferentialHierarchy
        • ❖ ReferenceTable
        • ❖ UniqueBridgeTable
  • Support
    • Troubleshooting
      • Help with Installation
      • Help with SDV
    • Versioning & Backwards Compatibility Policy
Powered by GitBook

Copyright (c) 2023, DataCebo, Inc.

On this page
  • Constraint API
  • Usage
  1. Concepts
  2. Constraints
  3. ❖ Constraint Augmented Generation (CAG)

❖ CompositeKey

Previous❖ CarryOverColumnsNext❖ ForeignToForeignKey

Last updated 15 days ago

Use the CompositeKey constraint when multiple columns together form a primary key. Optionally, you may also have multi-column foreign key that connects to the primary key.

Constraint API

Create a CompositeKey constraint.

Parameters:

  • (required) table_name: A string with the name of the table that has the composite key

  • (required) primary_key: A list of strings representing all the columns in the table that form the composite, primary key

  • child_tables: A list of dictionaries that represent all the children of this table. Within each dictionary provide 'table_name' (the name of the child table) and 'foreign_key' (a list of columns that form the composite foreign key).

    • (default) None: The table does not have any children.

from sdv.cag import CompositeKey

my_constraint = CompositeKey(
    table_name='Patient Visits',
    primary_key=['Patient ID', 'Date'],
    child_tables=[{
        'child_table_name': 'Test Results',
        'foreign_key': ['Patient ID', 'Visit Date']
    }])

Usage

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

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

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

Make sure that all the table and columns in you provide are in your . If you provide any foreign key connections, make sure they align with the columns in the primary key.

Metadata
'Patient ID' and 'Date' together form the primary key of the table.

❖ SDV Enterprise bundle. This feature is available for purchase as an SDV Enterprise bundle. For more information, visit our page to Explore SDV.