Merge pull request #9649 from influxdata/js-eval-functions-in-where

Allow math functions to be used in the condition
pull/9803/head
Jonathan A. Sternberg 2018-05-02 08:29:08 -05:00 committed by GitHub
commit 6607c29a02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 15 deletions

View File

@ -270,7 +270,13 @@ func (itr *floatIterator) Next() (*query.FloatPoint, error) {
}
// Evaluate condition, if one exists. Retry if it fails.
if itr.opt.Condition != nil && !influxql.EvalBool(itr.opt.Condition, itr.m) {
valuer := influxql.ValuerEval{
Valuer: influxql.MultiValuer(
query.MathValuer{},
influxql.MapValuer(itr.m),
),
}
if itr.opt.Condition != nil && !valuer.EvalBool(itr.opt.Condition) {
continue
}
@ -742,7 +748,13 @@ func (itr *integerIterator) Next() (*query.IntegerPoint, error) {
}
// Evaluate condition, if one exists. Retry if it fails.
if itr.opt.Condition != nil && !influxql.EvalBool(itr.opt.Condition, itr.m) {
valuer := influxql.ValuerEval{
Valuer: influxql.MultiValuer(
query.MathValuer{},
influxql.MapValuer(itr.m),
),
}
if itr.opt.Condition != nil && !valuer.EvalBool(itr.opt.Condition) {
continue
}
@ -1214,7 +1226,13 @@ func (itr *unsignedIterator) Next() (*query.UnsignedPoint, error) {
}
// Evaluate condition, if one exists. Retry if it fails.
if itr.opt.Condition != nil && !influxql.EvalBool(itr.opt.Condition, itr.m) {
valuer := influxql.ValuerEval{
Valuer: influxql.MultiValuer(
query.MathValuer{},
influxql.MapValuer(itr.m),
),
}
if itr.opt.Condition != nil && !valuer.EvalBool(itr.opt.Condition) {
continue
}
@ -1686,7 +1704,13 @@ func (itr *stringIterator) Next() (*query.StringPoint, error) {
}
// Evaluate condition, if one exists. Retry if it fails.
if itr.opt.Condition != nil && !influxql.EvalBool(itr.opt.Condition, itr.m) {
valuer := influxql.ValuerEval{
Valuer: influxql.MultiValuer(
query.MathValuer{},
influxql.MapValuer(itr.m),
),
}
if itr.opt.Condition != nil && !valuer.EvalBool(itr.opt.Condition) {
continue
}
@ -2158,7 +2182,13 @@ func (itr *booleanIterator) Next() (*query.BooleanPoint, error) {
}
// Evaluate condition, if one exists. Retry if it fails.
if itr.opt.Condition != nil && !influxql.EvalBool(itr.opt.Condition, itr.m) {
valuer := influxql.ValuerEval{
Valuer: influxql.MultiValuer(
query.MathValuer{},
influxql.MapValuer(itr.m),
),
}
if itr.opt.Condition != nil && !valuer.EvalBool(itr.opt.Condition) {
continue
}

View File

@ -268,7 +268,13 @@ func (itr *{{.name}}Iterator) Next() (*query.{{.Name}}Point, error) {
}
// Evaluate condition, if one exists. Retry if it fails.
if itr.opt.Condition != nil && !influxql.EvalBool(itr.opt.Condition, itr.m) {
valuer := influxql.ValuerEval{
Valuer: influxql.MultiValuer(
query.MathValuer{},
influxql.MapValuer(itr.m),
),
}
if itr.opt.Condition != nil && !valuer.EvalBool(itr.opt.Condition) {
continue
}

View File

@ -1851,7 +1851,13 @@ func (is IndexSet) seriesByBinaryExprIterator(name []byte, n *influxql.BinaryExp
if !ok {
key, ok = n.RHS.(*influxql.VarRef)
if !ok {
return nil, fmt.Errorf("invalid expression: %s", n.String())
// This is an expression we do not know how to evaluate. Let the
// query engine take care of this.
itr, err := is.measurementSeriesIDIterator(name)
if err != nil {
return nil, err
}
return newSeriesIDExprIterator(itr, n), nil
}
value = n.LHS
}
@ -1883,10 +1889,13 @@ func (is IndexSet) seriesByBinaryExprIterator(name []byte, n *influxql.BinaryExp
case *influxql.VarRef:
return is.seriesByBinaryExprVarRefIterator(name, []byte(key.Val), value, n.Op)
default:
if n.Op == influxql.NEQ || n.Op == influxql.NEQREGEX {
return is.measurementSeriesIDIterator(name)
// We do not know how to evaluate this expression so pass it
// on to the query engine.
itr, err := is.measurementSeriesIDIterator(name)
if err != nil {
return nil, err
}
return nil, nil
return newSeriesIDExprIterator(itr, n), nil
}
}

View File

@ -600,7 +600,9 @@ func (m *measurement) idsForExpr(n *influxql.BinaryExpr) (seriesIDs, influxql.Ex
if !ok {
name, ok = n.RHS.(*influxql.VarRef)
if !ok {
return nil, nil, fmt.Errorf("invalid expression: %s", n.String())
// This is an expression we do not know how to evaluate. Let the
// query engine take care of this.
return m.SeriesIDs(), n, nil
}
value = n.LHS
}
@ -742,10 +744,9 @@ func (m *measurement) idsForExpr(n *influxql.BinaryExpr) (seriesIDs, influxql.Ex
return ids, nil, nil
}
if n.Op == influxql.NEQ || n.Op == influxql.NEQREGEX {
return m.SeriesIDs(), nil, nil
}
return nil, nil, nil
// We do not know how to evaluate this expression so pass it
// on to the query engine.
return m.SeriesIDs(), n, nil
}
// FilterExprs represents a map of series IDs to filter expressions.