return an error if user attempts to group by field
parent
3fed8986db
commit
001cdefd7f
|
@ -13,6 +13,7 @@
|
|||
- [#2602](https://github.com/influxdb/influxdb/pull/2602): CLI execute command exits without cleaning up liner package.
|
||||
- [#2610](https://github.com/influxdb/influxdb/pull/2610): Fix shard group creation
|
||||
- [#2596](https://github.com/influxdb/influxdb/pull/2596): RC30: `panic: runtime error: index out of range` when insert data points.
|
||||
- [#2592](https://github.com/influxdb/influxdb/pull/2592): Should return an error if user attempts to group by a field.
|
||||
|
||||
## PRs
|
||||
- [#2569](https://github.com/influxdb/influxdb/pull/2569): Add derivative functions
|
||||
|
|
|
@ -529,6 +529,32 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent
|
|||
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","count"],"values":[["1970-01-01T00:00:01Z",10],["1970-01-01T00:00:02Z",10],["1970-01-01T00:00:03Z",10],["1970-01-01T00:00:04Z",10],["1970-01-01T00:00:05Z",7],["1970-01-01T00:00:06Z",3]]}]}]}`,
|
||||
},
|
||||
|
||||
// Test group by
|
||||
{
|
||||
reset: true,
|
||||
name: "GROUP by time",
|
||||
write: `{"database" : "%DB%", "retentionPolicy" : "%RP%", "points": [
|
||||
{"name": "cpu", "time": "2000-01-01T00:00:00Z", "tags": {"host": "server01"}, "fields": {"value": 10}},
|
||||
{"name": "cpu", "time": "2000-01-01T01:00:00Z", "tags": {"host": "server02"}, "fields": {"value": 10}},
|
||||
{"name": "cpu", "time": "2000-01-01T02:00:00Z", "tags": {"host": "server03"}, "fields": {"value": 10}}
|
||||
]}`,
|
||||
query: `SELECT count(value) FROM cpu where time >= '2000-01-01T00:00:00Z' and time <= '2000-01-01T02:00:00Z' group by time(1h)`,
|
||||
queryDb: "%DB%",
|
||||
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","count"],"values":[["2000-01-01T00:00:00Z",1],["2000-01-01T01:00:00Z",1],["2000-01-01T02:00:00Z",1]]}]}]}`,
|
||||
},
|
||||
{
|
||||
name: "GROUP by tag",
|
||||
query: `SELECT count(value) FROM cpu where time >= '2000-01-01T00:00:00Z' and time <= '2000-01-01T02:00:00Z' group by host`,
|
||||
queryDb: "%DB%",
|
||||
expected: `{"results":[{"series":[{"name":"cpu","tags":{"host":"server01"},"columns":["time","count"],"values":[["2000-01-01T00:00:00Z",1]]},{"name":"cpu","tags":{"host":"server02"},"columns":["time","count"],"values":[["2000-01-01T00:00:00Z",1]]},{"name":"cpu","tags":{"host":"server03"},"columns":["time","count"],"values":[["2000-01-01T00:00:00Z",1]]}]}]}`,
|
||||
},
|
||||
{
|
||||
name: "GROUP by field",
|
||||
query: `SELECT count(value) FROM cpu where time >= '2000-01-01T00:00:00Z' and time <= '2000-01-01T02:00:00Z' group by value`,
|
||||
queryDb: "%DB%",
|
||||
expected: `{"results":[{"error":"can not use field in group by clause: value"}]}`,
|
||||
},
|
||||
|
||||
// Limit and offset
|
||||
{
|
||||
reset: true,
|
||||
|
|
10
tx.go
10
tx.go
|
@ -93,6 +93,16 @@ func (tx *tx) CreateMapReduceJobs(stmt *influxql.SelectStatement, tagKeys []stri
|
|||
}
|
||||
}
|
||||
|
||||
// Validate that group by is not a field
|
||||
for _, d := range stmt.Dimensions {
|
||||
switch e := d.Expr.(type) {
|
||||
case *influxql.VarRef:
|
||||
if !m.HasTagKey(e.Val) {
|
||||
return nil, fmt.Errorf("can not use field in group by clause: %s", e.Val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
validateType := func(aname, fname string, t influxql.DataType) error {
|
||||
if t != influxql.Float && t != influxql.Integer {
|
||||
return fmt.Errorf("aggregate '%s' requires numerical field values. Field '%s' is of type %s",
|
||||
|
|
Loading…
Reference in New Issue