fix #102. Support expressions in where condition
parent
a1f3ce295d
commit
8f9337611b
|
@ -149,6 +149,7 @@
|
|||
- [Issue #88](https://github.com/influxdb/influxdb/issues/88). Support datetime strings
|
||||
- [Issue #64](https://github.com/influxdb/influxdb/issues/64). Shard writes and queries across cluster with replay for briefly downed nodes (< 24 hrs)
|
||||
- [Issue #78](https://github.com/influxdb/influxdb/issues/78). Sequence numbers persist across restarts so they're not reused
|
||||
- [Issue #102](https://github.com/influxdb/influxdb/issues/102). Support expressions in where condition
|
||||
|
||||
## Bugfixes
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package engine
|
||||
package datastore
|
||||
|
||||
import (
|
||||
"common"
|
||||
|
@ -20,7 +20,7 @@ func init() {
|
|||
registeredArithmeticOperator["/"] = DivideOperator
|
||||
}
|
||||
|
||||
func getValue(value *parser.Value, fields []string, point *protocol.Point) (*protocol.FieldValue, error) {
|
||||
func GetValue(value *parser.Value, fields []string, point *protocol.Point) (*protocol.FieldValue, error) {
|
||||
switch value.Type {
|
||||
case parser.ValueSimpleName:
|
||||
for idx, f := range fields {
|
||||
|
@ -44,11 +44,11 @@ func getValue(value *parser.Value, fields []string, point *protocol.Point) (*pro
|
|||
}
|
||||
|
||||
func PlusOperator(elems []*parser.Value, fields []string, point *protocol.Point) (*protocol.FieldValue, error) {
|
||||
leftValue, err := getValue(elems[0], fields, point)
|
||||
leftValue, err := GetValue(elems[0], fields, point)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rightValues, err := getValue(elems[1], fields, point)
|
||||
rightValues, err := GetValue(elems[1], fields, point)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -65,11 +65,11 @@ func PlusOperator(elems []*parser.Value, fields []string, point *protocol.Point)
|
|||
}
|
||||
|
||||
func MinusOperator(elems []*parser.Value, fields []string, point *protocol.Point) (*protocol.FieldValue, error) {
|
||||
leftValue, err := getValue(elems[0], fields, point)
|
||||
leftValue, err := GetValue(elems[0], fields, point)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rightValues, err := getValue(elems[1], fields, point)
|
||||
rightValues, err := GetValue(elems[1], fields, point)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -86,11 +86,11 @@ func MinusOperator(elems []*parser.Value, fields []string, point *protocol.Point
|
|||
}
|
||||
|
||||
func MultiplyOperator(elems []*parser.Value, fields []string, point *protocol.Point) (*protocol.FieldValue, error) {
|
||||
leftValue, err := getValue(elems[0], fields, point)
|
||||
leftValue, err := GetValue(elems[0], fields, point)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rightValues, err := getValue(elems[1], fields, point)
|
||||
rightValues, err := GetValue(elems[1], fields, point)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -107,11 +107,11 @@ func MultiplyOperator(elems []*parser.Value, fields []string, point *protocol.Po
|
|||
}
|
||||
|
||||
func DivideOperator(elems []*parser.Value, fields []string, point *protocol.Point) (*protocol.FieldValue, error) {
|
||||
leftValue, err := getValue(elems[0], fields, point)
|
||||
leftValue, err := GetValue(elems[0], fields, point)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rightValues, err := getValue(elems[1], fields, point)
|
||||
rightValues, err := GetValue(elems[1], fields, point)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
|
@ -38,6 +38,12 @@ func getExpressionValue(values []*parser.Value, fields []string, point *protocol
|
|||
}
|
||||
|
||||
fieldValues = append(fieldValues, point.Values[fieldIdx])
|
||||
case parser.ValueExpression:
|
||||
v, err := GetValue(value, fields, point)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fieldValues = append(fieldValues, v)
|
||||
default:
|
||||
return nil, fmt.Errorf("Cannot evaluate expression")
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package engine
|
|||
import (
|
||||
"common"
|
||||
"coordinator"
|
||||
"datastore"
|
||||
"fmt"
|
||||
"os"
|
||||
"parser"
|
||||
|
@ -438,7 +439,7 @@ func (self *QueryEngine) executeArithmeticQuery(user common.User, database strin
|
|||
}
|
||||
for _, field := range newSeries.Fields {
|
||||
value := names[field]
|
||||
v, err := getValue(value, series.Fields, point)
|
||||
v, err := datastore.GetValue(value, series.Fields, point)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -637,6 +637,29 @@ func (self *IntegrationSuite) TestIssue105(c *C) {
|
|||
c.Assert(data[0].Points[0][3], Equals, 1.0)
|
||||
}
|
||||
|
||||
func (self *IntegrationSuite) TestWhereConditionWithExpression(c *C) {
|
||||
err := self.server.WriteData(`
|
||||
[
|
||||
{
|
||||
"name": "test_issue_105",
|
||||
"columns": ["time", "a", "b"],
|
||||
"points":[
|
||||
[1386262529794, 2, 1],
|
||||
[1386262529794, 2, 0]
|
||||
]
|
||||
}
|
||||
]`, "time_precision=m")
|
||||
c.Assert(err, IsNil)
|
||||
bs, err := self.server.RunQuery("select a, b from test_issue_105 where a + b >= 3")
|
||||
c.Assert(err, IsNil)
|
||||
data := []*h.SerializedSeries{}
|
||||
err = json.Unmarshal(bs, &data)
|
||||
c.Assert(data, HasLen, 1)
|
||||
c.Assert(data[0].Columns, HasLen, 4)
|
||||
c.Assert(data[0].Points, HasLen, 1)
|
||||
c.Assert(data[0].Points[0][3], Equals, 1.0)
|
||||
}
|
||||
|
||||
// test for issue #41
|
||||
func (self *IntegrationSuite) TestDbDelete(c *C) {
|
||||
err := self.server.WriteData(`
|
||||
|
|
Loading…
Reference in New Issue