fix #63. Aggregated results don't include seq number

pull/70/head
John Shahid 2013-11-18 11:22:20 -05:00
parent 0d079597f5
commit 5aaa117f47
6 changed files with 66 additions and 75 deletions

View File

@ -120,3 +120,4 @@
## Bugfixes ## Bugfixes
- [Issue #57](https://github.com/influxdb/influxdb/issues/57). Don't panic when type of time != float - [Issue #57](https://github.com/influxdb/influxdb/issues/57). Don't panic when type of time != float
- [Issue #63](https://github.com/influxdb/influxdb/issues/63). Aggregate queries should not have a sequence_number column

View File

@ -425,7 +425,15 @@ func serializeSeries(memSeries map[string]*protocol.Series, precision TimePrecis
serializedSeries := []*SerializedSeries{} serializedSeries := []*SerializedSeries{}
for _, series := range memSeries { for _, series := range memSeries {
columns := []string{"time", "sequence_number"} includeSequenceNumber := true
if len(series.Points) > 0 && series.Points[0].SequenceNumber == nil {
includeSequenceNumber = false
}
columns := []string{"time"}
if includeSequenceNumber {
columns = append(columns, "sequence_number")
}
for _, field := range series.Fields { for _, field := range series.Fields {
columns = append(columns, field) columns = append(columns, field)
} }
@ -441,7 +449,10 @@ func serializeSeries(memSeries map[string]*protocol.Series, precision TimePrecis
timestamp /= 1000 timestamp /= 1000
} }
rowValues := []interface{}{timestamp, *row.SequenceNumber} rowValues := []interface{}{timestamp}
if includeSequenceNumber {
rowValues = append(rowValues, *row.SequenceNumber)
}
for _, value := range row.Values { for _, value := range row.Values {
if value != nil { if value != nil {
rowValues = append(rowValues, value.GetValue()) rowValues = append(rowValues, value.GetValue())

View File

@ -187,9 +187,8 @@ func (self *DerivativeAggregator) AggregatePoint(series string, group interface{
} }
newValue := &protocol.Point{ newValue := &protocol.Point{
Timestamp: p.Timestamp, Timestamp: p.Timestamp,
SequenceNumber: p.SequenceNumber, Values: []*protocol.FieldValue{&protocol.FieldValue{DoubleValue: &value}},
Values: []*protocol.FieldValue{&protocol.FieldValue{DoubleValue: &value}},
} }
firstValues := self.firstValues[series] firstValues := self.firstValues[series]

View File

@ -298,7 +298,6 @@ func (self *QueryEngine) executeCountQueryWithGroupBy(user common.User, database
return err return err
} }
var sequenceNumber uint32 = 1
fields := []string{} fields := []string{}
for _, aggregator := range aggregators { for _, aggregator := range aggregators {
@ -342,8 +341,7 @@ func (self *QueryEngine) executeCountQueryWithGroupBy(user common.User, database
for _, v := range values { for _, v := range values {
/* groupPoints := []*protocol.Point{} */ /* groupPoints := []*protocol.Point{} */
point := &protocol.Point{ point := &protocol.Point{
SequenceNumber: &sequenceNumber, Values: v,
Values: v,
} }
point.SetTimestampInMicroseconds(timestamp) point.SetTimestampInMicroseconds(timestamp)

View File

@ -176,8 +176,7 @@ func (self *EngineSuite) TestCountQuery(c *C) {
"string_value": "some_value" "string_value": "some_value"
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
}, },
{ {
"values": [ "values": [
@ -185,8 +184,7 @@ func (self *EngineSuite) TestCountQuery(c *C) {
"string_value": "some_value" "string_value": "some_value"
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 2
} }
], ],
"name": "foo", "name": "foo",
@ -204,8 +202,7 @@ func (self *EngineSuite) TestCountQuery(c *C) {
"int64_value": 2 "int64_value": 2
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
} }
], ],
"name": "foo", "name": "foo",
@ -268,8 +265,7 @@ func (self *EngineSuite) TestFirstAndLastQuery(c *C) {
"int64_value": 3 "int64_value": 3
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
} }
], ],
"name": "foo", "name": "foo",
@ -320,8 +316,7 @@ func (self *EngineSuite) TestUpperCaseQuery(c *C) {
"int64_value": 2 "int64_value": 2
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
} }
], ],
"name": "foo", "name": "foo",
@ -378,8 +373,7 @@ func (self *EngineSuite) TestCountQueryWithRegexTables(c *C) {
"int64_value": 1 "int64_value": 1
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
} }
], ],
"name": "foo.bar", "name": "foo.bar",
@ -393,8 +387,7 @@ func (self *EngineSuite) TestCountQueryWithRegexTables(c *C) {
"int64_value": 1 "int64_value": 1
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
} }
], ],
"name": "foo.baz", "name": "foo.baz",
@ -448,8 +441,7 @@ func (self *EngineSuite) TestCountQueryWithGroupByClause(c *C) {
"string_value": "some_value" "string_value": "some_value"
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
}, },
{ {
"values": [ "values": [
@ -460,8 +452,7 @@ func (self *EngineSuite) TestCountQueryWithGroupByClause(c *C) {
"string_value": "another_value" "string_value": "another_value"
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
} }
], ],
"name": "foo", "name": "foo",
@ -532,8 +523,7 @@ func (self *EngineSuite) TestCountQueryWithGroupByClauseAndNullValues(c *C) {
"string_value": "some_value" "string_value": "some_value"
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
}, },
{ {
"values": [ "values": [
@ -544,8 +534,7 @@ func (self *EngineSuite) TestCountQueryWithGroupByClauseAndNullValues(c *C) {
"string_value": "another_value" "string_value": "another_value"
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
}, },
{ {
"values": [ "values": [
@ -554,8 +543,7 @@ func (self *EngineSuite) TestCountQueryWithGroupByClauseAndNullValues(c *C) {
}, },
null null
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
} }
], ],
"name": "foo", "name": "foo",
@ -650,8 +638,7 @@ func (self *EngineSuite) TestCountQueryWithGroupByClauseWithMultipleColumns(c *C
"int64_value": 1 "int64_value": 1
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
}, },
{ {
"values": [ "values": [
@ -665,8 +652,7 @@ func (self *EngineSuite) TestCountQueryWithGroupByClauseWithMultipleColumns(c *C
"int64_value": 2 "int64_value": 2
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
}, },
{ {
"values": [ "values": [
@ -680,8 +666,7 @@ func (self *EngineSuite) TestCountQueryWithGroupByClauseWithMultipleColumns(c *C
"int64_value": 1 "int64_value": 1
} }
], ],
"timestamp": 1381346631000000, "timestamp": 1381346631000000
"sequence_number": 1
} }
], ],
"name": "foo", "name": "foo",
@ -740,8 +725,7 @@ func (self *EngineSuite) TestCountQueryWithGroupByTime(c *C) {
"int64_value": 1 "int64_value": 1
} }
], ],
"timestamp": 1381346640000000, "timestamp": 1381346640000000
"sequence_number": 1
}, },
{ {
"values": [ "values": [
@ -749,8 +733,7 @@ func (self *EngineSuite) TestCountQueryWithGroupByTime(c *C) {
"int64_value": 2 "int64_value": 2
} }
], ],
"timestamp": 1381346700000000, "timestamp": 1381346700000000
"sequence_number": 1
} }
], ],
"name": "foo", "name": "foo",
@ -799,8 +782,7 @@ func (self *EngineSuite) TestCountQueryWithGroupByTimeDescendingOrder(c *C) {
"int64_value": 1 "int64_value": 1
} }
], ],
"timestamp": %d, "timestamp": %d
"sequence_number": 1
}%s }%s
`, endTime.Add(time.Duration(-i)*time.Second).Unix()*1000000, delimiter) `, endTime.Add(time.Duration(-i)*time.Second).Unix()*1000000, delimiter)
} }
@ -843,9 +825,9 @@ func (self *EngineSuite) TestCountQueryWithGroupByTimeAndColumn(c *C) {
runQuery(engine, "select count(column_one), column_one from foo group by time(1m), column_one order asc", c, `[ runQuery(engine, "select count(column_one), column_one from foo group by time(1m), column_one order asc", c, `[
{ {
"points": [ "points": [
{ "values": [{ "int64_value": 1 }, { "string_value": "some_value" }], "timestamp": 1381346640000000, "sequence_number": 1 }, { "values": [{ "int64_value": 1 }, { "string_value": "some_value" }], "timestamp": 1381346640000000 },
{ "values": [{ "int64_value": 1 }, { "string_value": "another_value" }], "timestamp": 1381346700000000, "sequence_number": 1 }, { "values": [{ "int64_value": 1 }, { "string_value": "another_value" }], "timestamp": 1381346700000000},
{ "values": [{ "int64_value": 1 }, { "string_value": "some_value" }], "timestamp": 1381346700000000, "sequence_number": 1 } { "values": [{ "int64_value": 1 }, { "string_value": "some_value" }], "timestamp": 1381346700000000 }
], ],
"name": "foo", "name": "foo",
"fields": ["count" , "column_one"] "fields": ["count" , "column_one"]
@ -869,8 +851,8 @@ func (self *EngineSuite) TestMinQueryWithGroupByTime(c *C) {
runQuery(engine, "select min(column_one) from foo group by time(1m) order asc", c, `[ runQuery(engine, "select min(column_one) from foo group by time(1m) order asc", c, `[
{ {
"points": [ "points": [
{ "values": [{ "double_value": 3 }], "timestamp": 1381346640000000, "sequence_number": 1 }, { "values": [{ "double_value": 3 }], "timestamp": 1381346640000000},
{ "values": [{ "double_value": 4 }], "timestamp": 1381346700000000, "sequence_number": 1 } { "values": [{ "double_value": 4 }], "timestamp": 1381346700000000}
], ],
"name": "foo", "name": "foo",
"fields": ["min"] "fields": ["min"]
@ -894,8 +876,8 @@ func (self *EngineSuite) TestMaxQueryWithGroupByTime(c *C) {
runQuery(engine, "select max(column_one) from foo group by time(1m) order asc", c, `[ runQuery(engine, "select max(column_one) from foo group by time(1m) order asc", c, `[
{ {
"points": [ "points": [
{ "values": [{ "double_value": 3 }], "timestamp": 1381346640000000, "sequence_number": 1 }, { "values": [{ "double_value": 3 }], "timestamp": 1381346640000000},
{ "values": [{ "double_value": 8 }], "timestamp": 1381346700000000, "sequence_number": 1 } { "values": [{ "double_value": 8 }], "timestamp": 1381346700000000}
], ],
"name": "foo", "name": "foo",
"fields": ["max"] "fields": ["max"]
@ -920,8 +902,8 @@ func (self *EngineSuite) TestMaxMinQueryWithGroupByTime(c *C) {
runQuery(engine, "select max(column_one), min(column_one) from foo group by time(1m) order asc", c, `[ runQuery(engine, "select max(column_one), min(column_one) from foo group by time(1m) order asc", c, `[
{ {
"points": [ "points": [
{ "values": [{ "double_value": 3 }, { "double_value": 3 }], "timestamp": 1381346640000000, "sequence_number": 1 }, { "values": [{ "double_value": 3 }, { "double_value": 3 }], "timestamp": 1381346640000000},
{ "values": [{ "double_value": 8 }, { "double_value": 4 }], "timestamp": 1381346700000000, "sequence_number": 1 } { "values": [{ "double_value": 8 }, { "double_value": 4 }], "timestamp": 1381346700000000}
], ],
"name": "foo", "name": "foo",
"fields": ["max", "min"] "fields": ["max", "min"]
@ -957,8 +939,8 @@ func (self *EngineSuite) TestPercentileQueryWithGroupByTime(c *C) {
runQuery(engine, "select percentile(column_one, 80) from foo group by time(1m) order asc", c, `[ runQuery(engine, "select percentile(column_one, 80) from foo group by time(1m) order asc", c, `[
{ {
"points": [ "points": [
{ "values": [{ "double_value": 6 }], "timestamp": 1381346700000000, "sequence_number": 1 }, { "values": [{ "double_value": 6 }], "timestamp": 1381346700000000},
{ "values": [{ "double_value": 8 }], "timestamp": 1381346760000000, "sequence_number": 1 } { "values": [{ "double_value": 8 }], "timestamp": 1381346760000000}
], ],
"name": "foo", "name": "foo",
"fields": ["percentile"] "fields": ["percentile"]
@ -994,7 +976,7 @@ func (self *EngineSuite) TestCountDistinct(c *C) {
runQuery(engine, "select count(distinct(column_one)) from foo order asc", c, `[ runQuery(engine, "select count(distinct(column_one)) from foo order asc", c, `[
{ {
"points": [ "points": [
{ "values": [{ "int64_value": 9 }], "timestamp": 1381346771000000, "sequence_number": 1 } { "values": [{ "int64_value": 9 }], "timestamp": 1381346771000000}
], ],
"name": "foo", "name": "foo",
"fields": ["count"] "fields": ["count"]
@ -1029,8 +1011,8 @@ func (self *EngineSuite) TestMedianQueryWithGroupByTime(c *C) {
runQuery(engine, "select median(column_one) from foo group by time(1m) order asc", c, `[ runQuery(engine, "select median(column_one) from foo group by time(1m) order asc", c, `[
{ {
"points": [ "points": [
{ "values": [{ "double_value": 4 }], "timestamp": 1381346700000000, "sequence_number": 1 }, { "values": [{ "double_value": 4 }], "timestamp": 1381346700000000},
{ "values": [{ "double_value": 6 }], "timestamp": 1381346760000000, "sequence_number": 1 } { "values": [{ "double_value": 6 }], "timestamp": 1381346760000000}
], ],
"name": "foo", "name": "foo",
"fields": ["median"] "fields": ["median"]
@ -1065,8 +1047,8 @@ func (self *EngineSuite) TestMeanQueryWithGroupByTime(c *C) {
runQuery(engine, "select mean(column_one) from foo group by time(1m) order asc", c, `[ runQuery(engine, "select mean(column_one) from foo group by time(1m) order asc", c, `[
{ {
"points": [ "points": [
{ "values": [{ "double_value": 4 }], "timestamp": 1381346700000000, "sequence_number": 1 }, { "values": [{ "double_value": 4 }], "timestamp": 1381346700000000},
{ "values": [{ "double_value": 6 }], "timestamp": 1381346760000000, "sequence_number": 1 } { "values": [{ "double_value": 6 }], "timestamp": 1381346760000000}
], ],
"name": "foo", "name": "foo",
"fields": ["mean"] "fields": ["mean"]
@ -1116,8 +1098,8 @@ func (self *EngineSuite) TestDerivativeQuery(c *C) {
runQuery(engine, "select derivative(column_one) from foo group by time(2s) order asc", c, `[ runQuery(engine, "select derivative(column_one) from foo group by time(2s) order asc", c, `[
{ {
"points": [ "points": [
{ "values": [{ "double_value": 1 } ], "timestamp": 1381347700000000, "sequence_number": 1 }, { "values": [{ "double_value": 1 } ], "timestamp": 1381347700000000},
{ "values": [{ "double_value": -2 }], "timestamp": 1381347702000000, "sequence_number": 1 } { "values": [{ "double_value": -2 }], "timestamp": 1381347702000000}
], ],
"name": "foo", "name": "foo",
"fields": ["derivative"] "fields": ["derivative"]
@ -1142,9 +1124,9 @@ func (self *EngineSuite) TestDistinctQuery(c *C) {
runQuery(engine, "select distinct(column_one) from foo order asc", c, `[ runQuery(engine, "select distinct(column_one) from foo order asc", c, `[
{ {
"points": [ "points": [
{ "values": [{ "double_value": 1 }], "timestamp": 1381347704000000, "sequence_number": 1 }, { "values": [{ "double_value": 1 }], "timestamp": 1381347704000000},
{ "values": [{ "double_value": 2 }], "timestamp": 1381347704000000, "sequence_number": 1 }, { "values": [{ "double_value": 2 }], "timestamp": 1381347704000000},
{ "values": [{ "double_value": 6 }], "timestamp": 1381347704000000, "sequence_number": 1 } { "values": [{ "double_value": 6 }], "timestamp": 1381347704000000}
], ],
"name": "foo", "name": "foo",
"fields": ["distinct"] "fields": ["distinct"]
@ -1171,8 +1153,8 @@ func (self *EngineSuite) TestSumQueryWithGroupByTime(c *C) {
runQuery(engine, "select sum(column_one) from foo group by time(1m) order asc", c, `[ runQuery(engine, "select sum(column_one) from foo group by time(1m) order asc", c, `[
{ {
"points": [ "points": [
{ "values": [{ "double_value": 11 }], "timestamp": 1381346700000000, "sequence_number": 1 }, { "values": [{ "double_value": 11 }], "timestamp": 1381346700000000},
{ "values": [{ "double_value": 16 }], "timestamp": 1381346760000000, "sequence_number": 1 } { "values": [{ "double_value": 16 }], "timestamp": 1381346760000000}
], ],
"name": "foo", "name": "foo",
"fields": ["sum"] "fields": ["sum"]
@ -1208,8 +1190,8 @@ func (self *EngineSuite) TestModeQueryWithGroupByTime(c *C) {
runQuery(engine, "select mode(column_one) from foo group by time(1m) order asc", c, `[ runQuery(engine, "select mode(column_one) from foo group by time(1m) order asc", c, `[
{ {
"points": [ "points": [
{ "values": [{ "double_value": 1 }], "timestamp": 1381346700000000, "sequence_number": 1 }, { "values": [{ "double_value": 1 }], "timestamp": 1381346700000000},
{ "values": [{ "double_value": 3 }], "timestamp": 1381346760000000, "sequence_number": 1 } { "values": [{ "double_value": 3 }], "timestamp": 1381346760000000}
], ],
"name": "foo", "name": "foo",
"fields": ["mode"] "fields": ["mode"]

View File

@ -236,10 +236,10 @@ func (self *IntegrationSuite) TestMedians(c *C) {
err = json.Unmarshal(bs, &data) err = json.Unmarshal(bs, &data)
c.Assert(data, HasLen, 1) c.Assert(data, HasLen, 1)
c.Assert(data[0].Name, Equals, "test_medians") c.Assert(data[0].Name, Equals, "test_medians")
c.Assert(data[0].Columns, HasLen, 4) c.Assert(data[0].Columns, HasLen, 3)
c.Assert(data[0].Points, HasLen, 2) c.Assert(data[0].Points, HasLen, 2)
c.Assert(data[0].Points[0][2], Equals, 80.0) c.Assert(data[0].Points[0][1], Equals, 80.0)
c.Assert(data[0].Points[1][2], Equals, 70.0) c.Assert(data[0].Points[1][1], Equals, 70.0)
} }
// issue #34 // issue #34
@ -325,11 +325,11 @@ func (self *IntegrationSuite) TestCountWithGroupBy(c *C) {
err = json.Unmarshal(bs, &data) err = json.Unmarshal(bs, &data)
c.Assert(data, HasLen, 1) c.Assert(data, HasLen, 1)
c.Assert(data[0].Name, Equals, "test_count") c.Assert(data[0].Name, Equals, "test_count")
c.Assert(data[0].Columns, HasLen, 4) c.Assert(data[0].Columns, HasLen, 3)
c.Assert(data[0].Points, HasLen, 2) c.Assert(data[0].Points, HasLen, 2)
// count should be 3 // count should be 3
c.Assert(data[0].Points[0][2], Equals, 5.0) c.Assert(data[0].Points[0][1], Equals, 5.0)
c.Assert(data[0].Points[1][2], Equals, 5.0) c.Assert(data[0].Points[1][1], Equals, 5.0)
} }
// test for issue #30 // test for issue #30