Skip to content

Commit

Permalink
fix #331. Allow negative time values
Browse files Browse the repository at this point in the history
  • Loading branch information
jvshahid committed Mar 28, 2014
1 parent 99f6dc7 commit 1567c69
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,14 @@ func (self *QueryParserSuite) TestErrorWithTimeSuffix(c *C) {
c.Assert(err, ErrorMatches, ".*1f.*")
}

// issue #331
func (self *QueryParserSuite) TestTimeWithNegativeEndTime(c *C) {
q := `SELECT * FROM foo where time < -1s`
query, err := ParseSelectQuery(q)
c.Assert(err, IsNil)
c.Assert(query.GetEndTime(), Equals, time.Unix(-1, 0).UTC())
}

func (self *QueryParserSuite) TestParseSelectWithTimeCondition(c *C) {
queries := map[string]time.Time{
"select value, time from t where time > now() - 1d and time < now() - 1m;": time.Now().Add(-time.Minute).Round(time.Minute).UTC(),
Expand Down
11 changes: 11 additions & 0 deletions src/parser/query.yacc
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,17 @@ VALUE:
$$->alias = NULL;
}
|
'-' DURATION_VALUE
{
char *name = calloc(1, strlen($2->name) + 2);
strcat(name, "-");
strcat(name, $2->name);
free($2->name);
$2->name = name;
$$ = $2;
$$->alias = NULL;
}
|
SIMPLE_NAME_VALUE
{
$$ = $1;
Expand Down
3 changes: 3 additions & 0 deletions src/parser/test_memory_leaks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ int main(int argc, char **argv) {
q = parse_query("explain select users.events group_by user_email,time(1h) where time>now()-1d;");
close_query(&q);
q = parse_query("select * from foo where time < -1s");
close_query(&q);
// test freeing on error
q = parse_query("select count(*) from users.events group_by user_email,time(1h) where time >> now()-1d;");
close_query(&q);
Expand Down

0 comments on commit 1567c69

Please sign in to comment.