aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/sqlvm/ast
diff options
context:
space:
mode:
authorwmin0 <wmin0@cobinhood.com>2019-03-05 16:05:35 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:04 +0800
commit72aec0139d85a2b5e2a5684f1f0a20f2db208d2e (patch)
treebc4cefef1de31a17e31b8b02a4a7f11f08cdf706 /core/vm/sqlvm/ast
parent698e83b3cc39737a45244ac2d47595964f6e468c (diff)
downloaddexon-72aec0139d85a2b5e2a5684f1f0a20f2db208d2e.tar
dexon-72aec0139d85a2b5e2a5684f1f0a20f2db208d2e.tar.gz
dexon-72aec0139d85a2b5e2a5684f1f0a20f2db208d2e.tar.bz2
dexon-72aec0139d85a2b5e2a5684f1f0a20f2db208d2e.tar.lz
dexon-72aec0139d85a2b5e2a5684f1f0a20f2db208d2e.tar.xz
dexon-72aec0139d85a2b5e2a5684f1f0a20f2db208d2e.tar.zst
dexon-72aec0139d85a2b5e2a5684f1f0a20f2db208d2e.zip
core: vm: sqlvm: add ESCAPE grammar
Provide ESCAPE grammar for specifying escape character in like pattern matching.
Diffstat (limited to 'core/vm/sqlvm/ast')
-rw-r--r--core/vm/sqlvm/ast/ast.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/core/vm/sqlvm/ast/ast.go b/core/vm/sqlvm/ast/ast.go
index 3a1d12c19..9a5afb202 100644
--- a/core/vm/sqlvm/ast/ast.go
+++ b/core/vm/sqlvm/ast/ast.go
@@ -756,6 +756,7 @@ func (n *IsOperatorNode) GetType() DataType {
type LikeOperatorNode struct {
UntaggedExprNodeBase
BinaryOperatorNode
+ Escape ExprNode
}
var _ BinaryOperator = (*LikeOperatorNode)(nil)
@@ -765,6 +766,40 @@ func (n *LikeOperatorNode) GetType() DataType {
return ComposeDataType(DataTypeMajorBool, DataTypeMinorDontCare)
}
+// GetChildren returns a list of child nodes used for traversing.
+func (n *LikeOperatorNode) GetChildren() []Node {
+ size := 2
+ if n.Escape != nil {
+ size++
+ }
+
+ idx := 0
+ nodes := make([]Node, size)
+ nodes[idx] = n.Object
+ idx++
+ nodes[idx] = n.Subject
+ idx++
+ if n.Escape != nil {
+ nodes[idx] = n.Escape
+ idx++
+ }
+ return nodes
+}
+
+// IsConstant returns whether a node is a constant.
+func (n *LikeOperatorNode) IsConstant() bool {
+ if !n.Object.IsConstant() {
+ return false
+ }
+ if !n.Subject.IsConstant() {
+ return false
+ }
+ if n.Escape != nil && !n.Escape.IsConstant() {
+ return false
+ }
+ return true
+}
+
// ---------------------------------------------------------------------------
// Cast
// ---------------------------------------------------------------------------