memory

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2022 License: Apache-2.0 Imports: 17 Imported by: 53

Documentation

Index

Constants

View Source
const CommentPreventingIndexBuilding = "__FOR TESTING: I cannot be built__"
View Source
const IndexDriverId = "MemoryIndexDriver"

Variables

This section is empty.

Functions

func EncodeIndexValue added in v0.9.0

func EncodeIndexValue(value *IndexValue) ([]byte, error)

func NewMemoryDBProvider added in v0.11.0

func NewMemoryDBProvider(dbs ...sql.Database) sql.MutableDatabaseProvider

func NewTableEditAccumulator added in v0.12.0

func NewTableEditAccumulator(t *Table) tableEditAccumulator

NewTableEditAccumulator returns a tableEditAccumulator based on the schema.

Types

type BaseDatabase added in v0.11.0

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

BaseDatabase is an in-memory database that can't store views, only for testing the engine

func NewViewlessDatabase added in v0.11.0

func NewViewlessDatabase(name string) *BaseDatabase

NewViewlessDatabase creates a new database that doesn't persist views. Used only for testing. Use NewDatabase.

func (*BaseDatabase) AddTable added in v0.11.0

func (d *BaseDatabase) AddTable(name string, t sql.Table)

AddTable adds a new table to the database.

func (*BaseDatabase) CreateTable added in v0.11.0

func (d *BaseDatabase) CreateTable(ctx *sql.Context, name string, schema sql.PrimaryKeySchema) error

CreateTable creates a table with the given name and schema

func (*BaseDatabase) CreateTrigger added in v0.11.0

func (d *BaseDatabase) CreateTrigger(ctx *sql.Context, definition sql.TriggerDefinition) error

func (*BaseDatabase) DropStoredProcedure added in v0.11.0

func (d *BaseDatabase) DropStoredProcedure(ctx *sql.Context, name string) error

DropStoredProcedure implements sql.StoredProcedureDatabase

func (*BaseDatabase) DropTable added in v0.11.0

func (d *BaseDatabase) DropTable(ctx *sql.Context, name string) error

DropTable drops the table with the given name

func (*BaseDatabase) DropTrigger added in v0.11.0

func (d *BaseDatabase) DropTrigger(ctx *sql.Context, name string) error

func (*BaseDatabase) EnablePrimaryKeyIndexes added in v0.11.0

func (d *BaseDatabase) EnablePrimaryKeyIndexes()

EnablePrimaryKeyIndexes causes every table created in this database to use an index on its primary partitionKeys

func (*BaseDatabase) GetForeignKeyCollection added in v0.12.0

func (d *BaseDatabase) GetForeignKeyCollection() *ForeignKeyCollection

func (*BaseDatabase) GetStoredProcedures added in v0.11.0

func (d *BaseDatabase) GetStoredProcedures(ctx *sql.Context) ([]sql.StoredProcedureDetails, error)

GetStoredProcedures implements sql.StoredProcedureDatabase

func (*BaseDatabase) GetTableInsensitive added in v0.11.0

func (d *BaseDatabase) GetTableInsensitive(ctx *sql.Context, tblName string) (sql.Table, bool, error)

func (*BaseDatabase) GetTableNames added in v0.11.0

func (d *BaseDatabase) GetTableNames(ctx *sql.Context) ([]string, error)

func (*BaseDatabase) GetTriggers added in v0.11.0

func (d *BaseDatabase) GetTriggers(ctx *sql.Context) ([]sql.TriggerDefinition, error)

func (*BaseDatabase) Name added in v0.11.0

func (d *BaseDatabase) Name() string

Name returns the database name.

func (*BaseDatabase) RenameTable added in v0.11.0

func (d *BaseDatabase) RenameTable(ctx *sql.Context, oldName, newName string) error

func (*BaseDatabase) SaveStoredProcedure added in v0.11.0

func (d *BaseDatabase) SaveStoredProcedure(ctx *sql.Context, spd sql.StoredProcedureDetails) error

SaveStoredProcedure implements sql.StoredProcedureDatabase

func (*BaseDatabase) Tables added in v0.11.0

func (d *BaseDatabase) Tables() map[string]sql.Table

Tables returns all tables in the database.

type Database

type Database struct {
	*BaseDatabase
	// contains filtered or unexported fields
}

Database is an in-memory database.

func NewDatabase

func NewDatabase(name string) *Database

NewDatabase creates a new database with the given name.

func (*Database) AllViews added in v0.11.0

func (d *Database) AllViews(ctx *sql.Context) ([]sql.ViewDefinition, error)

func (*Database) CreateView added in v0.11.0

func (d *Database) CreateView(ctx *sql.Context, name string, selectStatement string) error

func (*Database) DropView added in v0.11.0

func (d *Database) DropView(ctx *sql.Context, name string) error

func (*Database) GetView added in v0.11.0

func (d *Database) GetView(ctx *sql.Context, viewName string) (string, bool, error)

type ExpressionsIndex

type ExpressionsIndex interface {
	sql.Index
	MemTable() *Table
	ColumnExpressions() []sql.Expression
}

ExpressionsIndex is an index made out of one or more expressions (usually field expressions), linked to a Table.

type ExternalStoredProcedureDatabase added in v0.12.0

type ExternalStoredProcedureDatabase struct {
	*HistoryDatabase
}

ExternalStoredProcedureDatabase is an implementation of sql.ExternalStoredProcedureDatabase for the memory db.

func NewExternalStoredProcedureDatabase added in v0.12.0

func NewExternalStoredProcedureDatabase(name string) ExternalStoredProcedureDatabase

NewExternalStoredProcedureDatabase returns a new ExternalStoredProcedureDatabase.

func (ExternalStoredProcedureDatabase) GetExternalStoredProcedures added in v0.12.0

func (e ExternalStoredProcedureDatabase) GetExternalStoredProcedures(ctx *sql.Context) ([]sql.ExternalStoredProcedureDetails, error)

GetExternalStoredProcedures implements the interface sql.ExternalStoredProcedureDatabase.

type FilteredTable added in v0.10.0

type FilteredTable struct {
	*Table
}

FilteredTable functionality in the Table type was disabled for a long period of time, and has developed major issues with the current analyzer logic. It's only used in the pushdown unit tests, and sql.FilteredTable should be considered unstable until this situation is fixed.

func NewFilteredTable added in v0.10.0

func NewFilteredTable(name string, schema sql.PrimaryKeySchema, fkColl *ForeignKeyCollection) *FilteredTable

func (*FilteredTable) Projections added in v0.12.0

func (t *FilteredTable) Projections() []string

Projections implements sql.ProjectedTable

func (*FilteredTable) WithFilters added in v0.10.0

func (t *FilteredTable) WithFilters(ctx *sql.Context, filters []sql.Expression) sql.Table

WithFilters implements the sql.FilteredTable interface.

func (*FilteredTable) WithProjections added in v0.12.0

func (t *FilteredTable) WithProjections(colNames []string) sql.Table

WithProjections implements sql.ProjectedTable

type ForeignKeyCollection added in v0.12.0

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

ForeignKeyCollection is a shareable container for a collection of foreign keys.

func (*ForeignKeyCollection) AddFK added in v0.12.0

AddFK adds the given foreign key to the internal slice.

func (*ForeignKeyCollection) DropFK added in v0.12.0

func (fkc *ForeignKeyCollection) DropFK(fkName string) bool

DropFK removes the given foreign key from the internal slice. Returns true if the foreign key was found.

func (*ForeignKeyCollection) Keys added in v0.12.0

Keys returns all of the foreign keys.

func (*ForeignKeyCollection) SetResolved added in v0.12.0

func (fkc *ForeignKeyCollection) SetResolved(fkName string) bool

SetResolved sets the given foreign key as being resolved.

type GlobalsMap added in v0.12.0

type GlobalsMap = map[string]interface{}

type HistoryDatabase

type HistoryDatabase struct {
	*Database
	Revisions map[string]map[interface{}]sql.Table
	// contains filtered or unexported fields
}

HistoryDatabase is a test-only VersionedDatabase implementation. It only supports exact lookups, not AS OF queries between two revisions. It's constructed just like its non-versioned sibling, but it can receive updates to particular tables via the AddTableAsOf method. Consecutive calls to AddTableAsOf with the same table must install new versions of the named table each time, with ascending version identifiers, for this to work.

func NewHistoryDatabase

func NewHistoryDatabase(name string) *HistoryDatabase

func (*HistoryDatabase) AddTableAsOf

func (db *HistoryDatabase) AddTableAsOf(name string, t sql.Table, asOf interface{})

Adds a table with an asOf revision key. The table given becomes the current version for the name given.

func (*HistoryDatabase) GetTableInsensitiveAsOf

func (db *HistoryDatabase) GetTableInsensitiveAsOf(ctx *sql.Context, tblName string, time interface{}) (sql.Table, bool, error)

func (*HistoryDatabase) GetTableNamesAsOf

func (db *HistoryDatabase) GetTableNamesAsOf(ctx *sql.Context, time interface{}) ([]string, error)

type InMemoryPersistedSession added in v0.12.0

type InMemoryPersistedSession struct {
	sql.Session
	// contains filtered or unexported fields
}

func NewInMemoryPersistedSession added in v0.12.0

func NewInMemoryPersistedSession(sess sql.Session, persistedGlobals GlobalsMap) *InMemoryPersistedSession

NewInMemoryPersistedSession is a sql.PersistableSession that writes global variables to an im-memory map

func (*InMemoryPersistedSession) GetPersistedValue added in v0.12.0

func (s *InMemoryPersistedSession) GetPersistedValue(k string) (interface{}, error)

RemoveAllPersistedGlobals implements sql.PersistableSession

func (*InMemoryPersistedSession) PersistGlobal added in v0.12.0

func (s *InMemoryPersistedSession) PersistGlobal(sysVarName string, value interface{}) error

PersistGlobal implements sql.PersistableSession

func (*InMemoryPersistedSession) RemoveAllPersistedGlobals added in v0.12.0

func (s *InMemoryPersistedSession) RemoveAllPersistedGlobals() error

RemoveAllPersistedGlobals implements sql.PersistableSession

func (*InMemoryPersistedSession) RemovePersistedGlobal added in v0.12.0

func (s *InMemoryPersistedSession) RemovePersistedGlobal(sysVarName string) error

RemovePersistedGlobal implements sql.PersistableSession

type Index added in v0.12.0

type Index struct {
	DB         string // required for engine tests with driver
	DriverName string // required for engine tests with driver
	Tbl        *Table // required for engine tests with driver
	TableName  string
	Exprs      []sql.Expression
	Name       string
	Unique     bool
	CommentStr string
}

func (*Index) ColumnExpressionTypes added in v0.12.0

func (idx *Index) ColumnExpressionTypes(*sql.Context) []sql.ColumnExpressionType

ColumnExpressionTypes implements the interface sql.Index.

func (*Index) ColumnExpressions added in v0.12.0

func (idx *Index) ColumnExpressions() []sql.Expression

func (*Index) Comment added in v0.12.0

func (idx *Index) Comment() string

func (*Index) Database added in v0.12.0

func (idx *Index) Database() string

func (*Index) Driver added in v0.12.0

func (idx *Index) Driver() string

func (*Index) Expressions added in v0.12.0

func (idx *Index) Expressions() []string

func (*Index) HandledFilters added in v0.12.0

func (idx *Index) HandledFilters(filters []sql.Expression) []sql.Expression

func (*Index) ID added in v0.12.0

func (idx *Index) ID() string

func (*Index) IndexType added in v0.12.0

func (idx *Index) IndexType() string

func (*Index) IsGenerated added in v0.12.0

func (idx *Index) IsGenerated() bool

func (*Index) IsUnique added in v0.12.0

func (idx *Index) IsUnique() bool

func (*Index) MemTable added in v0.12.0

func (idx *Index) MemTable() *Table

func (*Index) NewLookup added in v0.12.0

func (idx *Index) NewLookup(ctx *sql.Context, ranges ...sql.Range) (sql.IndexLookup, error)

NewLookup implements the interface sql.Index.

func (*Index) Order added in v0.12.0

func (idx *Index) Order() sql.IndexOrder

func (*Index) Table added in v0.12.0

func (idx *Index) Table() string

type IndexLookup added in v0.12.0

type IndexLookup struct {
	Expr sql.Expression
	// contains filtered or unexported fields
}

func NewIndexLookup added in v0.12.0

func NewIndexLookup(ctx *sql.Context, idx ExpressionsIndex, expr sql.Expression, ranges ...sql.Range) *IndexLookup

func (*IndexLookup) EvalExpression added in v0.12.0

func (eil *IndexLookup) EvalExpression() sql.Expression

func (*IndexLookup) Index added in v0.12.0

func (eil *IndexLookup) Index() sql.Index

Index implements the interface sql.IndexLookup.

func (*IndexLookup) Indexes added in v0.12.0

func (eil *IndexLookup) Indexes() []string

func (*IndexLookup) Ranges added in v0.12.0

func (eil *IndexLookup) Ranges() sql.RangeCollection

Ranges implements the interface sql.IndexLookup.

func (*IndexLookup) String added in v0.12.0

func (eil *IndexLookup) String() string

func (*IndexLookup) Values added in v0.12.0

func (eil *IndexLookup) Values(p sql.Partition) (sql.IndexValueIter, error)

type IndexValue added in v0.9.0

type IndexValue struct {
	Key string
	Pos int
}

func DecodeIndexValue added in v0.9.0

func DecodeIndexValue(data []byte) (*IndexValue, error)

type MemoryDatabase added in v0.11.0

type MemoryDatabase interface {
	sql.Database
	AddTable(name string, t sql.Table)
}

type Partition added in v0.9.0

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

func NewPartition added in v0.9.0

func NewPartition(key []byte) *Partition

func (*Partition) Key added in v0.9.0

func (p *Partition) Key() []byte

type ReadOnlyDatabase added in v0.11.0

type ReadOnlyDatabase struct {
	*HistoryDatabase
}

func NewReadOnlyDatabase added in v0.11.0

func NewReadOnlyDatabase(name string) ReadOnlyDatabase

func (ReadOnlyDatabase) IsReadOnly added in v0.11.0

func (d ReadOnlyDatabase) IsReadOnly() bool

type Table

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

Table represents an in-memory database table.

func NewPartitionedTable

func NewPartitionedTable(name string, schema sql.PrimaryKeySchema, fkColl *ForeignKeyCollection, numPartitions int) *Table

NewPartitionedTable creates a new Table with the given name, schema and number of partitions.

func NewTable

func NewTable(name string, schema sql.PrimaryKeySchema, fkColl *ForeignKeyCollection) *Table

NewTable creates a new Table with the given name and schema.

func (*Table) AddColumn

func (t *Table) AddColumn(ctx *sql.Context, column *sql.Column, order *sql.ColumnOrder) error

func (*Table) AddForeignKey added in v0.12.0

func (t *Table) AddForeignKey(ctx *sql.Context, fk sql.ForeignKeyConstraint) error

AddForeignKey implements sql.ForeignKeyTable. Foreign partitionKeys are not enforced on update / delete.

func (*Table) AutoIncrementSetter

func (t *Table) AutoIncrementSetter(*sql.Context) sql.AutoIncrementSetter

func (*Table) CreateCheck added in v0.9.0

func (t *Table) CreateCheck(_ *sql.Context, check *sql.CheckDefinition) error

CreateCheck implements sql.CheckAlterableTable

func (*Table) CreateIndex

func (t *Table) CreateIndex(ctx *sql.Context, indexName string, using sql.IndexUsing, constraint sql.IndexConstraint, columns []sql.IndexColumn, comment string) error

CreateIndex implements sql.IndexAlterableTable

func (*Table) CreateIndexForForeignKey added in v0.12.0

func (t *Table) CreateIndexForForeignKey(ctx *sql.Context, indexName string, using sql.IndexUsing, constraint sql.IndexConstraint, columns []sql.IndexColumn) error

CreateIndexForForeignKey implements sql.ForeignKeyTable.

func (*Table) CreatePrimaryKey added in v0.11.0

func (t *Table) CreatePrimaryKey(ctx *sql.Context, columns []sql.IndexColumn) error

CreatePrimaryKey implements the PrimaryKeyAlterableTable

func (*Table) DataLength added in v0.9.0

func (t *Table) DataLength(ctx *sql.Context) (uint64, error)

func (*Table) DebugString

func (t *Table) DebugString() string

func (*Table) Deleter

func (t *Table) Deleter(*sql.Context) sql.RowDeleter

func (*Table) DropCheck added in v0.9.0

func (t *Table) DropCheck(ctx *sql.Context, chName string) error

DropCheck implements sql.CheckAlterableTable.

func (*Table) DropColumn

func (t *Table) DropColumn(ctx *sql.Context, columnName string) error

func (*Table) DropForeignKey

func (t *Table) DropForeignKey(ctx *sql.Context, fkName string) error

DropForeignKey implements sql.ForeignKeyTable.

func (*Table) DropIndex

func (t *Table) DropIndex(ctx *sql.Context, indexName string) error

DropIndex implements sql.IndexAlterableTable

func (*Table) DropPrimaryKey added in v0.11.0

func (t *Table) DropPrimaryKey(ctx *sql.Context) error

DropPrimaryKey implements the PrimaryKeyAlterableTable

func (*Table) EnablePrimaryKeyIndexes

func (t *Table) EnablePrimaryKeyIndexes()

EnablePrimaryKeyIndexes enables the use of primary key indexes on this table.

func (*Table) Filters added in v0.10.0

func (t *Table) Filters() []sql.Expression

Filters implements the sql.FilteredTable interface.

func (*Table) GetChecks added in v0.9.0

func (t *Table) GetChecks(_ *sql.Context) ([]sql.CheckDefinition, error)

GetChecks implements sql.CheckTable

func (*Table) GetDeclaredForeignKeys added in v0.12.0

func (t *Table) GetDeclaredForeignKeys(ctx *sql.Context) ([]sql.ForeignKeyConstraint, error)

GetDeclaredForeignKeys implements the interface sql.ForeignKeyTable.

func (*Table) GetForeignKeyUpdater added in v0.12.0

func (t *Table) GetForeignKeyUpdater(ctx *sql.Context) sql.ForeignKeyUpdater

GetForeignKeyUpdater implements sql.ForeignKeyTable.

func (*Table) GetIndexes

func (t *Table) GetIndexes(ctx *sql.Context) ([]sql.Index, error)

GetIndexes implements sql.IndexedTable

func (*Table) GetNextAutoIncrementValue added in v0.11.0

func (t *Table) GetNextAutoIncrementValue(ctx *sql.Context, insertVal interface{}) (uint64, error)

GetNextAutoIncrementValue gets the next auto increment value for the memory table the increment.

func (*Table) GetPartition added in v0.9.0

func (t *Table) GetPartition(key string) []sql.Row

func (*Table) GetReferencedForeignKeys added in v0.12.0

func (t *Table) GetReferencedForeignKeys(ctx *sql.Context) ([]sql.ForeignKeyConstraint, error)

GetReferencedForeignKeys implements the interface sql.ForeignKeyTable.

func (*Table) HandledFilters

func (t *Table) HandledFilters(filters []sql.Expression) []sql.Expression

HandledFilters implements the sql.FilteredTable interface.

func (*Table) IndexKeyValues

func (t *Table) IndexKeyValues(
	ctx *sql.Context,
	colNames []string,
) (sql.PartitionIndexKeyValueIter, error)

IndexKeyValues implements the sql.IndexableTable interface.

func (*Table) Insert

func (t *Table) Insert(ctx *sql.Context, row sql.Row) error

Convenience method to avoid having to create an inserter in test setup

func (*Table) Inserter

func (t *Table) Inserter(*sql.Context) sql.RowInserter

func (*Table) ModifyColumn

func (t *Table) ModifyColumn(ctx *sql.Context, columnName string, column *sql.Column, order *sql.ColumnOrder) error

func (Table) Name

func (t Table) Name() string

Name implements the sql.Table interface.

func (*Table) NumRows added in v0.9.0

func (t *Table) NumRows(ctx *sql.Context) (uint64, error)

func (*Table) PartitionCount

func (t *Table) PartitionCount(ctx *sql.Context) (int64, error)

PartitionCount implements the sql.PartitionCounter interface.

func (*Table) PartitionRows

func (t *Table) PartitionRows(ctx *sql.Context, partition sql.Partition) (sql.RowIter, error)

PartitionRows implements the sql.PartitionRows interface.

func (*Table) PartitionRows2 added in v0.12.0

func (t *Table) PartitionRows2(ctx *sql.Context, partition sql.Partition) (sql.RowIter2, error)

func (*Table) Partitions

func (t *Table) Partitions(ctx *sql.Context) (sql.PartitionIter, error)

Partitions implements the sql.Table interface.

func (*Table) PeekNextAutoIncrementValue added in v0.11.0

func (t *Table) PeekNextAutoIncrementValue(*sql.Context) (uint64, error)

PeekNextAutoIncrementValue peeks at the next AUTO_INCREMENT value

func (*Table) PrimaryKeySchema added in v0.12.0

func (t *Table) PrimaryKeySchema() sql.PrimaryKeySchema

PrimaryKeySchema implements sql.PrimaryKeyAlterableTable

func (*Table) Projections added in v0.12.0

func (t *Table) Projections() []string

Projections implements sql.ProjectedTable

func (*Table) RenameIndex

func (t *Table) RenameIndex(ctx *sql.Context, fromIndexName string, toIndexName string) error

RenameIndex implements sql.IndexAlterableTable

func (*Table) Replacer

func (t *Table) Replacer(*sql.Context) sql.RowReplacer

func (*Table) Schema

func (t *Table) Schema() sql.Schema

Schema implements the sql.Table interface.

func (*Table) SetForeignKeyResolved added in v0.12.0

func (t *Table) SetForeignKeyResolved(ctx *sql.Context, fkName string) error

SetForeignKeyResolved implements sql.ForeignKeyTable.

func (*Table) String

func (t *Table) String() string

String implements the sql.Table interface.

func (*Table) Truncate

func (t *Table) Truncate(ctx *sql.Context) (int, error)

func (*Table) UpdateForeignKey added in v0.12.0

func (t *Table) UpdateForeignKey(ctx *sql.Context, fkName string, fk sql.ForeignKeyConstraint) error

UpdateForeignKey implements sql.ForeignKeyTable.

func (*Table) Updater

func (t *Table) Updater(*sql.Context) sql.RowUpdater

func (*Table) WithIndexLookup

func (t *Table) WithIndexLookup(lookup sql.IndexLookup) sql.Table

WithIndexLookup implements the sql.IndexAddressableTable interface.

func (*Table) WithProjections added in v0.12.0

func (t *Table) WithProjections(colNames []string) sql.Table

WithProjections implements sql.ProjectedTable

type TestIndexDriver

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

TestIndexDriver is a non-performant index driver meant to aid in verification of engine correctness. It can not create or delete indexes, but will use the index types defined in this package to alter how queries are executed, retrieving values from the indexes rather than from the tables directly.

func NewIndexDriver

func NewIndexDriver(db string, indexes map[string][]sql.DriverIndex) *TestIndexDriver

NewIndexDriver returns a new index driver for database and the indexes given, keyed by the table name.

func (*TestIndexDriver) Create

func (d *TestIndexDriver) Create(db, table, id string, expressions []sql.Expression, config map[string]string) (sql.DriverIndex, error)

func (*TestIndexDriver) Delete

func (*TestIndexDriver) ID

func (d *TestIndexDriver) ID() string

func (*TestIndexDriver) LoadAll

func (d *TestIndexDriver) LoadAll(ctx *sql.Context, db, table string) ([]sql.DriverIndex, error)

func (*TestIndexDriver) Save

Jump to

Keyboard shortcuts

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