diff --git a/go.mod b/go.mod index 6e0a32512..f1d6d285b 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,6 @@ require ( github.com/gorilla/securecookie v1.1.1 github.com/hashicorp/go-retryablehttp v0.7.0 github.com/improbable-eng/grpc-web v0.13.0 - github.com/jinzhu/copier v0.3.5 github.com/lib/pq v1.8.0 github.com/molecula/apophenia v0.0.0-20190827192002-68b7a14a478b github.com/opentracing/opentracing-go v1.1.0 diff --git a/go.sum b/go.sum index fdbdb8c1c..2778ff697 100644 --- a/go.sum +++ b/go.sum @@ -220,8 +220,6 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/tdigest v0.0.0-20180711151920-a7d76c6f093a h1:vMqgISSVkIqWxCIZs8m1L4096temR7IbYyNdMiBxSPA= github.com/influxdata/tdigest v0.0.0-20180711151920-a7d76c6f093a/go.mod h1:9GkyshztGufsdPQWjH+ifgnIr3xNUL5syI70g2dzU1o= -github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg= -github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= diff --git a/pql/ast.go b/pql/ast.go index 3aa6a29db..2f9ec02e8 100644 --- a/pql/ast.go +++ b/pql/ast.go @@ -9,8 +9,6 @@ import ( "strconv" "strings" "time" - - "github.com/jinzhu/copier" ) // Query represents a PQL query. @@ -625,7 +623,7 @@ func (c *Call) CheckCallInfo() error { case []interface{}, *Variable: continue default: - return fmt.Errorf("'%s': arg '%s' needed a []interfacer{} or variable value, got %T", + return fmt.Errorf("'%s': arg '%s' needed a []interface{} or variable value, got %T", c.String(), k, v) } } @@ -955,23 +953,25 @@ func (c *Call) ExpandVars(vars map[string]interface{}) ([]*Call, error) { for argK, argV := range c.Args { variable := getVariable(argV) if variable == nil { - return []*Call{c}, nil + continue } for varK, varV := range vars { - if variable.Name == varK { - switch values := varV.(type) { - case []interface{}: - return c.expandVars(argK, values), nil - default: - return nil, fmt.Errorf("expected variable value of type []interface{}, got: %T", values) - } + if variable.Name != varK { + continue } + switch values := varV.(type) { + case []interface{}: + return c.expandVars(argK, values), nil + default: + return nil, fmt.Errorf("expected variable value of type []interface{}, got: %T", values) + } + } } return []*Call{c}, nil default: - other := &Call{} - copier.Copy(other, c) + other := *c + other.Args = CopyArgs(c.Args) other.Children = make([]*Call, 0, len(c.Children)) for _, child := range c.Children { newChildren, err := child.ExpandVars(vars) @@ -993,7 +993,7 @@ func (c *Call) ExpandVars(vars map[string]interface{}) ([]*Call, error) { other.Args[key] = newArg[0] } } - return []*Call{other}, nil + return []*Call{&other}, nil } } @@ -1003,8 +1003,7 @@ func (c *Call) expandVars(name string, values []interface{}) []*Call { case "Row": union := &Call{Name: "Union"} for i := range values { - r := Call{Name: "Row"} - r.Args = CopyArgs(c.Args) + r := Call{Name: "Row", Args: CopyArgs(c.Args)} switch cond := r.Args[name].(type) { case *Condition: r.Args[name] = &Condition{Op: cond.Op, Value: values[i]} @@ -1036,7 +1035,10 @@ func (c *Call) expandVars(name string, values []interface{}) []*Call { func getVariable(i interface{}) *Variable { switch _var := i.(type) { case *Condition: - return _var.Value.(*Variable) + if v, ok := _var.Value.(*Variable); ok { + return v + } + return nil case *Variable: // if interface{} is of type Variable return _var default: