Skip to content

Commit

Permalink
Merge pull request influxdata#7889 from influxdata/js-subquery-fixes
Browse files Browse the repository at this point in the history
Cherry-pick 1.2 fixes for subqueries into master
  • Loading branch information
pauldix authored Jan 26, 2017
2 parents 91ee34b + ce54856 commit a801c9d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v1.2.1 [unreleased]

### Bugfixes

- [#7877](https://github.com/influxdata/influxdb/issues/7877): Fix mapping of types when the measurement uses a regex
- [#7888](https://github.com/influxdata/influxdb/pull/7888): Expand query dimensions from the subquery.

## v1.2.0 [2017-01-24]

### Release Notes
Expand All @@ -6,7 +13,6 @@

The stress tool `influx_stress` will be removed in a subsequent release. We recommend using [`influx-stress`](https://github.com/influxdata/influx-stress) as a replacement.


### Features

- [#7723](https://github.com/influxdata/influxdb/pull/7723): Remove the override of GOMAXPROCS.
Expand Down
6 changes: 6 additions & 0 deletions cmd/influxd/run/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2959,6 +2959,12 @@ func TestServer_Query_Regex(t *testing.T) {
command: `SELECT * FROM db0../cpu[13]/ GROUP BY *`,
exp: `{"results":[{"statement_id":0,"series":[{"name":"cpu1","tags":{"host":"server01"},"columns":["time","value"],"values":[["2015-02-28T01:03:36.703820946Z",10]]},{"name":"cpu3","tags":{"host":"server01"},"columns":["time","value"],"values":[["2015-02-28T01:03:36.703820946Z",30]]}]}]}`,
},
&Query{
name: "map field type with a regex source",
command: `SELECT value FROM /cpu[13]/`,
params: url.Values{"db": []string{"db0"}},
exp: `{"results":[{"statement_id":0,"series":[{"name":"cpu1","columns":["time","value"],"values":[["2015-02-28T01:03:36.703820946Z",10]]},{"name":"cpu3","columns":["time","value"],"values":[["2015-02-28T01:03:36.703820946Z",30]]}]}]}`,
},
}...)

for i, query := range test.queries {
Expand Down
17 changes: 16 additions & 1 deletion coordinator/shard_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,22 @@ func (a *LocalShardMapping) MapType(m *influxql.Measurement, field string) influ
if sg == nil {
return influxql.Unknown
}
return sg.MapType(m.Name, field)

var names []string
if m.Regex != nil {
names = sg.MeasurementsByRegex(m.Regex.Val)
} else {
names = []string{m.Name}
}

var typ influxql.DataType
for _, name := range names {
t := sg.MapType(name, field)
if typ == influxql.Unknown || t < typ {
typ = t
}
}
return typ
}

func (a *LocalShardMapping) CreateIterator(m *influxql.Measurement, opt influxql.IteratorOptions) (influxql.Iterator, error) {
Expand Down
11 changes: 4 additions & 7 deletions influxql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -4508,13 +4508,10 @@ func FieldDimensions(sources Sources, m FieldMapper) (fields map[string]DataType
}
}

_, d, err := FieldDimensions(src.Statement.Sources, m)
if err != nil {
return nil, nil, err
}

for k := range d {
dimensions[k] = struct{}{}
for _, d := range src.Statement.Dimensions {
if expr, ok := d.Expr.(*VarRef); ok {
dimensions[expr.Val] = struct{}{}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion influxql/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func TestSelectStatement_RewriteFields(t *testing.T) {
// Rewrite subquery
{
stmt: `SELECT * FROM (SELECT mean(value1) FROM cpu GROUP BY host) GROUP BY *`,
rewrite: `SELECT mean::float FROM (SELECT mean(value1::float) FROM cpu GROUP BY host) GROUP BY host, region`,
rewrite: `SELECT mean::float FROM (SELECT mean(value1::float) FROM cpu GROUP BY host) GROUP BY host`,
},
}

Expand Down

0 comments on commit a801c9d

Please sign in to comment.