engine

package
v0.0.0-...-f5d25ad Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package engine implement an engine that can execute a command.

Index

Constants

This section is empty.

Variables

View Source
var (
	// EmptyTable is the empty table, with 0 cols and 0 rows.
	EmptyTable = Table{
		Cols: make([]Col, 0),
		Rows: make([]Row, 0),
	}
)

Functions

func ToNumericValue

func ToNumericValue(s string) (types.Value, bool)

ToNumericValue checks whether the given string is of this form https://www.sqlite.org/lang_expr.html#literal_values_constants_ . If it is, an appropriate value is returned (either types.IntegerValue or types.RealValue). If it is not, false will be returned. This will never return the NULL value, even if the given string is empty. In that case, nil and false is returned.

Types

type Col

type Col struct {
	QualifiedName string
	Alias         string
	Type          types.Type
}

Col is a header for a single column in a table, containing the qualified name of the col, a possible alias and the col data type.

type Engine

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

Engine is the component that is used to evaluate commands.

func New

func New(dbFile *storage.DBFile, opts ...Option) (Engine, error)

New creates a new engine object and applies the given options to it.

func (Engine) Close

func (e Engine) Close() error

Close closes the underlying database file.

func (Engine) Closed

func (e Engine) Closed() bool

Closed determines whether the underlying database file was closed. If so, this engine is considered closed, as it can no longer operate on the underlying file.

func (Engine) Evaluate

func (e Engine) Evaluate(cmd command.Command) (Table, error)

Evaluate evaluates the given command. This may mutate the state of the database, and changes may occur to the database file.

type Error

type Error string

Error is a sentinel error.

const (
	// ErrClosed indicates that the component can not be used anymore, because
	// it already has been closed.
	ErrClosed Error = "already closed"
	// ErrUnsupported indicates that a requested feature is explicitely not
	// supported. This is different from ErrUnimplemented, since
	// ErrUnimplemented indicates, that the feature has not been implemented
	// yet, while ErrUnsupported indicates, that the feature is intentionally
	// unimplemented.
	ErrUnsupported Error = "unsupported"
)

func ErrNoSuchColumn

func ErrNoSuchColumn(name string) Error

ErrNoSuchColumn returns an error indicating that a requested column is not contained in the current result table.

func ErrNoSuchFunction

func ErrNoSuchFunction(name string) Error

ErrNoSuchFunction returns an error indicating that a function with the given name can not be found.

func ErrUncomparable

func ErrUncomparable(t types.Type) Error

ErrUncomparable returns an error indicating that the given type does not implement the types.Comparator interface, and thus, values of that type cannot be compared.

func ErrUnimplemented

func ErrUnimplemented(what interface{}) Error

ErrUnimplemented returns an error indicating a missing implementation for the requested feature. It may be implemented in the next version.

func (Error) Error

func (e Error) Error() string

type Evt

type Evt string

Evt is an event this engine uses.

const (
	// EvtEvaluate is the event 'evaluate'. This is used for every call to
	// 'Evaluate' (exported), and is used to measure the total amount of time it
	// takes the database to evaluate a command.
	EvtEvaluate Evt = "evaluate"
	// EvtCompare is the event 'compare'. This is used for every comparison
	// (with 'cmp') of two values that is performed.
	EvtCompare Evt = "compare"
)

func (Evt) String

func (e Evt) String() string

type ExecutionContext

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

ExecutionContext is a context that is passed down throughout a complete evaluation. It may be populated further.

func (ExecutionContext) String

func (c ExecutionContext) String() string

type Option

type Option func(*Engine)

Option is an option that can is applied to an Engine on creation.

func WithLogger

func WithLogger(log zerolog.Logger) Option

WithLogger specifies a logger for the Engine.

func WithProfiler

func WithProfiler(profiler *profile.Profiler) Option

WithProfiler passes a profiler into the engine. The default for the engine is not using a profiler at all.

func WithRandomProvider

func WithRandomProvider(rp randomProvider) Option

WithRandomProvider sets a random provider, which will be used by the engine to evaluate expressions, that require a random source, such as the function RANDOM().

func WithTimeProvider

func WithTimeProvider(tp timeProvider) Option

WithTimeProvider sets a time provider, which will be used by the engine to evaluate expressions, that require a timestamp, such as the function NOW().

type ParameterizedEvt

type ParameterizedEvt struct {
	// Name is the name of the event.
	Name string
	// Param is the parameterization of the event.
	Param string
}

ParameterizedEvt is a parameterized event, which will be printed in the form Name[Param].

func EvtFullTableScan

func EvtFullTableScan(tableName string) ParameterizedEvt

EvtFullTableScan creates an event 'full table scan[table=<tableName>]'.

func (ParameterizedEvt) String

func (e ParameterizedEvt) String() string

type Row

type Row struct {
	Values []types.Value
}

Row is a one-dimensional collection of values.

type Table

type Table struct {
	Cols []Col
	Rows []Row
}

Table is a one-dimensional collection of Rows.

func (Table) FilterRows

func (t Table) FilterRows(keep func([]Col, Row) (bool, error)) (Table, error)

FilterRows filteres this table's rows according to the given keep function. Rows for which the given function returns true and no error, will be copied over to a new table, which will then be returned. The keep function is fed with one row at a time, but always all columns from the original table, to facilitate checking values by index.

func (Table) HasColumn

func (t Table) HasColumn(qualifiedNameOrAlias string) bool

HasColumn inspects the table's columns and determines whether the table has any column, that has the given name as qualified name OR as alias.

func (Table) RemoveColumn

func (t Table) RemoveColumn(index int) Table

RemoveColumn works on a copy of the table, and removes the column with the given index from the copy. After removal, the copy is returned.

func (Table) RemoveColumnByQualifiedName

func (t Table) RemoveColumnByQualifiedName(qualifiedName string) Table

RemoveColumnByQualifiedName will remove the first column with the given qualified name from the table, and return the new table. The original table will not be modified. If no such column exists, the original table is returned.

func (Table) String

func (t Table) String() string

Directories

Path Synopsis
Package profile implements profiling with generic events.
Package profile implements profiling with generic events.
Package storage implements support for the file format of add.
Package storage implements support for the file format of add.
page
Package page describes generic pages.
Package page describes generic pages.
Package types provides a type system for the add engine.
Package types provides a type system for the add engine.

Jump to

Keyboard shortcuts

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