Skip to content

Commit

Permalink
Merge pull request #7 from vigith/fixOr
Browse files Browse the repository at this point in the history
fix Or
  • Loading branch information
jbguerraz authored Jan 20, 2021
2 parents eb6420a + a476207 commit 94c8825
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions builder/filter/or.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package filter

import (
"encoding/json"
"github.com/grafadruid/go-druid/builder"
)

type Or struct {
Base
Fields []string `json:"fields,omitempty"`
Fields []builder.Filter `json:"fields,omitempty"`
}

func NewOr() *Or {
Expand All @@ -11,7 +16,29 @@ func NewOr() *Or {
return o
}

func (o *Or) SetFields(fields []string) *Or {
func (o *Or) SetFields(fields []builder.Filter) *Or {
o.Fields = fields
return o
}

func (o *Or) UnmarshalJSON(data []byte) error {
var err error
var tmp struct {
Base
Fields []json.RawMessage `json:"fields,omitempty"`
}
if err = json.Unmarshal(data, &tmp); err != nil {
return err
}
var f builder.Filter
ff := make([]builder.Filter, len(tmp.Fields))
for i := range tmp.Fields {
if f, err = Load(tmp.Fields[i]); err != nil {
return err
}
ff[i] = f
}
o.Base = tmp.Base
o.Fields = ff
return nil
}

0 comments on commit 94c8825

Please sign in to comment.