Skip to main content

Module generate

Module generate 

Source
Expand description

Synthetic data generation engine.

This module hosts the pieces generators are built from: stable, seedable RNG streams (seed) so a run is fully reproducible from a single root seed, and a dialect-agnostic value representation (value) that generators produce instead of writing SQL literals directly.

§The public builder

Generate is the one-call facade: it loads a kind: model document, compiles it, runs the generation engine, and renders SQL to a file — the complete pipeline behind a single GenerateBuilder.

use sql_splitter::generate::Generate;

let dir = tempfile::tempdir()?;
let output = dir.path().join("synthetic.sql");

let report = Generate::builder()
    .config("tests/fixtures/generate/simple.yaml")
    .output(&output)
    .seed(42)
    .run()?;

assert!(report.rows_written > 0);
assert!(std::fs::read_to_string(&output)?.contains("INSERT INTO"));

See builder_generates_from_a_complete_model in tests/generate_api_test.rs for more builder-driven workflows (dump profiling, --check, --dry-run, --verify, table/seed overrides).

§The staged API

Callers that need to drive an individual stage directly — a custom statically linked ExtensionRegistry, mid-pipeline inspection, or a destination that is not a plain file — can assemble the same four stages Generate wires together: an ExtensionRegistry feeds a ModelCompiler, which produces a GenerationPlan that a GenerationEngine drives against any RowSink, most commonly a crate::render::SqlRenderer.

use sql_splitter::generate::{CompileOptions, ExtensionRegistry, GenerationEngine, ModelCompiler};
use sql_splitter::render::{RenderOptions, SqlRenderer};
use sql_splitter::synthetic::SyntheticFile;

let model = SyntheticFile::parse_str(
    r#"
version: 1
kind: model
defaults: { inference: disabled }
seed: 1
tables:
  users:
    rows: { kind: fixed, count: 3 }
    schema:
      name: users
      primary_key: [id]
      columns:
        - { name: id, type: bigint, nullable: false, primary_key: true }
        - { name: name, type: "varchar(50)", nullable: false }
    columns:
      id:
        generator: { kind: sequence, start: 1 }
      name:
        generator: { kind: string, min_length: 3, max_length: 8 }
"#,
)?
.into_model()
.expect("is a complete model");

let registry = ExtensionRegistry::standard();
let plan = ModelCompiler::new(registry).compile(model, CompileOptions::default())?;

let mut renderer = SqlRenderer::new(Vec::new(), RenderOptions::default());
GenerationEngine::new(plan).run(&mut renderer)?;
let bytes = renderer.finish()?;

assert!(String::from_utf8(bytes)?.contains("INSERT INTO"));

(Profiling a model from a dump — a DumpProfiler/ModelInference stage ahead of the compiler — is wired into Generate::run itself: pass GenerateBuilder::input to profile a dump into a base model, optionally merging a kind: overrides .config() on top.)

See staged_api_renders_inserts in tests/generate_engine_test.rs for a worked example of assembling the stages by hand, including a custom ExtensionRegistry.

Re-exports§

pub use crate::render::RenderOptions;
pub use crate::render::SqlRenderer;
pub use crate::synthetic::SyntheticModel;
pub use compiler::CompileOptions;
pub use compiler::ModelCompiler;
pub use compiler::TableCountKind;
pub use compiler::TableCountOverride;
pub use engine::DenseIntegerKey;
pub use engine::EngineReport;
pub use engine::GeneratedRow;
pub use engine::GenerationEngine;
pub use engine::KeyDomain;
pub use engine::RandomAccessKeyGenerator;
pub use engine::RowSink;
pub use generators::ConstantFactory;
pub use output::install_interrupt_handler;
pub use output::publish_in_order;
pub use output::AtomicOutput;
pub use output::CancellationToken;
pub use output::FamilyBudget;
pub use output::FamilyBuffer;
pub use output::FamilyState;
pub use output::PartialPublication;
pub use output::ProtectedSpool;
pub use output::PublicationSet;
pub use output::SpillKind;
pub use output::SpoolReader;
pub use output::SpoolWriter;
pub use output::SpooledRow;
pub use output::TempConfig;
pub use plan::ColumnOwner;
pub use plan::CompiledOutput;
pub use plan::CompiledRelationship;
pub use plan::DeferredConstraints;
pub use plan::ExecutionPhase;
pub use plan::FamilyPhase;
pub use plan::GenerationPlan;
pub use plan::PlanEstimates;
pub use plan::PlannedColumn;
pub use plan::PlannedTable;
pub use plan::RelationshipDistribution;
pub use plan::ResolvedTableSeed;
pub use registry::ArgumentSpec;
pub use registry::Buffering;
pub use registry::ColumnScope;
pub use registry::CompileContext;
pub use registry::CompiledGenerator;
pub use registry::CompiledModifier;
pub use registry::CompiledPlanner;
pub use registry::Determinism;
pub use registry::ExtensionRegistry;
pub use registry::FamilySumCheck;
pub use registry::GeneratorDescriptor;
pub use registry::GeneratorFactory;
pub use registry::KeyRecipe;
pub use registry::ModifierDescriptor;
pub use registry::ModifierFactory;
pub use registry::PlanContext;
pub use registry::PlannerDescriptor;
pub use registry::PlannerFactory;
pub use registry::PlannerPredicate;
pub use registry::PredicateGuard;
pub use registry::RowContext;
pub use registry::RowView;
pub use registry::Verification;
pub use seed::derive_seed;
pub use seed::SeedRoot;
pub use seed::StreamId;
pub use value::GenerateError;
pub use value::GeneratedValue;
pub use verify::CheckOutcome;
pub use verify::CheckStatus;
pub use verify::DistributionExpectation;
pub use verify::GenerationVerifier;
pub use verify::VerificationReport;

Modules§

compiler
The ModelCompiler: turns a complete model plus CLI options into an immutable GenerationPlan.
engine
The GenerationEngine: streams rows from a compiled GenerationPlan.
generators
Built-in generator factories.
output
Protected family state, spooling, and atomic publication.
plan
The immutable GenerationPlan: the compiler’s output.
planners
Built-in planner factories.
registry
The typed extension registry: how generators, modifiers, and planners are declared, discovered, and turned into runnable operators.
seed
Stable, deterministic seed derivation for synthetic data generation.
value
Typed representation of a single generated value.
verify
Post-generation verification: reparse protected output and audit it before publication.

Structs§

ExplainColumn
One column’s inference decision, reshaped for --explain reporting. Carries the winning rule’s reason/confidence and the rejected alternatives — never any observed values.
ExplainRejected
One rejected alternative recorded for ExplainColumn.
Generate
The public generation facade: loads a model, compiles it, and — under RunMode::Generate — runs the engine and renders SQL. Build a request with Generate::builder.
GenerateBuilder
Builds one GenerateRequest and runs it. The only validation performed here is request shape (e.g. RunMode::Generate needs an output path); anything about the model itself — a missing config, a compile error — surfaces from Generate::run as a structured GenerateError.
GenerateReport
A summary of a completed Generate::run.
GenerateRequest
One fully-specified generation request: everything Generate::run needs, assembled by a GenerateBuilder (or constructed directly by a caller that wants to bypass the builder).
SourceOptions
Controls for profiling a source dump named by GenerateRequest::input.

Enums§

OutputTarget
Where a Generate::run renders its SQL, or whether it renders none.
RunMode
How a Generate::run call should treat the compiled model.