sql

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: Apache-2.0 Imports: 14 Imported by: 4

Documentation

Overview

Copyright 2021 CodeNotary, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 CodeNotary, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 CodeNotary, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 CodeNotary, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 CodeNotary, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Code generated by goyacc -l -o sql_parser.go sql_grammar.y. DO NOT EDIT.

Index

Constants

View Source
const (
	IntegerType   SQLValueType = "INTEGER"
	BooleanType                = "BOOLEAN"
	VarcharType                = "VARCHAR"
	BLOBType                   = "BLOB"
	TimestampType              = "TIMESTAMP"
)
View Source
const (
	COUNT AggregateFn = "COUNT"
	SUM               = "SUM"
	MAX               = "MAX"
	MIN               = "MIN"
	AVG               = "AVG"
)
View Source
const ADD = 57357
View Source
const AGGREGATE_FUNC = 57397
View Source
const ALTER = 57356
View Source
const AS = 57382
View Source
const ASC = 57380
View Source
const BEFORE = 57371
View Source
const BEGIN = 57361
View Source
const BLOB = 57396
View Source
const BOOLEAN = 57395
View Source
const BY = 57377
View Source
const CMPOP = 57390
View Source
const COLUMN = 57358
View Source
const COMMIT = 57363
View Source
const CREATE = 57346
View Source
const DATABASE = 57348
View Source
const DESC = 57381
View Source
const DISTINCT = 57369
View Source
const ERROR = 57398
View Source
const EXISTS = 57386
View Source
const EncIDLen = 8
View Source
const EncLenLen = 4
View Source
const FROM = 57370
View Source
const GROUP = 57376
View Source
const HAVING = 57374
View Source
const IDENTIFIER = 57391
View Source
const IF = 57385
View Source
const INDEX = 57354
View Source
const INSERT = 57364
View Source
const INTO = 57366
View Source
const JOIN = 57373
View Source
const JOINTYPE = 57388
View Source
const KEY = 57360
View Source
const LIKE = 57384
View Source
const LIMIT = 57378
View Source
const LOP = 57389
View Source
const NOT = 57383
View Source
const NULL = 57387
View Source
const NUMBER = 57393
View Source
const ON = 57355
View Source
const ORDER = 57379
View Source
const PRIMARY = 57359
View Source
const (
	RowPrefix = "ROW." // (key=ROW.{dbID}{tableID}{colID}({valLen}{val})?{pkValLen}{pkVal}, value={})
)
View Source
const SELECT = 57368
View Source
const SINCE = 57350
View Source
const SNAPSHOT = 57349
View Source
const STMT_SEPARATOR = 57399
View Source
const TABLE = 57353
View Source
const TO = 57352
View Source
const TRANSACTION = 57362
View Source
const TX = 57372
View Source
const TYPE = 57392
View Source
const UP = 57351
View Source
const UPSERT = 57365
View Source
const USE = 57347
View Source
const VALUES = 57367
View Source
const VARCHAR = 57394
View Source
const WHERE = 57375

Variables

View Source
var ErrAlreadyClosed = errors.New("sql engine already closed")
View Source
var ErrColumnDoesNotExist = errors.New("column does not exist")
View Source
var ErrColumnIsNotAnAggregation = errors.New("column is not an aggregation")
View Source
var ErrColumnNotIndexed = errors.New("column is not indexed")
View Source
var ErrCorruptedData = store.ErrCorruptedData
View Source
var ErrDDLorDMLTxOnly = errors.New("transactions can NOT combine DDL and DML statements")
View Source
var ErrDatabaseAlreadyExists = errors.New("database already exists")
View Source
var ErrDatabaseDoesNotExist = errors.New("database does not exist")
View Source
var ErrDivisionByZero = errors.New("division by zero")
View Source
var ErrDuplicatedColumn = errors.New("duplicated column")
View Source
var ErrExpectingDQLStmt = errors.New("illegal statement. DQL statement expected")
View Source
var ErrHavingClauseRequiresGroupClause = errors.New("having clause requires group clause")
View Source
var ErrIllegalArguments = store.ErrIllegalArguments
View Source
var ErrIllegalMappedKey = errors.New("error illegal mapped key")
View Source
var ErrIndexAlreadyExists = errors.New("index already exists")
View Source
var ErrIndexedColumnCanNotBeNull = errors.New("indexed column can not be null")
View Source
var ErrInvalidColumn = errors.New("invalid column")
View Source
var ErrInvalidCondition = errors.New("invalid condition")
View Source
var ErrInvalidJointColumn = errors.New("invalid joint column")
View Source
var ErrInvalidNumberOfValues = errors.New("invalid number of values provided")
View Source
var ErrInvalidPK = errors.New("primary key of invalid type. Supported types are: INTEGER, STRING[256], TIMESTAMP OR BLOB[256]")
View Source
var ErrInvalidValue = errors.New("invalid value provided")
View Source
var ErrJointColumnNotFound = errors.New("joint column not found")
View Source
var ErrLimitedCount = errors.New("only unbounded counting is supported i.e. COUNT()")
View Source
var ErrLimitedIndex = errors.New("index creation is only supported on empty tables")
View Source
var ErrLimitedJoins = errors.New("joins limited to tables")
View Source
var ErrLimitedOrderBy = errors.New("order is limit to one indexed column")
View Source
var ErrMaxKeyLengthExceeded = errors.New("max key length exceeded")
View Source
var ErrMissingParameter = errors.New("missing paramter")
View Source
var ErrNoDatabaseSelected = errors.New("no database selected")
View Source
var ErrNoMoreRows = store.ErrNoMoreEntries
View Source
var ErrNoSupported = errors.New("not yet supported")
View Source
var ErrNotComparableValues = errors.New("values are not comparable")
View Source
var ErrNotNullableColumnCannotBeNull = errors.New("not nullable column can not be null")
View Source
var ErrPKCanNotBeNull = errors.New("primary key can not be null")
View Source
var ErrTableAlreadyExists = errors.New("table already exists")
View Source
var ErrTableDoesNotExist = errors.New("table does not exist")
View Source
var ErrTxDoesNotExist = errors.New("tx does not exist")
View Source
var ErrUnexpected = errors.New("unexpected error")
View Source
var ErrUnsupportedJoinType = errors.New("unsupported join type")
View Source
var ErrUnsupportedParameter = errors.New("unsupported parameter")

Functions

func EncodeID

func EncodeID(id uint64) []byte

func EncodeRawValue

func EncodeRawValue(val interface{}, colType SQLValueType, asKey bool) ([]byte, error)

func EncodeSelector

func EncodeSelector(aggFn, db, table, col string) string

func EncodeValue

func EncodeValue(val TypedValue, colType SQLValueType, asKey bool) ([]byte, error)

func MapKey

func MapKey(prefix []byte, mappingPrefix string, encValues ...[]byte) []byte

Types

type AVGValue

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

func (*AVGValue) ColBounded

func (v *AVGValue) ColBounded() bool

func (*AVGValue) Compare

func (v *AVGValue) Compare(val TypedValue) (int, error)

func (*AVGValue) Selector

func (v *AVGValue) Selector() string

func (*AVGValue) Type

func (v *AVGValue) Type() SQLValueType

func (*AVGValue) Value

func (v *AVGValue) Value() interface{}

type AddColumnStmt

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

func (*AddColumnStmt) CompileUsing

func (stmt *AddColumnStmt) CompileUsing(e *Engine, implicitDB *Database, params map[string]interface{}) (ces, des []*store.KV, db *Database, err error)

type AggColSelector

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

type AggregateFn

type AggregateFn = string

type AggregatedValue

type AggregatedValue interface {
	TypedValue

	Selector() string
	ColBounded() bool
	// contains filtered or unexported methods
}

type BinBoolExp

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

type Blob

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

func (*Blob) Compare

func (v *Blob) Compare(val TypedValue) (int, error)

func (*Blob) Type

func (v *Blob) Type() SQLValueType

func (*Blob) Value

func (v *Blob) Value() interface{}

type Bool

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

func (*Bool) Compare

func (v *Bool) Compare(val TypedValue) (int, error)

func (*Bool) Type

func (v *Bool) Type() SQLValueType

func (*Bool) Value

func (v *Bool) Value() interface{}

type Catalog

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

func (*Catalog) Databases

func (c *Catalog) Databases() []*Database

func (*Catalog) ExistDatabase

func (c *Catalog) ExistDatabase(db string) bool

func (*Catalog) GetDatabaseByID

func (c *Catalog) GetDatabaseByID(id uint64) (*Database, error)

func (*Catalog) GetDatabaseByName

func (c *Catalog) GetDatabaseByName(name string) (*Database, error)

func (*Catalog) GetTableByName

func (c *Catalog) GetTableByName(dbName, tableName string) (*Table, error)

type CmpBoolExp

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

type CmpOperator

type CmpOperator = int
const (
	EQ CmpOperator = iota
	NE
	LT
	LE
	GT
	GE
)

type ColDescriptor

type ColDescriptor struct {
	Selector string
	Type     SQLValueType
}

type ColSelector

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

type ColSpec

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

type Column

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

func (*Column) ID

func (c *Column) ID() uint64

func (*Column) IsNullable

func (c *Column) IsNullable() bool

func (*Column) Name

func (c *Column) Name() string

func (*Column) Type

func (c *Column) Type() SQLValueType

type Comparison

type Comparison int
const (
	EqualTo Comparison = iota
	LowerThan
	LowerOrEqualTo
	GreaterThan
	GreaterOrEqualTo
)

type CountValue

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

func (*CountValue) ColBounded

func (v *CountValue) ColBounded() bool

func (*CountValue) Compare

func (v *CountValue) Compare(val TypedValue) (int, error)

func (*CountValue) Selector

func (v *CountValue) Selector() string

func (*CountValue) Type

func (v *CountValue) Type() SQLValueType

func (*CountValue) Value

func (v *CountValue) Value() interface{}

type CreateDatabaseStmt

type CreateDatabaseStmt struct {
	DB string
}

func (*CreateDatabaseStmt) CompileUsing

func (stmt *CreateDatabaseStmt) CompileUsing(e *Engine, implicitDB *Database, params map[string]interface{}) (ces, des []*store.KV, db *Database, err error)

type CreateIndexStmt

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

func (*CreateIndexStmt) CompileUsing

func (stmt *CreateIndexStmt) CompileUsing(e *Engine, implicitDB *Database, params map[string]interface{}) (ces, des []*store.KV, db *Database, err error)

type CreateTableStmt

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

func (*CreateTableStmt) CompileUsing

func (stmt *CreateTableStmt) CompileUsing(e *Engine, implicitDB *Database, params map[string]interface{}) (ces, des []*store.KV, db *Database, err error)

type DataSource

type DataSource interface {
	Resolve(e *Engine, implicitDB *Database, snap *store.Snapshot, params map[string]interface{}, ordCol *OrdCol) (RowReader, error)
	Alias() string
}

type Database

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

func (*Database) ExistTable

func (db *Database) ExistTable(table string) bool

func (*Database) GetTableByID

func (db *Database) GetTableByID(id uint64) (*Table, error)

func (*Database) GetTableByName

func (db *Database) GetTableByName(name string) (*Table, error)

func (*Database) GetTables

func (db *Database) GetTables() []*Table

func (*Database) ID

func (db *Database) ID() uint64

func (*Database) Name

func (db *Database) Name() string

type Engine

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

func NewEngine

func NewEngine(catalogStore, dataStore *store.ImmuStore, prefix []byte) (*Engine, error)

func (*Engine) Catalog

func (e *Engine) Catalog() *Catalog

func (*Engine) Close

func (e *Engine) Close() error

func (*Engine) CloseSnapshot

func (e *Engine) CloseSnapshot() error

func (*Engine) DatabaseInUse

func (e *Engine) DatabaseInUse() (*Database, error)

func (*Engine) Exec

func (e *Engine) Exec(sql io.ByteReader, params map[string]interface{}, waitForIndexing bool) (ddTxs, dmTxs []*store.TxMetadata, err error)

func (*Engine) ExecPreparedStmts

func (e *Engine) ExecPreparedStmts(stmts []SQLStmt, params map[string]interface{}, waitForIndexing bool) (ddTxs, dmTxs []*store.TxMetadata, err error)

func (*Engine) ExecStmt

func (e *Engine) ExecStmt(sql string, params map[string]interface{}, waitForIndexing bool) (ddTxs, dmTxs []*store.TxMetadata, err error)

func (*Engine) Query

func (e *Engine) Query(sql io.ByteReader, params map[string]interface{}, renewSnapshot bool) (RowReader, error)

func (*Engine) QueryPreparedStmt

func (e *Engine) QueryPreparedStmt(stmt *SelectStmt, params map[string]interface{}, renewSnapshot bool) (RowReader, error)

func (*Engine) QueryStmt

func (e *Engine) QueryStmt(sql string, params map[string]interface{}, renewSnapshot bool) (RowReader, error)

exist database directly on catalogStore: // existKey(e.mapKey(catalogDatabase, db), e.catalogStore)

func (*Engine) RenewSnapshot

func (e *Engine) RenewSnapshot() error

func (*Engine) Snapshot

func (e *Engine) Snapshot() (*store.Snapshot, error)

func (*Engine) UseDatabase

func (e *Engine) UseDatabase(dbName string) error

func (*Engine) UseSnapshot

func (e *Engine) UseSnapshot(sinceTx uint64, asBeforeTx uint64) error

type ExistsBoolExp

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

type GroupBySpec

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

type JoinSpec

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

type JoinType

type JoinType = int
const (
	InnerJoin JoinType = iota
	LeftJoin
	RightJoin
)

type LikeBoolExp

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

type LogicOperator

type LogicOperator = int
const (
	AND LogicOperator = iota
	OR
)

type MaxValue

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

func (*MaxValue) ColBounded

func (v *MaxValue) ColBounded() bool

func (*MaxValue) Compare

func (v *MaxValue) Compare(val TypedValue) (int, error)

func (*MaxValue) Selector

func (v *MaxValue) Selector() string

func (*MaxValue) Type

func (v *MaxValue) Type() SQLValueType

func (*MaxValue) Value

func (v *MaxValue) Value() interface{}

type MinValue

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

func (*MinValue) ColBounded

func (v *MinValue) ColBounded() bool

func (*MinValue) Compare

func (v *MinValue) Compare(val TypedValue) (int, error)

func (*MinValue) Selector

func (v *MinValue) Selector() string

func (*MinValue) Type

func (v *MinValue) Type() SQLValueType

func (*MinValue) Value

func (v *MinValue) Value() interface{}

type NotBoolExp

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

type NullValue

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

func (*NullValue) Compare

func (n *NullValue) Compare(val TypedValue) (int, error)

func (*NullValue) Type

func (n *NullValue) Type() SQLValueType

func (*NullValue) Value

func (n *NullValue) Value() interface{}

type NumExp

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

type NumOperator

type NumOperator = int
const (
	ADDOP NumOperator = iota
	SUBSOP
	DIVOP
	MULTOP
)

type Number

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

func (*Number) Compare

func (v *Number) Compare(val TypedValue) (int, error)

func (*Number) Type

func (v *Number) Type() SQLValueType

func (*Number) Value

func (v *Number) Value() interface{}

type OrdCol

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

type Param

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

type Row

type Row struct {
	Values map[string]TypedValue
}

func (*Row) Compatible

func (row *Row) Compatible(aRow *Row, selectors []*ColSelector, db, table string) (bool, error)

rows are selector-compatible if both rows have the same assigned value for all specified selectors

type RowReader

type RowReader interface {
	ImplicitDB() string
	ImplicitTable() string
	Read() (*Row, error)
	Close() error
	Columns() ([]*ColDescriptor, error)
	// contains filtered or unexported methods
}

type RowSpec

type RowSpec struct {
	Values []ValueExp
}

type SQLStmt

type SQLStmt interface {
	CompileUsing(e *Engine, implicitDB *Database, params map[string]interface{}) (ces, des []*store.KV, db *Database, err error)
	// contains filtered or unexported methods
}

func Parse

func Parse(r io.ByteReader) ([]SQLStmt, error)

func ParseString

func ParseString(sql string) ([]SQLStmt, error)

type SQLValueType

type SQLValueType = string

type SelectStmt

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

func (*SelectStmt) Alias

func (stmt *SelectStmt) Alias() string

func (*SelectStmt) CompileUsing

func (stmt *SelectStmt) CompileUsing(e *Engine, implicitDB *Database, params map[string]interface{}) (ces, des []*store.KV, db *Database, err error)

func (*SelectStmt) Limit

func (stmt *SelectStmt) Limit() uint64

func (*SelectStmt) Resolve

func (stmt *SelectStmt) Resolve(e *Engine, implicitDB *Database, snap *store.Snapshot, params map[string]interface{}, ordCol *OrdCol) (RowReader, error)

type Selector

type Selector interface {
	ValueExp
	// contains filtered or unexported methods
}

type SumValue

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

func (*SumValue) ColBounded

func (v *SumValue) ColBounded() bool

func (*SumValue) Compare

func (v *SumValue) Compare(val TypedValue) (int, error)

func (*SumValue) Selector

func (v *SumValue) Selector() string

func (*SumValue) Type

func (v *SumValue) Type() SQLValueType

func (*SumValue) Value

func (v *SumValue) Value() interface{}

type SysFn

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

type Table

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

func (*Table) ColsByID

func (t *Table) ColsByID() map[uint64]*Column

func (*Table) ColsByName

func (t *Table) ColsByName() map[string]*Column

func (*Table) Database

func (t *Table) Database() *Database

func (*Table) GetColumnByID

func (t *Table) GetColumnByID(id uint64) (*Column, error)

func (*Table) GetColumnByName

func (t *Table) GetColumnByName(name string) (*Column, error)

func (*Table) ID

func (t *Table) ID() uint64

func (*Table) IsIndexed

func (t *Table) IsIndexed(colName string) (bool, error)

func (*Table) Name

func (t *Table) Name() string

func (*Table) PrimaryKey

func (t *Table) PrimaryKey() *Column

type TableRef

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

func (*TableRef) Alias

func (stmt *TableRef) Alias() string

func (*TableRef) Resolve

func (stmt *TableRef) Resolve(e *Engine, implicitDB *Database, snap *store.Snapshot, params map[string]interface{}, ordCol *OrdCol) (RowReader, error)

type TxStmt

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

func (*TxStmt) CompileUsing

func (stmt *TxStmt) CompileUsing(e *Engine, implicitDB *Database, params map[string]interface{}) (ces, des []*store.KV, db *Database, err error)

type TypedValue

type TypedValue interface {
	Type() SQLValueType
	Value() interface{}
	Compare(val TypedValue) (int, error)
}

func DecodeValue

func DecodeValue(b []byte, colType SQLValueType) (TypedValue, int, error)

type UpsertIntoStmt

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

func (*UpsertIntoStmt) CompileUsing

func (stmt *UpsertIntoStmt) CompileUsing(e *Engine, implicitDB *Database, params map[string]interface{}) (ces, des []*store.KV, db *Database, err error)

func (*UpsertIntoStmt) Validate

func (stmt *UpsertIntoStmt) Validate(table *Table) (map[uint64]int, error)

type UseDatabaseStmt

type UseDatabaseStmt struct {
	DB string
}

func (*UseDatabaseStmt) CompileUsing

func (stmt *UseDatabaseStmt) CompileUsing(e *Engine, implicitDB *Database, params map[string]interface{}) (ces, des []*store.KV, db *Database, err error)

type UseSnapshotStmt

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

func (*UseSnapshotStmt) CompileUsing

func (stmt *UseSnapshotStmt) CompileUsing(e *Engine, implicitDB *Database, params map[string]interface{}) (ces, des []*store.KV, db *Database, err error)

type ValueExp

type ValueExp interface {
	// contains filtered or unexported methods
}

type Varchar

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

func (*Varchar) Compare

func (v *Varchar) Compare(val TypedValue) (int, error)

func (*Varchar) Type

func (v *Varchar) Type() SQLValueType

func (*Varchar) Value

func (v *Varchar) Value() interface{}

Jump to

Keyboard shortcuts

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