From ca471f7d0f0040f0c327c8a77f3287579e3fa31a Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Wed, 14 Feb 2018 14:34:34 -0500 Subject: [PATCH] Fix regression when math between literals is used in a field --- query/compile.go | 9 ++++++--- query/compile_test.go | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/query/compile.go b/query/compile.go index 137d5829f50..8761632a986 100644 --- a/query/compile.go +++ b/query/compile.go @@ -195,12 +195,15 @@ func (c *compiledStatement) compileFields(stmt *influxql.SelectStatement) error // Append this field to the list of processed fields and compile it. field := &compiledField{ - global: c, - Field: f, + global: c, + Field: &influxql.Field{ + Expr: influxql.Reduce(f.Expr, nil), + Alias: f.Alias, + }, AllowWildcard: true, } c.Fields = append(c.Fields, field) - if err := field.compileExpr(f.Expr); err != nil { + if err := field.compileExpr(field.Field.Expr); err != nil { return err } } diff --git a/query/compile_test.go b/query/compile_test.go index fa4de435179..be622d96d1a 100644 --- a/query/compile_test.go +++ b/query/compile_test.go @@ -81,6 +81,7 @@ func TestCompile_Success(t *testing.T) { `SELECT value FROM cpu WHERE time >= '2000-01-01T00:00:00Z' AND time <= '2000-01-01T01:00:00Z'`, `SELECT value FROM (SELECT value FROM cpu) ORDER BY time DESC`, `SELECT count(distinct(value)), max(value) FROM cpu`, + `SELECT last(value) / (1 - 0) FROM cpu`, } { t.Run(tt, func(t *testing.T) { stmt, err := influxql.ParseStatement(tt)