generator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	/// =
	Equal = RangeCondition(opcode.EQ)

	/// <=>
	NullSafeEqual = RangeCondition(opcode.NullEQ)

	/// IN()
	In = RangeCondition(opcode.In)

	/// IS NULL
	IsNull = RangeCondition(opcode.IsNull)

	/// >
	Greater = RangeCondition(opcode.GT)

	/// <
	Less = RangeCondition(opcode.LT)

	///>=
	GreaterEqual = RangeCondition(opcode.GE)

	/// <=
	LessEqual = RangeCondition(opcode.LE)

	/// !=
	NotEqual = RangeCondition(opcode.NE)

	/// LIKE
	Like = RangeCondition(opcode.Like)

	/// BETWEEN ... AND
	Between = RangeCondition(iota + opcode.IsFalsity + 1)

	IsNotNull
)

Variables

View Source
var (
	ComposeTmpTable = model.NewCIStr("tmp")

	ComposeValueAsName = model.NewCIStr("val")

	ComposeSumExpr = &ast.AggregateFuncExpr{
		F: ast.AggFuncSum,
		Args: []ast.ExprNode{
			&ast.ColumnNameExpr{
				Name: &ast.ColumnName{
					Name:  ComposeValueAsName,
					Table: ComposeTmpTable,
				},
			},
		},
	}

	UnionOperator = ast.Union
)

Functions

func FormatDuration

func FormatDuration(dur time.Duration) string

TODO: Implement `FormatDuration`

func FormatStringLiteral

func FormatStringLiteral(value string) string

func FormatTime

func FormatTime(t time.Time) string

func FormatValue

func FormatValue(tp *types.FieldType, value []byte) string

func Rd

func Rd(n int) int

Rd same to rand.Intn

func RdAggregateExpr

func RdAggregateExpr(column *database.Column) ast.ExprNode

func RdBinaryOperator

func RdBinaryOperator(ops []opcode.Op) opcode.Op

func RdBool added in v0.9.1

func RdBool() bool

func RdColumns added in v0.9.1

func RdColumns(columnsList [][]*database.Column) *database.Column

func RdDate

func RdDate() time.Time

RdDate rand date

func RdDuration

func RdDuration() time.Duration

func RdFloat64

func RdFloat64() float64

RdFloat64 rand float64

func RdGreaterValue

func RdGreaterValue(exec executor.Executor, column *database.Column, less []byte) (value []byte, err error)

func RdInRange

func RdInRange(column *database.Column, value []byte, exec executor.Executor) (rg []ast.ExprNode, err error)

func RdInt63

func RdInt63(n int64) int64

func RdInt64

func RdInt64() int64

func RdLessValue

func RdLessValue(exec executor.Executor, column *database.Column, less []byte) (value []byte, err error)

func RdLogicOp

func RdLogicOp() opcode.Op

func RdNotEqualValue

func RdNotEqualValue(exec executor.Executor, column *database.Column, value []byte) (other []byte, err error)

func RdRange

func RdRange(n, m int64) int64

RdRange rand int in range

func RdRangeConditionExpr

func RdRangeConditionExpr(exec executor.Executor, column *database.Column, value []byte) ast.ExprNode

func RdSQLValue

func RdSQLValue(tp *types.FieldType) string

func RdString

func RdString(length int) string

RdString rand string with given length

func RdStringChar

func RdStringChar(length int) string

RdStringChar rand string with given length, letter chars only

func RdTimestamp

func RdTimestamp() time.Time

RdTimestamp return same format as RdDate except rand range TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07'

func RdTowColumns added in v0.9.1

func RdTowColumns(columnsList [][]*database.Column) []*database.Column

func RdValue

func RdValue(exec executor.Executor, column *database.Column) (value []byte, err error)

func SetAndOpWeight

func SetAndOpWeight(weight int)

Set the weight of "AND" operator

func SumSelect added in v0.9.1

func SumSelect(source ast.ResultSetNode) *ast.SelectStmt

Types

type AggregateFunc

type AggregateFunc string

func (AggregateFunc) RdExpr

func (fn AggregateFunc) RdExpr(column *database.Column) ast.ExprNode

/ RdExpr is a function generating random expression.

func (AggregateFunc) Suit

func (fn AggregateFunc) Suit(tp *types.FieldType) bool

type Generator

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

func NewGenerator

func NewGenerator(db *database.Database, exec executor.Executor, keymaps []keymap.KeyMap) *Generator

func (*Generator) AggregateSelect

func (g *Generator) AggregateSelect(options Options, tables []string, columnsList [][]*database.Column) (stmt *ast.SelectStmt, err error)

func (*Generator) BenchSelect added in v0.9.1

func (g *Generator) BenchSelect(options Options, tables []string, columnsList [][]*database.Column) (*ast.SelectStmt, error)

func (*Generator) BenchStmt added in v0.9.1

func (g *Generator) BenchStmt(options Options) (query string, err error)

func (*Generator) ComposeSelect added in v0.9.1

func (g *Generator) ComposeSelect(options Options, tables []string, columnsList [][]*database.Column, composedStmt *ast.SelectStmt) (*ast.SelectStmt, error)

func (*Generator) ComposeStmt added in v0.9.1

func (g *Generator) ComposeStmt(options Options) (query string, err error)

func (*Generator) ComposeUnion added in v0.9.1

func (g *Generator) ComposeUnion(options Options, tables []string, columnsList [][]*database.Column, composedStmt *ast.SelectStmt) (stmt *ast.SelectStmt, err error)

func (*Generator) NormalSelect

func (g *Generator) NormalSelect(options Options, tables []string, columnsList [][]*database.Column) (stmt *ast.SelectStmt, err error)

func (*Generator) PrepareSelect

func (g *Generator) PrepareSelect(tables []string, columnsList [][]*database.Column) (*ast.SelectStmt, error)

func (*Generator) RdGroupBy

func (g *Generator) RdGroupBy(maxByItems int, tableColumns [][]*database.Column) ([]*ast.ByItem, map[*database.Column]bool)

func (*Generator) RdOrderBy

func (g *Generator) RdOrderBy(options Options, tables []string, tableColumns [][]*database.Column) []*ast.ByItem

func (*Generator) RdTablesAndKeys

func (g *Generator) RdTablesAndKeys(option *Options) ([]string, [][]*database.Column)

func (*Generator) RdValues

func (g *Generator) RdValues(table string, columns []*database.Column) (values [][]byte, err error)

func (*Generator) RdValuesList

func (g *Generator) RdValuesList(tableRefs *ast.TableRefsClause, columnsList [][]*database.Column) (valuesList [][][]byte, err error)

func (*Generator) TableRefsClause

func (g *Generator) TableRefsClause(tables []string) *ast.TableRefsClause

func (*Generator) WhereExpr

func (g *Generator) WhereExpr(columnsList [][]*database.Column, valuesList [][][]byte) ast.ExprNode

type Options

type Options struct {
	MaxTables            int           `json:"max_tables"`
	MinDurationThreshold time.Duration `json:"min_duration_threshold"`
	Limit                int           `json:"limit"`
	KeyOnly              bool          `json:"key_only"`

	// control order by
	UnstableOrderBy bool `json:"unstable_order_by"`
	MaxByItems      int  `json:"max_by_items"`

	EnableKeyMap bool `json:"enable_key_map"`

	AggregateWeight float64 `json:"aggregate_weight"`
}

type RangeCondition

type RangeCondition int

func (RangeCondition) RdExpr

func (condition RangeCondition) RdExpr(column *database.Column, value []byte, exec executor.Executor) (expr ast.ExprNode)

/ RdExpr is a function generating random expression. / empty expression represents for failure

func (RangeCondition) Suit

func (condition RangeCondition) Suit(tp *types.FieldType, value []byte) bool

Jump to

Keyboard shortcuts

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