From 65b6b1dbb097dc12a8b314ffef3e4c7293f51791 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Wed, 17 Apr 2019 15:59:10 -0500 Subject: [PATCH] Use the timezone when evaluating time literals in subqueries --- query/iterator.go | 3 ++- query/subquery_test.go | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/query/iterator.go b/query/iterator.go index 2e7631a966..6d02a95fa1 100644 --- a/query/iterator.go +++ b/query/iterator.go @@ -714,7 +714,8 @@ func newIteratorOptionsSubstatement(ctx context.Context, stmt *influxql.SelectSt subOpt.InterruptCh = opt.InterruptCh // Extract the time range and condition from the condition. - cond, t, err := influxql.ConditionExpr(stmt.Condition, nil) + valuer := &influxql.NowValuer{Location: stmt.Location} + cond, t, err := influxql.ConditionExpr(stmt.Condition, valuer) if err != nil { return IteratorOptions{}, err } diff --git a/query/subquery_test.go b/query/subquery_test.go index 32f0a12335..6b02873afe 100644 --- a/query/subquery_test.go +++ b/query/subquery_test.go @@ -3,6 +3,7 @@ package query_test import ( "context" "testing" + "time" "github.com/google/go-cmp/cmp" "github.com/influxdata/influxdb/models" @@ -272,6 +273,22 @@ func TestSubquery(t *testing.T) { {Time: 30 * Second, Series: query.Series{Name: "cpu"}, Values: []interface{}{float64(8)}}, }, }, + { + Name: "TimeZone", + Statement: `SELECT * FROM (SELECT * FROM cpu WHERE time >= '2019-04-17 09:00:00' and time < '2019-04-17 10:00:00' TZ('America/Chicago'))`, + Fields: map[string]influxql.DataType{"value": influxql.Float}, + MapShardsFn: func(t *testing.T, tr influxql.TimeRange) CreateIteratorFn { + return func(ctx context.Context, m *influxql.Measurement, opt query.IteratorOptions) query.Iterator { + if got, want := time.Unix(0, opt.StartTime).UTC(), mustParseTime("2019-04-17T14:00:00Z"); !got.Equal(want) { + t.Errorf("unexpected min time: got=%q want=%q", got, want) + } + if got, want := time.Unix(0, opt.EndTime).UTC(), mustParseTime("2019-04-17T15:00:00Z").Add(-1); !got.Equal(want) { + t.Errorf("unexpected max time: got=%q want=%q", got, want) + } + return &FloatIterator{} + } + }, + }, } { t.Run(test.Name, func(t *testing.T) { shardMapper := ShardMapper{