From e0552629e32b0bc35271ac4fb567ddfd3e7b8bc0 Mon Sep 17 00:00:00 2001 From: pedrocarlo Date: Wed, 27 Aug 2025 01:11:25 -0300 Subject: [PATCH] create Generation Options structs --- simulator/generation/mod.rs | 6 +-- simulator/runner/env.rs | 9 +++++ sql_generation/generation/mod.rs | 15 +------- sql_generation/generation/opts.rs | 62 +++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 sql_generation/generation/opts.rs diff --git a/simulator/generation/mod.rs b/simulator/generation/mod.rs index 79bdf506f..a63936ab5 100644 --- a/simulator/generation/mod.rs +++ b/simulator/generation/mod.rs @@ -25,9 +25,7 @@ impl GenerationContext for SimulatorEnv { &self.tables.tables } - fn opts(&self) -> sql_generation::generation::Opts { - sql_generation::generation::Opts { - indexes: self.opts.experimental_indexes, - } + fn opts(&self) -> &sql_generation::generation::Opts { + &self.gen_opts } } diff --git a/simulator/runner/env.rs b/simulator/runner/env.rs index a29adc591..50b21c61a 100644 --- a/simulator/runner/env.rs +++ b/simulator/runner/env.rs @@ -7,6 +7,7 @@ use std::sync::Arc; use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha8Rng; +use sql_generation::generation::Opts; use sql_generation::model::table::Table; use turso_core::Database; @@ -59,6 +60,7 @@ impl Deref for SimulatorTables { pub(crate) struct SimulatorEnv { pub(crate) opts: SimulatorOpts, + pub gen_opts: Opts, pub(crate) connections: Vec, pub(crate) io: Arc, pub(crate) db: Option>, @@ -85,6 +87,7 @@ impl SimulatorEnv { paths: self.paths.clone(), type_: self.type_, phase: self.phase, + gen_opts: self.gen_opts.clone(), } } @@ -291,6 +294,11 @@ impl SimulatorEnv { .map(|_| SimConnection::Disconnected) .collect::>(); + let gen_opts = Opts { + indexes: opts.experimental_indexes, + ..Default::default() + }; + SimulatorEnv { opts, tables: SimulatorTables::new(), @@ -301,6 +309,7 @@ impl SimulatorEnv { db: Some(db), type_: simulation_type, phase: SimulationPhase::Test, + gen_opts, } } diff --git a/sql_generation/generation/mod.rs b/sql_generation/generation/mod.rs index 25bd7ec09..6d475590a 100644 --- a/sql_generation/generation/mod.rs +++ b/sql_generation/generation/mod.rs @@ -3,24 +3,13 @@ use std::{iter::Sum, ops::SubAssign}; use anarchist_readable_name_generator_lib::readable_name_custom; use rand::{distr::uniform::SampleUniform, Rng}; -use crate::model::table::Table; - +pub mod opts; pub mod expr; pub mod predicate; pub mod query; pub mod table; -#[derive(Debug, Clone, Copy)] -pub struct Opts { - /// Indexes enabled - pub indexes: bool, -} - -/// Trait used to provide context to generation functions -pub trait GenerationContext { - fn tables(&self) -> &Vec; - fn opts(&self) -> Opts; -} +pub use opts::*; type ArbitraryFromFunc<'a, R, T> = Box T + 'a>; type Choice<'a, R, T> = (usize, Box Option + 'a>); diff --git a/sql_generation/generation/opts.rs b/sql_generation/generation/opts.rs new file mode 100644 index 000000000..d9caf81d7 --- /dev/null +++ b/sql_generation/generation/opts.rs @@ -0,0 +1,62 @@ +use std::ops::Range; + +use crate::model::table::Table; + +#[derive(Debug, Clone)] +pub struct Opts { + /// Indexes enabled + pub indexes: bool, + pub table: TableOpts, +} + +impl Default for Opts { + fn default() -> Self { + Self { + indexes: true, + table: Default::default(), + } + } +} + +/// Trait used to provide context to generation functions +pub trait GenerationContext { + fn tables(&self) -> &Vec
; + fn opts(&self) -> &Opts; +} + +#[derive(Debug, Clone)] +pub struct TableOpts { + pub large_table: LargeTableOpts, + /// Range of numbers of columns to generate + pub column_range: Range, +} + +impl Default for TableOpts { + fn default() -> Self { + Self { + large_table: Default::default(), + // Up to 10 columns + column_range: 1..11, + } + } +} + +/// Options for generating large tables +#[derive(Debug, Clone)] +pub struct LargeTableOpts { + pub enable: bool, + pub large_table_prob: f32, + /// Range of numbers of columns to generate + pub column_range: Range, +} + +impl Default for LargeTableOpts { + fn default() -> Self { + Self { + enable: true, + large_table_prob: 0.1, + // todo: make this higher (128+) + column_range: 64..125, + } + } +}