aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorTing-Wei Lan <tingwei.lan@cobinhood.com>2019-03-28 11:56:56 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:04 +0800
commit10861508f90fa45ad65f5f15163614cdaec8f9f8 (patch)
tree4e9dd88cb7f71f68a3a5421058ab83f4524ec648 /core
parent8c4e09207c74294364eefa14159338908bc65f67 (diff)
downloaddexon-10861508f90fa45ad65f5f15163614cdaec8f9f8.tar
dexon-10861508f90fa45ad65f5f15163614cdaec8f9f8.tar.gz
dexon-10861508f90fa45ad65f5f15163614cdaec8f9f8.tar.bz2
dexon-10861508f90fa45ad65f5f15163614cdaec8f9f8.tar.lz
dexon-10861508f90fa45ad65f5f15163614cdaec8f9f8.tar.xz
dexon-10861508f90fa45ad65f5f15163614cdaec8f9f8.tar.zst
dexon-10861508f90fa45ad65f5f15163614cdaec8f9f8.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.go8
-rw-r--r--core/vm/sqlvm/schema/schema.go43
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
+}