Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package relay

import (
"errors"
"fmt"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -271,14 +272,48 @@ func markRecords(filterConditions string, val reflect.Value, arraySlice map[int]
return nil, errors.New("Filter [" + ColumnStruct[1] + "] Column is not primitive type")
}

} else if CurField.Kind() == reflect.Slice {
if len(ColumnStruct) < 2 {
continue
}
fieldName := ColumnStruct[1]
if fieldName == "" {
return nil, errors.New("Filter applied to slice column but inner field not specified")
}

for i := 0; i < CurField.Len(); i++ {
item := CurField.Index(i)

bMatched, err = itemMatches(item, fieldName, Key, Op)
if err != nil {
return nil, err
}
}
}

arraySlice[k] = DataSet{bMatched: bMatched, CurRec: arraySlice[k].CurRec}
}
}
}
return arraySlice, nil
}

func itemMatches(item reflect.Value, fieldName, key, op string) (bool, error) {
if !item.IsValid() {
return false, fmt.Errorf("Filter [%s] No such column exist!!!", fieldName)
}

if item.FieldByName("ID").String() != fieldName {
return false, nil
}

if !isPrimitive(item.FieldByName("Value")) {
return false, fmt.Errorf("Filter [%s] Value is not primitive type", fieldName)
}

return processPrimitive(item.FieldByName("Value"), key, op)
}

func isPrimitive(CurField reflect.Value) bool {
switch CurField.Kind() {
case reflect.Bool, reflect.String, reflect.Float32, reflect.Float64, reflect.Int, reflect.Int32, reflect.Int64:
Expand Down
Loading