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