Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing no longer used code in the query engine #6382

Merged
merged 1 commit into from
Apr 15, 2016
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [#6296](https://github.com/influxdata/influxdb/issues/6296): Allow the implicit time field to be renamed again.
- [#6379](https://github.com/influxdata/influxdb/issues/6379): Validate the first argument to percentile() is a variable.
- [#6294](https://github.com/influxdata/influxdb/issues/6294): Fix panic running influx_inspect info.
- [#6382](https://github.com/influxdata/influxdb/pull/6382): Removed dead code from the old query engine.

## v0.12.0 [2016-04-05]
### Release Notes
Expand Down
121 changes: 0 additions & 121 deletions influxql/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,124 +82,3 @@ func (r *Result) UnmarshalJSON(b []byte) error {
}
return nil
}

// GetProcessor is a Method that returns processor type and index
// based on the type of expression.
func GetProcessor(expr Expr, startIndex int) (Processor, int) {
switch expr := expr.(type) {
case *VarRef:
return newEchoProcessor(startIndex), startIndex + 1
case *Call:
return newEchoProcessor(startIndex), startIndex + 1
case *BinaryExpr:
return getBinaryProcessor(expr, startIndex)
case *ParenExpr:
return GetProcessor(expr.Expr, startIndex)
case *NumberLiteral:
return newLiteralProcessor(expr.Val), startIndex
case *StringLiteral:
return newLiteralProcessor(expr.Val), startIndex
case *BooleanLiteral:
return newLiteralProcessor(expr.Val), startIndex
case *TimeLiteral:
return newLiteralProcessor(expr.Val), startIndex
case *DurationLiteral:
return newLiteralProcessor(expr.Val), startIndex
}
panic("unreachable")
}

// Processor is a prcessor type returned by GetProcessor
type Processor func(values []interface{}) interface{}

func newEchoProcessor(index int) Processor {
return func(values []interface{}) interface{} {
if index > len(values)-1 {
return nil
}
return values[index]
}
}

func newLiteralProcessor(val interface{}) Processor {
return func(values []interface{}) interface{} {
return val
}
}

func getBinaryProcessor(expr *BinaryExpr, startIndex int) (Processor, int) {
lhs, index := GetProcessor(expr.LHS, startIndex)
rhs, index := GetProcessor(expr.RHS, index)

return newBinaryExprEvaluator(expr.Op, lhs, rhs), index
}

func newBinaryExprEvaluator(op Token, lhs, rhs Processor) Processor {
switch op {
case ADD:
return func(values []interface{}) interface{} {
l := lhs(values)
r := rhs(values)
if lf, rf, ok := processorValuesAsFloat64(l, r); ok {
return lf + rf
}
return nil
}
case SUB:
return func(values []interface{}) interface{} {
l := lhs(values)
r := rhs(values)
if lf, rf, ok := processorValuesAsFloat64(l, r); ok {
return lf - rf
}
return nil
}
case MUL:
return func(values []interface{}) interface{} {
l := lhs(values)
r := rhs(values)
if lf, rf, ok := processorValuesAsFloat64(l, r); ok {
return lf * rf
}
return nil
}
case DIV:
return func(values []interface{}) interface{} {
l := lhs(values)
r := rhs(values)
if lf, rf, ok := processorValuesAsFloat64(l, r); ok {
return lf / rf
}
return nil
}
default:
// we shouldn't get here, but give them back nils if it goes this way
return func(values []interface{}) interface{} {
return nil
}
}
}

func processorValuesAsFloat64(lhs interface{}, rhs interface{}) (float64, float64, bool) {
var lf float64
var rf float64
var ok bool

lf, ok = lhs.(float64)
if !ok {
var li int64
if li, ok = lhs.(int64); !ok {
return 0, 0, false
}
lf = float64(li)
}
rf, ok = rhs.(float64)
if !ok {
var ri int64
if ri, ok = rhs.(int64); !ok {
return 0, 0, false
}
rf = float64(ri)
}
return lf, rf, true
}