Fix #557. Using group by time(1y) doesn't work while time(365d) is fine
parent
a64ee2ae1a
commit
b6a5a10912
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue