Update the interface for the simplified call valuer

pull/9666/head
Jonathan A. Sternberg 2018-03-31 00:21:33 -05:00
parent 5e08187cb6
commit f7bfae4044
5 changed files with 22 additions and 47 deletions

2
Godeps
View File

@ -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

4
Gopkg.lock generated
View File

@ -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

View File

@ -32,7 +32,7 @@
[[constraint]]
name = "github.com/influxdata/influxql"
revision = "53bc9c15f65bea9e4b9f6cc5d9c5327d4077bdc5"
revision = "145e0677ff6418fa00ee7e5dd434305631ab44ea"
[[constraint]]
name = "github.com/mattn/go-isatty"

View File

@ -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 {

View File

@ -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
}