forked from tobgu/qframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.go
111 lines (94 loc) · 2.43 KB
/
filters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package ecolumn
import (
"github.com/tobgu/qframe/errors"
"github.com/tobgu/qframe/filter"
"github.com/tobgu/qframe/internal/index"
qfstrings "github.com/tobgu/qframe/internal/strings"
)
var filterFuncs0 = map[string]func(index.Int, []enumVal, index.Bool){
filter.IsNull: isNull,
filter.IsNotNull: isNotNull,
}
var filterFuncs1 = map[string]func(index.Int, []enumVal, enumVal, index.Bool){
filter.Gt: gt,
filter.Gte: gte,
filter.Lt: lt,
filter.Lte: lte,
filter.Eq: eq,
filter.Neq: neq,
}
var filterFuncs2 = map[string]func(index.Int, []enumVal, []enumVal, index.Bool){
filter.Gt: gt2,
filter.Gte: gte2,
filter.Lt: lt2,
filter.Lte: lte2,
filter.Eq: eq2,
filter.Neq: neq2,
}
var multiFilterFuncs = map[string]func(comparatee string, values []string) (*bitset, error){
"like": like,
"ilike": ilike,
}
var multiInputFilterFuncs = map[string]func(comparatee qfstrings.StringSet, values []string) *bitset{
"in": in,
}
func like(comp string, values []string) (*bitset, error) {
return filterLike(comp, values, true)
}
func ilike(comp string, values []string) (*bitset, error) {
return filterLike(comp, values, false)
}
func filterLike(comp string, values []string, caseSensitive bool) (*bitset, error) {
matcher, err := qfstrings.NewMatcher(comp, caseSensitive)
if err != nil {
return nil, errors.Propagate("enum like", err)
}
bset := &bitset{}
for i, v := range values {
if matcher.Matches(v) {
bset.set(enumVal(i))
}
}
return bset, nil
}
func in(comp qfstrings.StringSet, values []string) *bitset {
bset := &bitset{}
for i, v := range values {
if comp.Contains(v) {
bset.set(enumVal(i))
}
}
return bset
}
func neq(index index.Int, column []enumVal, comparatee enumVal, bIndex index.Bool) {
for i, x := range bIndex {
if !x {
enum := column[index[i]]
bIndex[i] = enum.isNull() || enum.compVal() != comparatee.compVal()
}
}
}
func neq2(index index.Int, col, col2 []enumVal, bIndex index.Bool) {
for i, x := range bIndex {
if !x {
enum, enum2 := col[index[i]], col2[index[i]]
bIndex[i] = enum.isNull() || enum2.isNull() || enum.compVal() != enum2.compVal()
}
}
}
func isNull(index index.Int, col []enumVal, bIndex index.Bool) {
for i, x := range bIndex {
if !x {
enum := col[index[i]]
bIndex[i] = enum.isNull()
}
}
}
func isNotNull(index index.Int, col []enumVal, bIndex index.Bool) {
for i, x := range bIndex {
if !x {
enum := col[index[i]]
bIndex[i] = !enum.isNull()
}
}
}