sqlsmith

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

README

SQLsmith-GO

Go version of SQLsmith.

Usage

import (
	sqlsmith_go "github.com/pingcap/tipocket/pkg/go-sqlsmith"
)

func gosmith() {
	ss := sqlsmith_go.New()

	// load schema
	ss.LoadSchema([][5]string{
		// members table
		[5]string{"games", "members", "BASE TABLE", "id", "int(11)"},
		[5]string{"games", "members", "BASE TABLE", "name", "varchar(255)"},
		[5]string{"games", "members", "BASE TABLE", "age", "int(11)"},
		[5]string{"games", "members", "BASE TABLE", "team_id", "int(11)"},
		// teams table
		[5]string{"games", "teams", "BASE TABLE", "id", "int(11)"},
		[5]string{"games", "teams", "BASE TABLE", "team_name", "varchar(255)"},
		[5]string{"games", "teams", "BASE TABLE", "created_at", "timestamp"},
	})

	// use games database
	ss.SetDB("games")

	// generate select statement AST without scema information
	node := ss.SelectStmt(5)

	// fill the tree with selected schema and get SQL string
	sql, err := ss.Walk(node)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() generator.Generator

New create SQLSmith instance

Types

type DataGenerator

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

DataGenerator defines data generator

func (*DataGenerator) Next

func (d *DataGenerator) Next() []string

Next returns data batch

type SQLSmith

type SQLSmith struct {
	Rand      *rand.Rand
	Databases map[string]*types.Database

	Node ast.Node
	// contains filtered or unexported fields
}

SQLSmith defines SQLSmith struct

func (*SQLSmith) AlterTableStmt

func (s *SQLSmith) AlterTableStmt(opt *generator.DDLOptions) (string, error)

AlterTableStmt alter table

func (*SQLSmith) BatchData

func (s *SQLSmith) BatchData(total, batchSize int) ([]string, error)

BatchData generate testing data by schema in given batch return SQLs with insert statement

func (*SQLSmith) BeginWithOnlineTables

func (s *SQLSmith) BeginWithOnlineTables(opt *generator.DMLOptions) []string

BeginWithOnlineTables begins a transaction with some online tables

func (*SQLSmith) CreateIndexStmt

func (s *SQLSmith) CreateIndexStmt(opt *generator.DDLOptions) (string, error)

CreateIndexStmt create index

func (*SQLSmith) CreateTableStmt

func (s *SQLSmith) CreateTableStmt() (string, string, error)

CreateTableStmt create table

func (*SQLSmith) Debug

func (s *SQLSmith) Debug()

Debug turn on debug mode

func (*SQLSmith) DeleteStmt

func (s *SQLSmith) DeleteStmt() (string, string, error)

DeleteStmt implement delete statement from AST

func (*SQLSmith) EndTransaction

func (s *SQLSmith) EndTransaction() []string

EndTransaction ends transaction and set every table offline

func (*SQLSmith) GenData

func (s *SQLSmith) GenData(total, batch int) (*DataGenerator, error)

GenData returns data generator

func (*SQLSmith) GetCurrDBName

func (s *SQLSmith) GetCurrDBName() string

GetCurrDBName returns current selected dbname

func (*SQLSmith) GetDB

func (s *SQLSmith) GetDB(db string) *types.Database

GetDB get current database without nil

func (*SQLSmith) Hint

func (s *SQLSmith) Hint() bool

Hint ...

func (*SQLSmith) InsertStmt

func (s *SQLSmith) InsertStmt(fn bool) (string, string, error)

InsertStmt implement insert statement from AST

func (*SQLSmith) InsertStmtStr

func (s *SQLSmith) InsertStmtStr(fn bool) (string, string, error)

InsertStmtStr make random insert statement SQL

func (*SQLSmith) LoadSchema

func (s *SQLSmith) LoadSchema(records [][5]string, indexes map[string][]string)

LoadSchema init schemas, tables and columns record[0] dbname record[1] table name record[2] table type record[3] column name record[4] column type

func (*SQLSmith) SelectForUpdateStmt

func (s *SQLSmith) SelectForUpdateStmt(depth int) (string, string, error)

SelectForUpdateStmt make random select statement SQL with for update lock

func (*SQLSmith) SelectStmt

func (s *SQLSmith) SelectStmt(depth int) (string, string, error)

SelectStmt make random select statement SQL

func (*SQLSmith) SetDB

func (s *SQLSmith) SetDB(db string)

SetDB set current database

func (*SQLSmith) SetHint

func (s *SQLSmith) SetHint(hint bool)

SetHint ...

func (*SQLSmith) SetStable

func (s *SQLSmith) SetStable(stable bool)

SetStable set stable to given value

func (*SQLSmith) Stable

func (s *SQLSmith) Stable()

Stable set generated SQLs no rand

func (*SQLSmith) UpdateStmt

func (s *SQLSmith) UpdateStmt() (string, string, error)

UpdateStmt make random update statement SQL

func (*SQLSmith) Walk

func (s *SQLSmith) Walk(tree ast.Node) (string, string, error)

Walk will walk the tree and fillin tables and columns data

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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