Don't normalize drop/delete series statements
7093 causes a parse error to be returned from delete and drop statements. Normalizing them cause an invalid statement to be generated which cannot be reparse if converted to a string and back.pull/7532/head
parent
d785a2d9f2
commit
d105e344c2
|
@ -1090,8 +1090,14 @@ func (e *StatementExecutor) NormalizeStatement(stmt influxql.Statement, defaultD
|
||||||
node.Database = defaultDatabase
|
node.Database = defaultDatabase
|
||||||
}
|
}
|
||||||
case *influxql.Measurement:
|
case *influxql.Measurement:
|
||||||
|
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)
|
err = e.normalizeMeasurement(node, defaultDatabase)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/influxdata/influxdb/coordinator"
|
"github.com/influxdata/influxdb/coordinator"
|
||||||
"github.com/influxdata/influxdb/influxql"
|
"github.com/influxdata/influxdb/influxql"
|
||||||
|
"github.com/influxdata/influxdb/internal"
|
||||||
"github.com/influxdata/influxdb/models"
|
"github.com/influxdata/influxdb/models"
|
||||||
"github.com/influxdata/influxdb/services/meta"
|
"github.com/influxdata/influxdb/services/meta"
|
||||||
"github.com/influxdata/influxdb/tsdb"
|
"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.
|
// QueryExecutor is a test wrapper for coordinator.QueryExecutor.
|
||||||
type QueryExecutor struct {
|
type QueryExecutor struct {
|
||||||
*influxql.QueryExecutor
|
*influxql.QueryExecutor
|
||||||
|
|
|
@ -19,7 +19,7 @@ type MetaClientMock struct {
|
||||||
CreateUserFn func(name, password string, admin bool) (*meta.UserInfo, error)
|
CreateUserFn func(name, password string, admin bool) (*meta.UserInfo, error)
|
||||||
|
|
||||||
DatabaseFn func(name string) *meta.DatabaseInfo
|
DatabaseFn func(name string) *meta.DatabaseInfo
|
||||||
DatabasesFn func() ([]meta.DatabaseInfo, error)
|
DatabasesFn func() []meta.DatabaseInfo
|
||||||
|
|
||||||
DataFn func() meta.Data
|
DataFn func() meta.Data
|
||||||
DeleteShardGroupFn func(database string, policy string, id uint64) error
|
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)
|
return c.DatabaseFn(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MetaClientMock) Databases() ([]meta.DatabaseInfo, error) {
|
func (c *MetaClientMock) Databases() []meta.DatabaseInfo {
|
||||||
return c.DatabasesFn()
|
return c.DatabasesFn()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue