Skip to content

Commit

Permalink
Merge pull request #9443 from influxdata/js-9273-reduce-field-express…
Browse files Browse the repository at this point in the history
…ions

Fix regression when math between literals is used in a field
  • Loading branch information
jsternberg committed Feb 14, 2018
2 parents b866943 + ca471f7 commit 4c76e5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions query/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
1 change: 1 addition & 0 deletions query/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4c76e5f

Please sign in to comment.