pvt #59002514. default start and end time set properly.

Start time defaults to 1 hour before end time if it wasn't specified
in the query.  End time defaults to the current time. If neither start
or end time are given, the query defaults to all points between an
hour ago and current time.
pull/17/head
John Shahid 2013-10-18 11:07:44 -04:00
parent c161c494aa
commit 9adf374d1d
2 changed files with 38 additions and 8 deletions

View File

@ -321,14 +321,6 @@ func ParseQuery(query string) (*Query, error) {
}
var startTime, endTime time.Time
goQuery.Condition, startTime, err = getTime(goQuery.GetWhereCondition(), true)
if err != nil {
return nil, err
}
if startTime.Unix() > 0 {
goQuery.startTime = startTime
}
goQuery.Condition, endTime, err = getTime(goQuery.GetWhereCondition(), false)
if err != nil {
@ -338,5 +330,17 @@ func ParseQuery(query string) (*Query, error) {
if endTime.Unix() > 0 {
goQuery.endTime = endTime
}
goQuery.Condition, startTime, err = getTime(goQuery.GetWhereCondition(), true)
if err != nil {
return nil, err
}
if startTime.Unix() > 0 {
goQuery.startTime = startTime
} else if endTime.Unix() > 0 {
goQuery.startTime = endTime.Add(-1 * time.Hour)
}
return goQuery, nil
}

View File

@ -100,6 +100,32 @@ func (self *QueryApiSuite) TestGetReferencedColumnsReturnsGroupByColumn(c *C) {
}
}
func (self *QueryApiSuite) TestDefaultStartTime(c *C) {
for queryStr, t := range map[string]time.Time{
"select * from t where time < now() - 1d;": time.Now().Add(-24 * time.Hour).Add(-1 * time.Hour).Round(time.Minute),
"select * from t;": time.Now().Add(-1 * time.Hour).Round(time.Minute),
} {
query, err := ParseQuery(queryStr)
c.Assert(err, IsNil)
startTime := query.GetStartTime()
roundedStartTime := startTime.Round(time.Minute)
c.Assert(roundedStartTime, Equals, t)
}
}
func (self *QueryApiSuite) TestDefaultEndTime(c *C) {
for queryStr, t := range map[string]time.Time{
"select * from t where time > now() - 1d;": time.Now().Round(time.Minute),
"select * from t;": time.Now().Round(time.Minute),
} {
query, err := ParseQuery(queryStr)
c.Assert(err, IsNil)
endTime := query.GetEndTime()
roundedEndTime := endTime.Round(time.Minute)
c.Assert(roundedEndTime, Equals, t)
}
}
func (self *QueryApiSuite) TestGetStartTimeWithOr(c *C) {
for _, queryStr := range []string{
"select * from t where time > now() - 1d and (value > 90 or value < 10);",