Skip to content

Commit

Permalink
Change default time boundaries for raw queries
Browse files Browse the repository at this point in the history
Changes the default time boundaries for raw queries so raw queries will
range until the end of time. Aggregate queries continue to have their
default end time be `now()`.
  • Loading branch information
jsternberg committed Oct 25, 2016
1 parent 17eb8cb commit f1fbb55
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The following configuration changes in the `[data]` section may need to changed
- [#7320](https://github.com/influxdata/influxdb/issues/7320): Update defaults in config for latest best practices
- [#7495](https://github.com/influxdata/influxdb/pull/7495): Rewrite regexes of the form host = /^server-a$/ to host = 'server-a', to take advantage of the tsdb index.
- [#6704](https://github.com/influxdata/influxdb/issues/6704): Optimize first/last when no group by interval is present.
- [#4461](https://github.com/influxdata/influxdb/issues/4461): Change default time boundaries for raw queries.

### Bugfixes

Expand Down
57 changes: 57 additions & 0 deletions cmd/influxd/run/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6981,3 +6981,60 @@ func TestServer_WhereTimeInclusive(t *testing.T) {
}
}
}

func TestServer_Query_ImplicitEndTime(t *testing.T) {
t.Parallel()
s := OpenServer(NewConfig())
defer s.Close()

if err := s.CreateDatabaseAndRetentionPolicy("db0", newRetentionPolicySpec("rp0", 1, 0)); err != nil {
t.Fatal(err)
}
if err := s.MetaClient.SetDefaultRetentionPolicy("db0", "rp0"); err != nil {
t.Fatal(err)
}

now := time.Now().UTC().Truncate(time.Second)
past := now.Add(-10 * time.Second)
future := now.Add(10 * time.Minute)
writes := []string{
fmt.Sprintf(`cpu value=1 %d`, past.UnixNano()),
fmt.Sprintf(`cpu value=2 %d`, future.UnixNano()),
}

test := NewTest("db0", "rp0")
test.writes = Writes{
&Write{data: strings.Join(writes, "\n")},
}

test.addQueries([]*Query{
&Query{
name: "raw query",
params: url.Values{"db": []string{"db0"}},
command: `SELECT * FROM cpu`,
exp: fmt.Sprintf(`{"results":[{"series":[{"name":"cpu","columns":["time","value"],"values":[["%s",1],["%s",2]]}]}]}`, past.Format(time.RFC3339Nano), future.Format(time.RFC3339Nano)),
},
&Query{
name: "aggregate query",
params: url.Values{"db": []string{"db0"}},
command: `SELECT mean(value) FROM cpu WHERE time > now() - 1m GROUP BY time(1m) FILL(none)`,
exp: fmt.Sprintf(`{"results":[{"series":[{"name":"cpu","columns":["time","mean"],"values":[["%s",1]]}]}]}`, now.Truncate(time.Minute).Format(time.RFC3339Nano)),
},
}...)

if err := test.init(s); err != nil {
t.Fatalf("test init failed: %s", err)
}

for _, query := range test.queries {
if query.skip {
t.Logf("SKIP:: %s", query.name)
continue
}
if err := query.Execute(s); err != nil {
t.Error(query.Error(err))
} else if !query.success() {
t.Error(query.failureMessage())
}
}
}
8 changes: 7 additions & 1 deletion coordinator/statement_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,13 @@ func (e *StatementExecutor) createIterators(stmt *influxql.SelectStatement, ctx
if influxql.Sources(stmt.Sources).HasSystemSource() {
opt.MaxTime = time.Unix(0, influxql.MaxTime).UTC()
} else {
opt.MaxTime = now
if interval, err := stmt.GroupByInterval(); err != nil {
return nil, stmt, err
} else if interval > 0 {
opt.MaxTime = now
} else {
opt.MaxTime = time.Unix(0, influxql.MaxTime).UTC()
}
}
}
if opt.MinTime.IsZero() {
Expand Down

0 comments on commit f1fbb55

Please sign in to comment.