-
Notifications
You must be signed in to change notification settings - Fork 5
SQL DDL Schema Examples
Supported for the documented subset. Great Generator supports compact DDL strings and full SQL CREATE TABLE ingestion through parse_ddl(...).
Use compact DDL for quick one-table schemas. Use full SQL DDL when you want a canonical contract with table names, keys, foreign keys, constraints, stable hashing, and parser diagnostics.
from great_generator import generate_from_schema
ddl = "customer_id string, customer_name string, age int, balance decimal(12,2), created_at timestamp"
df = generate_from_schema(ddl, rows=1000)
print(df.head())
df.to_parquet("customers.parquet", index=False)from great_generator import generate_from_schema, parse_ddl
ddl = """
CREATE TABLE sales.customers (
customer_id BIGINT PRIMARY KEY,
customer_name STRING NOT NULL,
email VARCHAR(120) UNIQUE,
signup_date DATE
);
CREATE TABLE sales.orders (
order_id BIGINT PRIMARY KEY,
customer_id BIGINT NOT NULL,
order_amount DECIMAL(12, 2),
order_date DATE,
CONSTRAINT fk_orders_customers
FOREIGN KEY (customer_id) REFERENCES sales.customers(customer_id)
)
"""
contract = parse_ddl(ddl, dialect="databricks")
print(contract.fingerprint())
print(contract.tables["sales.orders"].foreign_keys[0].parent_table)customer_contract = parse_ddl(
"""
CREATE TABLE customers (
customer_id BIGINT PRIMARY KEY,
customer_name STRING,
email STRING,
signup_date DATE
)
""",
dialect="databricks",
)
df = generate_from_schema(customer_contract, rows=1000)data = generate_from_schema(
contract,
rows={"sales.customers": 1000, "sales.orders": 5000},
)
customers = data["sales.customers"]
orders = data["sales.orders"]Simple single-column relationships can generate through the existing path. Composite-key and cyclic relationships are parsed as metadata today and planned for a later relational generation milestone.
| Construct | Status |
|---|---|
One or more CREATE TABLE statements |
Supported |
| Schema-qualified names | Supported |
| Quoted identifiers | Supported |
| Scalar ANSI, Spark, and Databricks types | Supported |
| Inline and table primary keys | Supported |
| Composite primary keys | Parsed as metadata |
| Inline and table foreign keys | Supported |
| Composite foreign keys | Parsed as metadata |
| Multiple foreign keys | Supported |
| Self-referencing foreign keys | Parsed as metadata |
| Unique constraints | Supported |
| Check constraints | Stored as metadata |
| Defaults and comments | Stored as metadata |
USING DELTA and PARTITIONED BY
|
Stored as metadata |
Supported type families include INT, BIGINT, STRING, VARCHAR, CHAR, TEXT, DECIMAL, NUMERIC, DOUBLE, FLOAT, BOOLEAN, DATE, TIMESTAMP, TIMESTAMP_NTZ, and BINARY.
from great_generator.contracts import ContractParseError
try:
parse_ddl(ddl, dialect="databricks", strict=True)
except ContractParseError as exc:
for diagnostic in exc.diagnostics:
print(diagnostic.construct, diagnostic.message)strict=True fails on unsupported contract-affecting syntax. strict=False can return warnings only when the remaining contract can still be represented safely.
- Great Generator supports a tested ANSI, Spark, and Databricks subset. It does not claim complete coverage for every database dialect.
- Unknown types and malformed key definitions are errors.
- Composite and cyclic relationship metadata is parsed, but full generation strategy support for those advanced cases is planned later.
- Home
- Problem Statement
- Quick Start
- Generate Related Tables
- Query-Aware Generation
- Supported Schema Inputs
- Function Comparison
- Getting Started
- Plain Dictionary
- Rich Dictionary
- Pandas
- PySpark StructType
- Contracts and SQL DDL
- Schema Generation
- JSON Schema
- YAML Schema Profile