diff --git a/CHANGELOG.md b/CHANGELOG.md index 52020fe7bf..cefdc92652 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Bugfixes +- [Issue #557](https://github.com/influxdb/influxdb/issues/557). Group by time(1y) doesn't work while time(365d) works + ## v0.6.5 [2014-05-19] ### Features diff --git a/src/datastore/leveldb_shard.go b/src/datastore/leveldb_shard.go index dcd3e016cb..1bcbfe8105 100644 --- a/src/datastore/leveldb_shard.go +++ b/src/datastore/leveldb_shard.go @@ -175,8 +175,10 @@ func (self *LevelDbShard) executeQueryForSeries(querySpec *parser.QuerySpec, ser // because a db is distributed across the cluster, it's possible we don't have the series indexed here. ignore switch err := err.(type) { case FieldLookupError: + log.Debug("Cannot find fields %v", columns) return nil default: + log.Error("Error looking up fields for %s: %s", seriesName, err) return fmt.Errorf("Error looking up fields for %s: %s", seriesName, err) } } @@ -189,6 +191,7 @@ func (self *LevelDbShard) executeQueryForSeries(querySpec *parser.QuerySpec, ser if querySpec.IsSinglePointQuery() { series, err := self.fetchSinglePoint(querySpec, seriesName, fields) if err != nil { + log.Error("Error reading a single point: %s", err) return err } if len(series.Points) > 0 { @@ -275,6 +278,7 @@ func (self *LevelDbShard) executeQueryForSeries(querySpec *parser.QuerySpec, ser valueBuffer.SetBuf(rawColumnValues[i].value) err := valueBuffer.Unmarshal(fv) if err != nil { + log.Error("Error while running query: %s", err) return err } point.Values[i] = fv @@ -313,6 +317,7 @@ func (self *LevelDbShard) executeQueryForSeries(querySpec *parser.QuerySpec, ser Points: seriesOutgoing.Points, } if !processor.YieldSeries(series) { + log.Info("Stopping processing") shouldContinue = false } } @@ -333,6 +338,7 @@ func (self *LevelDbShard) executeQueryForSeries(querySpec *parser.QuerySpec, ser } } + log.Debug("Finished running query %s") return nil } diff --git a/src/integration/data_test.go b/src/integration/data_test.go index 6b4ba1070d..3027ba4fea 100644 --- a/src/integration/data_test.go +++ b/src/integration/data_test.go @@ -1921,3 +1921,21 @@ func (self *DataTestSuite) BottomWithMultipleGroupBy(c *C) (Fun, Fun) { c.Assert(tops, DeepEquals, []tmp{tmp{60, "hosta"}, tmp{70, "hosta"}, tmp{70, "hostb"}, tmp{80, "hostb"}}) } } + +// issue #557 +func (self *DataTestSuite) GroupByYear(c *C) (Fun, Fun) { + return func(client Client) { + data := `[{"points": [[4], [10], [5]], "name": "test_group_by_day", "columns": ["value"]}]` + client.WriteJsonData(data, c) + t := time.Now().Truncate(time.Hour).Add(-24 * 365 * time.Hour).Unix() + data = fmt.Sprintf(`[{"points": [[2, %d]], "name": "test_group_by_day", "columns": ["value", "time"]}]`, t) + client.WriteJsonData(data, c, "s") + }, func(client Client) { + collection := client.RunQuery("select count(value) from test_group_by_day group by time(1y)", c) + c.Assert(collection, HasLen, 1) + maps := ToMap(collection[0]) + c.Assert(maps, HasLen, 2) + c.Assert(maps[0]["count"], Equals, 3.0) + c.Assert(maps[1]["count"], Equals, 1.0) + } +} diff --git a/src/parser/group_by.go b/src/parser/group_by.go index 3154a4a280..2a847e37c6 100644 --- a/src/parser/group_by.go +++ b/src/parser/group_by.go @@ -4,7 +4,10 @@ import ( "bytes" "common" "fmt" + "strings" "time" + + log "code.google.com/p/log4go" ) type GroupByClause struct { @@ -15,13 +18,15 @@ type GroupByClause struct { func (self GroupByClause) GetGroupByTime() (*time.Duration, error) { for _, groupBy := range self.Elems { - if groupBy.IsFunctionCall() { + if groupBy.IsFunctionCall() && strings.ToLower(groupBy.Name) == "time" { // TODO: check the number of arguments and return an error if len(groupBy.Elems) != 1 { return nil, common.NewQueryError(common.WrongNumberOfArguments, "time function only accepts one argument") } - // TODO: check the function name - // TODO: error checking + + if groupBy.Elems[0].Type != ValueDuration { + log.Debug("Get a time function without a duration argument %s", groupBy.Elems[0].Type) + } arg := groupBy.Elems[0].Name durationInt, err := common.ParseTimeDuration(arg) if err != nil { diff --git a/src/parser/query.lex b/src/parser/query.lex index a2bf6bf2e7..509fcef0fc 100644 --- a/src/parser/query.lex +++ b/src/parser/query.lex @@ -92,7 +92,7 @@ static int yycolumn = 1; [0-9]+ { yylval->string = strdup(yytext); return INT_VALUE; } -([0-9]+|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)[usmhdw] { yylval->string = strdup(yytext); return DURATION; } +([0-9]+|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)[usmhdwy] { yylval->string = strdup(yytext); return DURATION; } [0-9]*\.[0-9]+|[0-9]+\.[0-9]* { yylval->string = strdup(yytext); return FLOAT_VALUE; }