Search…
⌃K
Links

Multi Table Metadata

Use this guide to write a description for multi table data. You have multi table data if your data is present in multiple tables that have rows and columns. Usually the tables are connected to each other through primary and foreign key references.
This example of a Multi Table dataset has a table for users and a table for their sessions. Each user can have multiple sessions recorded.
Your data description is called metadata. SDMetrics expects metadata as a Python dictionary object.
This is the metadata dictionary for the illustrated table
{
"tables": {
"users": {
"primary_key": "user_id",
"fields": {
"user_id": {
"type": "id",
"subtype": "string",
"regex": "U_[0-9]{3}"
},
"age": {
"type": "numerical",
"subtype": "int"
},
"address": {
"type": "categorical",
"pii": True
}
}
},
"sessions": {
"primary_key": "session_id",
"fields": {
"session_id": {
"type": "id",
"subtype": "integer"
},
"user": {
"type": "id",
"ref": {
"table": "users",
"field": "user_id"
}
},
"date": {
"type": "datetime",
"format": "%Y-%m-%d"
},
"browser": {
"type": "categorical"
},
"bounced": {
"type": "boolean"
}
}
}
}
}

Metadata Specification

The file is an object that includes a dictionary named "tables".
{
"tables": {
<tables information>
},
}

Tables

The "tables" dictionary contains the information about each individual table of your application. Its keys are the table names and the values are dictionaries that describe each single table. This includes:
  • "primary_key": the column name used to identify a row in your table
  • (required) "fields": a dictionary description of each column
{
"tables": {
"users": {
"primary_key": "user_id",
"fields": { <column information> }
},
"sessions": {
"primary_key": "session_id",
"fields": { <column information> }
}
},
...
}

Column Information (Fields)

Inside "fields", you will describe each column. You'll start with the name of the column. Then you'll specify the type of data and any other information about it.
There are specific data types to choose from. Expand the options below to learn about the data types.
categorical
datetime
numerical
boolean
id
Use "type": "categorical" to represent data that has discrete categories
"tier": {
"type": "categorical",
}
Properties
  • "pii": True or False to represent whether the data is sensitive, meaning it should be anonymized in the synthetic data. By default, we assume the data is not sensitive.
Use "type": "datetime" to specify columns that represent points in time
"renew_date": {
"type": "datetime",
"format": "%Y-%m-%d"
}
Properties
  • (required) "format" to describe the format of the datetime string
The format string has special values to describe the components. For example, Jan 06, 2022 is represented as "%b %d, %Y"
See this documentation for a full list. Common values are:
  • Year: "%Y" for a 4-digit year like 2022, or "%y" for a 2-digit year like 22
  • Month: "%m" for a 2-digit month like 01, "%b" for an abbreviated month like Jan
  • Day: "%d" for a 2-digit day like 06
Use "type": "numerical" to specify columns that represent whole number or continuous values
"age": {
"type": "numerical",
"subtype": "integer",
},
"paid_amt": {
"type": "numerical",
"subtype": "float",
}
Properties
  • (required) "subtype": "float" or "integer" to specify whether this is a continuous value or a whole number
Use "type": "boolean" to represent column that have True/False values.
"active": {
"type": "boolean"
}
Properties: None
Use "type": "id" to represent any columns that act as row identifiers for the table. Usually, ID columns will either be the primary key of the table or a foreign key that refers to another table.
"user_id": {
"type": "id",
"subtype": "string",
"regex": "U_[0-9]{3}"
}
Properties
  • (required) "subtype": Either an "integer" or "string"
  • "regex": A regular expression describing how to create the id, if the id is a string
  • "ref": If this column is a foreign key, add a dictionary to represent which other column it refers to. This includes "table", the name of the other table, and "field", the name of the column in the other table.
"user_id": {
"type": "id",
"ref": {
"table": "users",
"field": "user_id"
}
}

Saving & Loading Metadata

After creating your dictionary, you can save it as a JSON file. For example, my_metadata_file.json.
import json
with open('my_metadata_file.json', 'w') as f:
json.dump(my_metadata_dict, f)
In the future, you can load the Python dictionary by reading from the file.
import json
with open('my_metadata_file.json') as f:
my_metadata_dict = json.load(f)
# use my_metadata_dict in the SDMetrics library