summaryrefslogtreecommitdiff
path: root/internal/mapr/wherecondition.go
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2020-12-10 14:37:19 +0000
committerPaul Buetow <pbuetow@mimecast.com>2020-12-10 14:37:19 +0000
commit404cc052f028b6e2ba98c791553e7a561fecf626 (patch)
tree3f41ad369f6aa3303946aebac4aef68e90b094f0 /internal/mapr/wherecondition.go
parenta6017261ebd06629361d4794c8c2970e7eb04857 (diff)
add hasprefix, nhasprefix, hassuffix, nhassuffix operation support to where clause
Diffstat (limited to 'internal/mapr/wherecondition.go')
-rw-r--r--internal/mapr/wherecondition.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/mapr/wherecondition.go b/internal/mapr/wherecondition.go
index ff1b489..70e9c32 100644
--- a/internal/mapr/wherecondition.go
+++ b/internal/mapr/wherecondition.go
@@ -19,6 +19,10 @@ const (
StringNe QueryOperation = iota
StringContains QueryOperation = iota
StringNotContains QueryOperation = iota
+ StringHasPrefix QueryOperation = iota
+ StringNotHasPrefix QueryOperation = iota
+ StringHasSuffix QueryOperation = iota
+ StringNotHasSuffix QueryOperation = iota
FloatOperation QueryOperation = iota
FloatEq QueryOperation = iota
FloatNe QueryOperation = iota
@@ -78,7 +82,17 @@ func makeWhereConditions(tokens []token) (where []whereCondition, err error) {
case "contains":
wc.Operation = StringContains
case "lacks":
+ fallthrough
+ case "ncontains":
wc.Operation = StringNotContains
+ case "hasprefix":
+ wc.Operation = StringHasPrefix
+ case "nhasprefix":
+ wc.Operation = StringNotHasPrefix
+ case "hassuffix":
+ wc.Operation = StringHasSuffix
+ case "nhassuffix":
+ wc.Operation = StringNotHasSuffix
default:
return wc, nil, errors.New(invalidQuery + "Unknown operation in 'where' clause: " + whereOp)
}
@@ -169,6 +183,14 @@ func (wc *whereCondition) stringClause(lValue string, rValue string) bool {
return strings.Contains(lValue, rValue)
case StringNotContains:
return !strings.Contains(lValue, rValue)
+ case StringHasPrefix:
+ return strings.HasPrefix(lValue, rValue)
+ case StringNotHasPrefix:
+ return !strings.HasPrefix(lValue, rValue)
+ case StringHasSuffix:
+ return strings.HasSuffix(lValue, rValue)
+ case StringNotHasSuffix:
+ return !strings.HasSuffix(lValue, rValue)
default:
logger.Error("Unknown string operation", lValue, wc.Operation, rValue)
}