From ff62ab442319cc8257ae65531c15a14181c65995 Mon Sep 17 00:00:00 2001 From: John Shahid Date: Sat, 26 Oct 2013 12:21:17 -0400 Subject: [PATCH] don't blow up on nil values. --- src/api/http/api.go | 6 +++++- src/api/http/api_test.go | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/api/http/api.go b/src/api/http/api.go index e279fb94aa..3723ad692f 100644 --- a/src/api/http/api.go +++ b/src/api/http/api.go @@ -427,7 +427,11 @@ func serializeSeries(memSeries map[string]*protocol.Series, precision TimePrecis rowValues := []interface{}{timestamp, *row.SequenceNumber} for _, value := range row.Values { - rowValues = append(rowValues, value.GetValue()) + if value != nil { + rowValues = append(rowValues, value.GetValue()) + } else { + rowValues = append(rowValues, nil) + } } points = append(points, rowValues) } diff --git a/src/api/http/api_test.go b/src/api/http/api_test.go index ea6ca277ca..8aa4170f65 100644 --- a/src/api/http/api_test.go +++ b/src/api/http/api_test.go @@ -39,7 +39,7 @@ func (self *MockEngine) RunQuery(_ common.User, _ string, query string, yield fu "points": [ { "values": [ - { "string_value": "some_value"},{"int64_value": 1} + { "string_value": "some_value"},null ], "timestamp": 1381346631000000, "sequence_number": 1 @@ -146,6 +146,28 @@ func (self *ApiSuite) SetUpTest(c *C) { self.manager.ops = nil } +func (self *ApiSuite) TestQueryWithNullColumns(c *C) { + query := "select * from foo;" + query = url.QueryEscape(query) + addr := self.formatUrl("/db/foo/series?q=%s&time_precision=s&u=dbuser&p=password", query) + resp, err := libhttp.Get(addr) + c.Assert(err, IsNil) + defer resp.Body.Close() + c.Assert(resp.StatusCode, Equals, libhttp.StatusOK) + data, err := ioutil.ReadAll(resp.Body) + c.Assert(err, IsNil) + series := []SerializedSeries{} + err = json.Unmarshal(data, &series) + c.Assert(err, IsNil) + c.Assert(series, HasLen, 1) + c.Assert(series[0].Name, Equals, "foo") + // time, seq, column_one, column_two + c.Assert(series[0].Columns, HasLen, 4) + c.Assert(series[0].Points, HasLen, 4) + c.Assert(int(series[0].Points[0][0].(float64)), Equals, 1381346631) + c.Assert(series[0].Points[0][3], Equals, nil) +} + func (self *ApiSuite) TestQueryWithSecondsPrecision(c *C) { query := "select * from foo where column_one == 'some_value';" query = url.QueryEscape(query)