diff --git a/CHANGELOG.md b/CHANGELOG.md index bf457c61cf9..ee55559a145 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - [#3421](https://github.com/influxdb/influxdb/issues/3421): Should update metastore and cluster if IP or hostname changes - [#3502](https://github.com/influxdb/influxdb/pull/3502): Importer for 0.8.9 data via the CLI - [#3564](https://github.com/influxdb/influxdb/pull/3564): Fix alias, maintain column sort order +- [#3585](https://github.com/influxdb/influxdb/pull/3585): Additional test coverage for non-existent fields ### Bugfixes - [#3405](https://github.com/influxdb/influxdb/pull/3405): Prevent database panic when fields are missing. Thanks @jhorwit2 diff --git a/cmd/influxd/run/server_test.go b/cmd/influxd/run/server_test.go index 2bf6b9e9f08..979bd9e84e0 100644 --- a/cmd/influxd/run/server_test.go +++ b/cmd/influxd/run/server_test.go @@ -695,6 +695,51 @@ func TestServer_Query_IdenticalTagValues(t *testing.T) { } } +// Ensure the server can query a non-existent field +func TestServer_Query_NonExistent(t *testing.T) { + t.Parallel() + s := OpenServer(NewConfig(), "") + defer s.Close() + + if err := s.CreateDatabaseAndRetentionPolicy("db0", newRetentionPolicyInfo("rp0", 1, 1*time.Hour)); err != nil { + t.Fatal(err) + } + + now := now() + + test := NewTest("db0", "rp0") + test.write = `cpu,host=server01 value=1 ` + strconv.FormatInt(now.UnixNano(), 10) + + test.addQueries([]*Query{ + &Query{ + name: "selecting value should succeed", + command: `SELECT value FROM db0.rp0.cpu`, + exp: fmt.Sprintf(`{"results":[{"series":[{"name":"cpu","columns":["time","value"],"values":[["%s",1]]}]}]}`, now.Format(time.RFC3339Nano)), + }, + &Query{ + name: "selecting non-existent should succeed", + command: `SELECT foo FROM db0.rp0.cpu`, + exp: `{"results":[{}]}`, + }, + }...) + + 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()) + } + } +} + // Ensure the server can query with the count aggregate function func TestServer_Query_Count(t *testing.T) { t.Parallel() @@ -1067,6 +1112,11 @@ func TestServer_Query_Alias(t *testing.T) { command: `SELECT mean(value) as mv, max(value) as mv FROM db0.rp0.cpu`, exp: `{"results":[{"series":[{"name":"cpu","columns":["time","mv","mv"],"values":[["1970-01-01T00:00:00Z",1.5,2]]}]}]}`, }, + &Query{ + name: "double aggregate with non-existent field - SELECT mean(value), max(foo) FROM db0.rp0.cpu", + command: `SELECT mean(value), max(foo) FROM db0.rp0.cpu`, + exp: `{"results":[{"series":[{"name":"cpu","columns":["time","mean","max"],"values":[["1970-01-01T00:00:00Z",1.5,null]]}]}]}`, + }, }...) if err := test.init(s); err != nil {