diff --git a/coordinator/statement_executor.go b/coordinator/statement_executor.go index a5ec146c95..a2c534fd36 100644 --- a/coordinator/statement_executor.go +++ b/coordinator/statement_executor.go @@ -1090,7 +1090,13 @@ func (e *StatementExecutor) NormalizeStatement(stmt influxql.Statement, defaultD node.Database = defaultDatabase } case *influxql.Measurement: - err = e.normalizeMeasurement(node, defaultDatabase) + switch stmt.(type) { + case *influxql.DropSeriesStatement, *influxql.DeleteSeriesStatement: + // DB and RP not supported by these statements so don't rewrite into invalid + // statements + default: + err = e.normalizeMeasurement(node, defaultDatabase) + } } }) return diff --git a/coordinator/statement_executor_test.go b/coordinator/statement_executor_test.go index 67f42cbda6..824abac256 100644 --- a/coordinator/statement_executor_test.go +++ b/coordinator/statement_executor_test.go @@ -13,6 +13,7 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/influxdata/influxdb/coordinator" "github.com/influxdata/influxdb/influxql" + "github.com/influxdata/influxdb/internal" "github.com/influxdata/influxdb/models" "github.com/influxdata/influxdb/services/meta" "github.com/influxdata/influxdb/tsdb" @@ -107,6 +108,72 @@ func TestQueryExecutor_ExecuteQuery_MaxSelectBucketsN(t *testing.T) { } } +func TestStatementExecutor_NormalizeDropSeries(t *testing.T) { + q, err := influxql.ParseQuery("DROP SERIES FROM cpu") + if err != nil { + t.Fatalf("unexpected error parsing query: %v", err) + } + + stmt := q.Statements[0].(*influxql.DropSeriesStatement) + + s := &coordinator.StatementExecutor{ + MetaClient: &internal.MetaClientMock{ + DatabaseFn: func(name string) *meta.DatabaseInfo { + t.Fatal("meta client should not be called") + return nil + }, + }, + } + if err := s.NormalizeStatement(stmt, "foo"); err != nil { + t.Fatalf("unexpected error normalizing statement: %v", err) + } + + m := stmt.Sources[0].(*influxql.Measurement) + if m.Database != "" { + t.Fatalf("database rewritten when not supposed to: %v", m.Database) + } + if m.RetentionPolicy != "" { + t.Fatalf("database rewritten when not supposed to: %v", m.RetentionPolicy) + } + + if exp, got := "DROP SERIES FROM cpu", q.String(); exp != got { + t.Fatalf("generated query does match parsed: exp %v, got %v", exp, got) + } +} + +func TestStatementExecutor_NormalizeDeleteSeries(t *testing.T) { + q, err := influxql.ParseQuery("DELETE FROM cpu") + if err != nil { + t.Fatalf("unexpected error parsing query: %v", err) + } + + stmt := q.Statements[0].(*influxql.DeleteSeriesStatement) + + s := &coordinator.StatementExecutor{ + MetaClient: &internal.MetaClientMock{ + DatabaseFn: func(name string) *meta.DatabaseInfo { + t.Fatal("meta client should not be called") + return nil + }, + }, + } + if err := s.NormalizeStatement(stmt, "foo"); err != nil { + t.Fatalf("unexpected error normalizing statement: %v", err) + } + + m := stmt.Sources[0].(*influxql.Measurement) + if m.Database != "" { + t.Fatalf("database rewritten when not supposed to: %v", m.Database) + } + if m.RetentionPolicy != "" { + t.Fatalf("database rewritten when not supposed to: %v", m.RetentionPolicy) + } + + if exp, got := "DELETE FROM cpu", q.String(); exp != got { + t.Fatalf("generated query does match parsed: exp %v, got %v", exp, got) + } +} + // QueryExecutor is a test wrapper for coordinator.QueryExecutor. type QueryExecutor struct { *influxql.QueryExecutor diff --git a/internal/meta_client.go b/internal/meta_client.go index d5844a9c53..f24361cb27 100644 --- a/internal/meta_client.go +++ b/internal/meta_client.go @@ -19,7 +19,7 @@ type MetaClientMock struct { CreateUserFn func(name, password string, admin bool) (*meta.UserInfo, error) DatabaseFn func(name string) *meta.DatabaseInfo - DatabasesFn func() ([]meta.DatabaseInfo, error) + DatabasesFn func() []meta.DatabaseInfo DataFn func() meta.Data DeleteShardGroupFn func(database string, policy string, id uint64) error @@ -83,7 +83,7 @@ func (c *MetaClientMock) Database(name string) *meta.DatabaseInfo { return c.DatabaseFn(name) } -func (c *MetaClientMock) Databases() ([]meta.DatabaseInfo, error) { +func (c *MetaClientMock) Databases() []meta.DatabaseInfo { return c.DatabasesFn() }