From f7bfae4044cb8e9a0f83e388eacd06dfe72c7ec4 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Sat, 31 Mar 2018 00:21:33 -0500 Subject: [PATCH] Update the interface for the simplified call valuer --- Godeps | 2 +- Gopkg.lock | 4 ++-- Gopkg.toml | 2 +- query/cursor.go | 7 ++++--- query/math.go | 54 +++++++++++++------------------------------------ 5 files changed, 22 insertions(+), 47 deletions(-) diff --git a/Godeps b/Godeps index 3fbe2fa965..804dc49f25 100644 --- a/Godeps +++ b/Godeps @@ -13,7 +13,7 @@ github.com/gogo/protobuf 1adfc126b41513cc696b209667c8656ea7aac67c github.com/golang/protobuf 925541529c1fa6821df4e44ce2723319eb2be768 github.com/golang/snappy d9eb7a3d35ec988b8585d4a0068e462c27d28380 github.com/google/go-cmp 3af367b6b30c263d47e8895973edcca9a49cf029 -github.com/influxdata/influxql 53bc9c15f65bea9e4b9f6cc5d9c5327d4077bdc5 +github.com/influxdata/influxql 145e0677ff6418fa00ee7e5dd434305631ab44ea github.com/influxdata/usage-client 6d3895376368aa52a3a81d2a16e90f0f52371967 github.com/influxdata/yamux 1f58ded512de5feabbe30b60c7d33a7a896c5f16 github.com/influxdata/yarpc f0da2db138cad2fb425541938fc28dd5a5bc6918 diff --git a/Gopkg.lock b/Gopkg.lock index c8ea9f45dc..2d66f57bed 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -113,7 +113,7 @@ ".", "internal" ] - revision = "53bc9c15f65bea9e4b9f6cc5d9c5327d4077bdc5" + revision = "145e0677ff6418fa00ee7e5dd434305631ab44ea" [[projects]] branch = "master" @@ -337,6 +337,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "24a09b8e892a864f31c3cd636006c3f8bcd9eea046b08c1a8d93b9da5b7206c6" + inputs-digest = "9bb6fd90291e987c895b33e55cd20d968e141b4583d47e28aa6dfb733b7a320b" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 3ce87b30ae..95d2b4ffea 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -32,7 +32,7 @@ [[constraint]] name = "github.com/influxdata/influxql" - revision = "53bc9c15f65bea9e4b9f6cc5d9c5327d4077bdc5" + revision = "145e0677ff6418fa00ee7e5dd434305631ab44ea" [[constraint]] name = "github.com/mattn/go-isatty" diff --git a/query/cursor.go b/query/cursor.go index 1ca66d01ab..694465b24b 100644 --- a/query/cursor.go +++ b/query/cursor.go @@ -190,9 +190,10 @@ func (cur *scannerCursorBase) Scan(row *Row) bool { } valuer := influxql.ValuerEval{ - Valuer: &MathValuer{ - Valuer: influxql.MapValuer(cur.m), - }, + Valuer: influxql.MultiValuer( + MathValuer{}, + influxql.MapValuer(cur.m), + ), IntegerFloatDivision: true, } for i, expr := range cur.fields { diff --git a/query/math.go b/query/math.go index a2b64e9a2c..fb96da71f9 100644 --- a/query/math.go +++ b/query/math.go @@ -2,7 +2,6 @@ package query import ( "math" - "time" "github.com/influxdata/influxql" ) @@ -29,63 +28,38 @@ func (MathTypeMapper) CallType(name string, args []influxql.DataType) (influxql. return influxql.Unknown, nil } -type MathValuer struct { - Valuer influxql.Valuer -} +type MathValuer struct{} -func (v *MathValuer) Value(key string) (interface{}, bool) { - if v.Valuer != nil { - return v.Valuer.Value(key) - } +var _ influxql.CallValuer = MathValuer{} + +func (MathValuer) Value(key string) (interface{}, bool) { return nil, false } -func (v *MathValuer) Call(name string, args []influxql.Expr) (interface{}, bool) { +func (v MathValuer) Call(name string, args []interface{}) (interface{}, bool) { if len(args) == 1 { + arg0 := args[0] switch name { case "sin": - return v.callTrigFunction(math.Sin, args[0]) + return v.callTrigFunction(math.Sin, arg0) case "cos": - return v.callTrigFunction(math.Cos, args[0]) + return v.callTrigFunction(math.Cos, arg0) case "tan": - return v.callTrigFunction(math.Tan, args[0]) + return v.callTrigFunction(math.Tan, arg0) } } - if v, ok := v.Valuer.(influxql.CallValuer); ok { - return v.Call(name, args) - } return nil, false } -func (v *MathValuer) callTrigFunction(fn func(x float64) float64, arg0 influxql.Expr) (interface{}, bool) { +func (MathValuer) callTrigFunction(fn func(x float64) float64, arg0 interface{}) (interface{}, bool) { var value float64 switch arg0 := arg0.(type) { - case *influxql.NumberLiteral: - value = arg0.Val - case *influxql.IntegerLiteral: - value = float64(arg0.Val) - case *influxql.VarRef: - if v.Valuer == nil { - return nil, false - } else if val, ok := v.Valuer.Value(arg0.Val); ok { - switch val := val.(type) { - case float64: - value = val - case int64: - value = float64(val) - } - } else { - return nil, false - } + case float64: + value = arg0 + case int64: + value = float64(arg0) default: return nil, false } return fn(value), true } - -func (v *MathValuer) Zone() *time.Location { - if v, ok := v.Valuer.(influxql.ZoneValuer); ok { - return v.Zone() - } - return nil -}