From bd79d70f501dfb7e7751d9dfcbea304f193c6c79 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Sun, 21 Dec 2014 11:07:14 -0700 Subject: [PATCH] Add absolute time support. This commit adds the ability to specify time by duration since epoch. Example: SELECT * FROM cpu WHERE time > 1388534400s --- influxql/ast.go | 5 ++++- influxql/ast_test.go | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/influxql/ast.go b/influxql/ast.go index b0f2efc721..fee0ccdf29 100644 --- a/influxql/ast.go +++ b/influxql/ast.go @@ -1127,8 +1127,11 @@ func TimeRange(expr Expr) (min, max time.Time) { // Returns zero time if the expression is not a time expression. func timeExprValue(ref Expr, lit Expr) time.Time { if ref, ok := ref.(*VarRef); ok && strings.ToLower(ref.Val) == "time" { - if lit, ok := lit.(*TimeLiteral); ok { + switch lit := lit.(type) { + case *TimeLiteral: return lit.Val + case *DurationLiteral: + return time.Unix(0, int64(lit.Val)).UTC() } } return time.Time{} diff --git a/influxql/ast_test.go b/influxql/ast_test.go index d12afce621..9b4bd7b000 100644 --- a/influxql/ast_test.go +++ b/influxql/ast_test.go @@ -188,6 +188,9 @@ func TestTimeRange(t *testing.T) { // Min/max crossover {expr: `time >= "2000-01-01 00:00:00" AND time <= "1999-01-01 00:00:00"`, min: `2000-01-01 00:00:00`, max: `1999-01-01 00:00:00`}, + // Absolute time + {expr: `time = 1388534400s`, min: `2014-01-01 00:00:00`, max: `2014-01-01 00:00:00`}, + // Non-comparative expressions. {expr: `time`, min: `0001-01-01 00:00:00`, max: `0001-01-01 00:00:00`}, {expr: `time + 2`, min: `0001-01-01 00:00:00`, max: `0001-01-01 00:00:00`},