SQLValidator

package
v0.11.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator produces SQL SELECT statements that reference the TPC-C schema. All generated queries are read-only; data integrity is maintained by the setup phase in Validator.

func NewGenerator

func NewGenerator(lcg *LCG) *Generator

NewGenerator creates a Generator that uses the given LCG for randomness.

func (*Generator) Next

func (g *Generator) Next() string

Next returns the next randomly generated SQL statement. The statement is guaranteed to be syntactically valid for SQLite/sqlvibe.

type LCG

type LCG struct {
	// contains filtered or unexported fields
}

LCG implements a Linear Congruential Generator using Knuth MMIX parameters for a deterministic, reproducible pseudo-random number stream.

Parameters:

Multiplier: 6364136223846793005
Increment:  1442695040888963407
Modulus:    2^64 (implicit via uint64 overflow)

func NewLCG

func NewLCG(seed uint64) *LCG

NewLCG creates a new LCG with the given seed.

func (*LCG) Choice

func (l *LCG) Choice(items []string) string

Choice returns a uniformly random element from items. Returns "" if items is empty.

func (*LCG) Float64

func (l *LCG) Float64() float64

Float64 returns a pseudo-random float64 in [0.0, 1.0).

func (*LCG) Intn

func (l *LCG) Intn(n int) int

Intn returns a pseudo-random int in [0, n). Returns 0 if n <= 0.

func (*LCG) Next

func (l *LCG) Next() uint64

Next advances the LCG state and returns the next pseudo-random uint64.

type Mismatch

type Mismatch struct {
	Query         string
	SQLiteResult  QueryResult
	SQLVibeResult QueryResult
	Reason        string
}

Mismatch describes a single discrepancy found by the validator.

func Compare

func Compare(query string, liteRes, svibeRes QueryResult) *Mismatch

Compare returns a Mismatch if the two results differ, or nil if they match.

Comparison rules:

  1. Both error → match (we don't compare error message text).
  2. One error, other success → mismatch.
  3. Both success → rows are sorted and compared cell-by-cell with float tolerance; NULL == NULL is true.

type QueryResult

type QueryResult struct {
	// Columns is nil for non-SELECT statements.
	Columns []string
	// Rows holds the result rows; each row is a slice of Go values
	// (int64, float64, string, or nil for NULL).
	Rows [][]interface{}
	// Err is non-nil when the statement caused an error.
	Err error
}

QueryResult holds the outcome of running a single SQL statement.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator runs the same SQL statements against both SQLite and sqlvibe and reports any result mismatches.

func NewValidator

func NewValidator(seed uint64) (*Validator, error)

NewValidator creates a Validator with the given LCG seed. Both SQLite and sqlvibe databases are created in-memory and seeded with the TPC-C starter dataset.

func (*Validator) Close

func (v *Validator) Close()

Close releases all resources held by the Validator.

func (*Validator) Run

func (v *Validator) Run(n int, onMatch func(idx int, query string, liteRes, svibeRes QueryResult)) ([]Mismatch, error)

Run generates n random SQL statements, executes each against both backends, and collects any mismatches. It calls onMatch after each execution to allow immediate result checking.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL