diff options
author | Ting-Wei Lan <tingwei.lan@cobinhood.com> | 2019-03-28 11:56:56 +0800 |
---|---|---|
committer | lantw44 <lantw44@gmail.com> | 2019-03-29 18:40:42 +0800 |
commit | 679d5e9571bc9a1af090252fb0dcbec1cd28b46c (patch) | |
tree | 903d08ae763b0efdf04a8509396451288796d6a4 /core | |
parent | eb7c259337e4cc1792fbe86e71d1dd842a890e13 (diff) | |
download | dexon-679d5e9571bc9a1af090252fb0dcbec1cd28b46c.tar dexon-679d5e9571bc9a1af090252fb0dcbec1cd28b46c.tar.gz dexon-679d5e9571bc9a1af090252fb0dcbec1cd28b46c.tar.bz2 dexon-679d5e9571bc9a1af090252fb0dcbec1cd28b46c.tar.lz dexon-679d5e9571bc9a1af090252fb0dcbec1cd28b46c.tar.xz dexon-679d5e9571bc9a1af090252fb0dcbec1cd28b46c.tar.zst dexon-679d5e9571bc9a1af090252fb0dcbec1cd28b46c.zip |
core: vm: sqlvm: add a descriptor field to IdentifierNode
It will be used to store the descriptor of the object after the name is
resolved.
Diffstat (limited to 'core')
-rw-r--r-- | core/vm/sqlvm/ast/ast.go | 8 | ||||
-rw-r--r-- | core/vm/sqlvm/schema/schema.go | 43 |
2 files changed, 51 insertions, 0 deletions
diff --git a/core/vm/sqlvm/ast/ast.go b/core/vm/sqlvm/ast/ast.go index 0a82ac76c..d5ebb35af 100644 --- a/core/vm/sqlvm/ast/ast.go +++ b/core/vm/sqlvm/ast/ast.go @@ -105,10 +105,18 @@ func (n *TaggedExprNodeBase) SetType(t DataType) { n.Type = t } +// IdentifierDescriptor defines the interface of a descriptor. A descriptor +// identifies an object in a SQL statement. This interface is intended to be +// used by IdentifierNode to store the target after the name is resolved. +type IdentifierDescriptor interface { + GetDescriptor() uint32 +} + // IdentifierNode references table, column, or function. type IdentifierNode struct { TaggedExprNodeBase Name []byte + Desc IdentifierDescriptor } var _ ExprNode = (*IdentifierNode)(nil) diff --git a/core/vm/sqlvm/schema/schema.go b/core/vm/sqlvm/schema/schema.go index 2937d3660..0d40a9612 100644 --- a/core/vm/sqlvm/schema/schema.go +++ b/core/vm/sqlvm/schema/schema.go @@ -61,6 +61,9 @@ func (a ColumnAttr) GetDerivedFlags() ColumnAttr { return a & mask } +// FunctionRef defines the type for number of builtin function. +type FunctionRef uint16 + // TableRef defines the type for table index in Schema. type TableRef uint8 @@ -261,25 +264,65 @@ func (c *Column) DecodeRLP(s *rlp.Stream) error { return nil } +// FunctionDescriptor identifies a function. +type FunctionDescriptor struct { + Function FunctionRef +} + +var _ ast.IdentifierDescriptor = (*FunctionDescriptor)(nil) + +// GetDescriptor is a useless function to satisfy the interface. +func (d FunctionDescriptor) GetDescriptor() uint32 { + return uint32(0)<<24 | uint32(d.Function)<<8 +} + // TableDescriptor identifies a table in a schema by an array index. type TableDescriptor struct { Table TableRef } +var _ ast.IdentifierDescriptor = (*TableDescriptor)(nil) + +// GetDescriptor is a useless function to satisfy the interface. +func (d TableDescriptor) GetDescriptor() uint32 { + return uint32(1)<<24 | uint32(d.Table)<<16 +} + // ColumnDescriptor identifies a column in a schema by array indices. type ColumnDescriptor struct { Table TableRef Column ColumnRef } +var _ ast.IdentifierDescriptor = (*ColumnDescriptor)(nil) + +// GetDescriptor is a useless function to satisfy the interface. +func (d ColumnDescriptor) GetDescriptor() uint32 { + return uint32(2)<<24 | uint32(d.Table)<<16 | uint32(d.Column)<<8 +} + // IndexDescriptor identifies a index in a schema by array indices. type IndexDescriptor struct { Table TableRef Index IndexRef } +var _ ast.IdentifierDescriptor = (*IndexDescriptor)(nil) + +// GetDescriptor is a useless function to satisfy the interface. +func (d IndexDescriptor) GetDescriptor() uint32 { + return uint32(3)<<24 | uint32(d.Table)<<16 | uint32(d.Index)<<8 +} + // SelectColumnDescriptor identifies a column specified in a select command by // an array index. type SelectColumnDescriptor struct { SelectColumn SelectColumnRef } + +var _ ast.IdentifierDescriptor = (*SelectColumnDescriptor)(nil) + +// GetDescriptor is a useless function to satisfy the interface. +func (d SelectColumnDescriptor) GetDescriptor() uint32 { + return uint32(4)<<24 | uint32(d.SelectColumn)<<8 +} |