fix panic in query execution

pull/7924/head
Cory LaNou 2017-01-31 13:59:26 -06:00
parent ae8a553b7c
commit e3e319a176
3 changed files with 164 additions and 17 deletions

View File

@ -7356,3 +7356,48 @@ func TestServer_Query_Sample_Wildcard(t *testing.T) {
}
}
}
// Validate that nested aggregates don't panic
func TestServer_NestedAggregateWithMathPanics(t *testing.T) {
t.Parallel()
s := OpenServer(NewConfig())
defer s.Close()
if err := s.CreateDatabaseAndRetentionPolicy("db0", newRetentionPolicySpec("rp0", 1, 0), true); err != nil {
t.Fatal(err)
}
writes := []string{
`cpu value=2 0`,
}
test := NewTest("db0", "rp0")
test.writes = Writes{
&Write{data: strings.Join(writes, "\n")},
}
test.addQueries([]*Query{
&Query{
name: "dividing by elapsed count should not panic",
params: url.Values{"db": []string{"db0"}},
command: `SELECT sum(value) / elapsed(sum(value), 1m) FROM cpu WHERE time >= 0 AND time < 10m GROUP BY time(1m)`,
exp: `{"results":[{"statement_id":0,"series":[{"name":"cpu","columns":["time","sum_elapsed"],"values":[["1970-01-01T00:00:00Z",null],["1970-01-01T00:01:00Z",null],["1970-01-01T00:02:00Z",null],["1970-01-01T00:03:00Z",null],["1970-01-01T00:04:00Z",null],["1970-01-01T00:05:00Z",null],["1970-01-01T00:06:00Z",null],["1970-01-01T00:07:00Z",null],["1970-01-01T00:08:00Z",null],["1970-01-01T00:09:00Z",null]]}]}]}`,
},
}...)
if err := test.init(s); err != nil {
t.Fatalf("test init failed: %s", err)
}
for _, query := range test.queries {
if query.skip {
t.Logf("SKIP:: %s", query.name)
continue
}
if err := query.Execute(s); err != nil {
t.Error(query.Error(err))
} else if !query.success() {
t.Error(query.failureMessage())
}
}
}

View File

@ -1287,7 +1287,13 @@ func (itr *floatExprIterator) Next() (*FloatPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p FloatPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -1621,7 +1627,13 @@ func (itr *floatIntegerExprIterator) Next() (*IntegerPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p FloatPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -1959,7 +1971,13 @@ func (itr *floatStringExprIterator) Next() (*StringPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p FloatPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -2297,7 +2315,13 @@ func (itr *floatBooleanExprIterator) Next() (*BooleanPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p FloatPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -3803,7 +3827,13 @@ func (itr *integerFloatExprIterator) Next() (*FloatPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p IntegerPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -4141,7 +4171,13 @@ func (itr *integerExprIterator) Next() (*IntegerPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p IntegerPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -4475,7 +4511,13 @@ func (itr *integerStringExprIterator) Next() (*StringPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p IntegerPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -4813,7 +4855,13 @@ func (itr *integerBooleanExprIterator) Next() (*BooleanPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p IntegerPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -6304,7 +6352,13 @@ func (itr *stringFloatExprIterator) Next() (*FloatPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p StringPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -6642,7 +6696,13 @@ func (itr *stringIntegerExprIterator) Next() (*IntegerPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p StringPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -6980,7 +7040,13 @@ func (itr *stringExprIterator) Next() (*StringPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p StringPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -7314,7 +7380,13 @@ func (itr *stringBooleanExprIterator) Next() (*BooleanPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p StringPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -8805,7 +8877,13 @@ func (itr *booleanFloatExprIterator) Next() (*FloatPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p BooleanPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -9143,7 +9221,13 @@ func (itr *booleanIntegerExprIterator) Next() (*IntegerPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p BooleanPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -9481,7 +9565,13 @@ func (itr *booleanStringExprIterator) Next() (*StringPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p BooleanPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p
@ -9819,7 +9909,13 @@ func (itr *booleanExprIterator) Next() (*BooleanPoint, error) {
if itr.points == nil {
continue
}
p := *b
var p BooleanPoint
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p

View File

@ -1288,7 +1288,13 @@ func (itr *{{$k.name}}{{if ne $k.Name $v.Name}}{{$v.Name}}{{end}}ExprIterator) N
if itr.points == nil {
continue
}
p := *b
var p {{$k.Name}}Point
if b != nil {
p = *b
} else {
p = *a
}
p.Value = itr.points[0].Value
p.Nil = itr.points[0].Nil
a = &p