Merge pull request #2624 from influxdb/fix-2563-remove-drop-series-id

Remove references to SeriesID in `DROP SERIES` handlers.
pull/2600/head
Todd Persen 2015-05-21 13:14:29 -07:00
commit 37c47e36d5
5 changed files with 61 additions and 53 deletions

View File

@ -22,6 +22,7 @@
## PRs ## PRs
- [#2569](https://github.com/influxdb/influxdb/pull/2569): Add derivative functions - [#2569](https://github.com/influxdb/influxdb/pull/2569): Add derivative functions
- [#2598](https://github.com/influxdb/influxdb/pull/2598): Implement tag support in SELECT statements - [#2598](https://github.com/influxdb/influxdb/pull/2598): Implement tag support in SELECT statements
- [#2624](https://github.com/influxdb/influxdb/pull/2624): Remove references to SeriesID in `DROP SERIES` handlers.
## v0.9.0-rc30 [2015-05-12] ## v0.9.0-rc30 [2015-05-12]

View File

@ -1448,11 +1448,8 @@ func (s *ShowSeriesStatement) RequiredPrivileges() ExecutionPrivileges {
// DropSeriesStatement represents a command for removing a series from the database. // DropSeriesStatement represents a command for removing a series from the database.
type DropSeriesStatement struct { type DropSeriesStatement struct {
// The Id of the series being dropped (optional)
SeriesID uint64
// Data source that fields are extracted from (optional) // Data source that fields are extracted from (optional)
Source Source Sources Sources
// An expression evaluated on data point (optional) // An expression evaluated on data point (optional)
Condition Expr Condition Expr
@ -1461,20 +1458,15 @@ type DropSeriesStatement struct {
// String returns a string representation of the drop series statement. // String returns a string representation of the drop series statement.
func (s *DropSeriesStatement) String() string { func (s *DropSeriesStatement) String() string {
var buf bytes.Buffer var buf bytes.Buffer
i, _ := buf.WriteString("DROP SERIES") buf.WriteString("DROP SERIES")
if s.Source != nil { if s.Sources != nil {
_, _ = buf.WriteString(" FROM ") buf.WriteString(" FROM ")
_, _ = buf.WriteString(s.Source.String()) buf.WriteString(s.Sources.String())
} }
if s.Condition != nil { if s.Condition != nil {
_, _ = buf.WriteString(" WHERE ") buf.WriteString(" WHERE ")
_, _ = buf.WriteString(s.Condition.String()) buf.WriteString(s.Condition.String())
}
// If we haven't written any data since the initial statement, then this was a SeriesID statement
if len(buf.String()) == i {
_, _ = buf.WriteString(fmt.Sprintf(" %d", s.SeriesID))
} }
return buf.String() return buf.String()

View File

@ -1023,9 +1023,11 @@ func (p *Parser) parseDropSeriesStatement() (*DropSeriesStatement, error) {
stmt := &DropSeriesStatement{} stmt := &DropSeriesStatement{}
var err error var err error
if tok, _, _ := p.scanIgnoreWhitespace(); tok == FROM { tok, pos, lit := p.scanIgnoreWhitespace()
if tok == FROM {
// Parse source. // Parse source.
if stmt.Source, err = p.parseSource(); err != nil { if stmt.Sources, err = p.parseSources(); err != nil {
return nil, err return nil, err
} }
} else { } else {
@ -1037,14 +1039,11 @@ func (p *Parser) parseDropSeriesStatement() (*DropSeriesStatement, error) {
return nil, err return nil, err
} }
// If they didn't provide a FROM or a WHERE, they need to provide the SeriesID // If they didn't provide a FROM or a WHERE, this query is invalid
if stmt.Condition == nil && stmt.Source == nil { if stmt.Condition == nil && stmt.Sources == nil {
id, err := p.parseUInt64() return nil, newParseError(tokstr(tok, lit), []string{"FROM", "WHERE"}, pos)
if err != nil {
return nil, err
}
stmt.SeriesID = id
} }
return stmt, nil return stmt, nil
} }

View File

@ -717,13 +717,9 @@ func TestParser_ParseStatement(t *testing.T) {
}, },
// DROP SERIES statement // DROP SERIES statement
{
s: `DROP SERIES 1`,
stmt: &influxql.DropSeriesStatement{SeriesID: 1},
},
{ {
s: `DROP SERIES FROM src`, s: `DROP SERIES FROM src`,
stmt: &influxql.DropSeriesStatement{Source: &influxql.Measurement{Name: "src"}}, stmt: &influxql.DropSeriesStatement{Sources: []influxql.Source{&influxql.Measurement{Name: "src"}}},
}, },
{ {
s: `DROP SERIES WHERE host = 'hosta.influxdb.org'`, s: `DROP SERIES WHERE host = 'hosta.influxdb.org'`,
@ -738,7 +734,7 @@ func TestParser_ParseStatement(t *testing.T) {
{ {
s: `DROP SERIES FROM src WHERE host = 'hosta.influxdb.org'`, s: `DROP SERIES FROM src WHERE host = 'hosta.influxdb.org'`,
stmt: &influxql.DropSeriesStatement{ stmt: &influxql.DropSeriesStatement{
Source: &influxql.Measurement{Name: "src"}, Sources: []influxql.Source{&influxql.Measurement{Name: "src"}},
Condition: &influxql.BinaryExpr{ Condition: &influxql.BinaryExpr{
Op: influxql.EQ, Op: influxql.EQ,
LHS: &influxql.VarRef{Val: "host"}, LHS: &influxql.VarRef{Val: "host"},
@ -1158,7 +1154,7 @@ func TestParser_ParseStatement(t *testing.T) {
{s: `DELETE FROM`, err: `found EOF, expected identifier at line 1, char 13`}, {s: `DELETE FROM`, err: `found EOF, expected identifier at line 1, char 13`},
{s: `DELETE FROM myseries WHERE`, err: `found EOF, expected identifier, string, number, bool at line 1, char 28`}, {s: `DELETE FROM myseries WHERE`, err: `found EOF, expected identifier, string, number, bool at line 1, char 28`},
{s: `DROP MEASUREMENT`, err: `found EOF, expected identifier at line 1, char 18`}, {s: `DROP MEASUREMENT`, err: `found EOF, expected identifier at line 1, char 18`},
{s: `DROP SERIES`, err: `found EOF, expected number at line 1, char 13`}, {s: `DROP SERIES`, err: `found EOF, expected FROM, WHERE at line 1, char 13`},
{s: `DROP SERIES FROM`, err: `found EOF, expected identifier at line 1, char 18`}, {s: `DROP SERIES FROM`, err: `found EOF, expected identifier at line 1, char 18`},
{s: `DROP SERIES FROM src WHERE`, err: `found EOF, expected identifier, string, number, bool at line 1, char 28`}, {s: `DROP SERIES FROM src WHERE`, err: `found EOF, expected identifier, string, number, bool at line 1, char 28`},
{s: `SHOW CONTINUOUS`, err: `found EOF, expected QUERIES at line 1, char 17`}, {s: `SHOW CONTINUOUS`, err: `found EOF, expected QUERIES at line 1, char 17`},
@ -1530,18 +1526,14 @@ func TestDropSeriesStatement_String(t *testing.T) {
s string s string
stmt influxql.Statement stmt influxql.Statement
}{ }{
{
s: `DROP SERIES 1`,
stmt: &influxql.DropSeriesStatement{SeriesID: 1},
},
{ {
s: `DROP SERIES FROM src`, s: `DROP SERIES FROM src`,
stmt: &influxql.DropSeriesStatement{Source: &influxql.Measurement{Name: "src"}}, stmt: &influxql.DropSeriesStatement{Sources: []influxql.Source{&influxql.Measurement{Name: "src"}}},
}, },
{ {
s: `DROP SERIES FROM src WHERE host = 'hosta.influxdb.org'`, s: `DROP SERIES FROM src WHERE host = 'hosta.influxdb.org'`,
stmt: &influxql.DropSeriesStatement{ stmt: &influxql.DropSeriesStatement{
Source: &influxql.Measurement{Name: "src"}, Sources: []influxql.Source{&influxql.Measurement{Name: "src"}},
Condition: &influxql.BinaryExpr{ Condition: &influxql.BinaryExpr{
Op: influxql.EQ, Op: influxql.EQ,
LHS: &influxql.VarRef{Val: "host"}, LHS: &influxql.VarRef{Val: "host"},
@ -1552,7 +1544,7 @@ func TestDropSeriesStatement_String(t *testing.T) {
{ {
s: `DROP SERIES FROM src WHERE host = 'hosta.influxdb.org'`, s: `DROP SERIES FROM src WHERE host = 'hosta.influxdb.org'`,
stmt: &influxql.DropSeriesStatement{ stmt: &influxql.DropSeriesStatement{
Source: &influxql.Measurement{Name: "src"}, Sources: []influxql.Source{&influxql.Measurement{Name: "src"}},
Condition: &influxql.BinaryExpr{ Condition: &influxql.BinaryExpr{
Op: influxql.EQ, Op: influxql.EQ,
LHS: &influxql.VarRef{Val: "host"}, LHS: &influxql.VarRef{Val: "host"},

View File

@ -2547,20 +2547,8 @@ func (s *Server) executeDropSeriesStatement(stmt *influxql.DropSeriesStatement,
defer s.mu.RUnlock() defer s.mu.RUnlock()
seriesByMeasurement := make(map[string][]uint64) seriesByMeasurement := make(map[string][]uint64)
// Handle the simple `DROP SERIES <id>` case.
if stmt.Source == nil && stmt.Condition == nil {
for _, db := range s.databases {
for _, m := range db.measurements {
if m.seriesByID[stmt.SeriesID] != nil {
seriesByMeasurement[m.Name] = []uint64{stmt.SeriesID}
}
}
}
return seriesByMeasurement, nil // Handle `DROP SERIES` with sources and/or conditions...
}
// Handle the more complicated `DROP SERIES` with sources and/or conditions...
// Find the database. // Find the database.
db := s.databases[database] db := s.databases[database]
@ -2568,8 +2556,13 @@ func (s *Server) executeDropSeriesStatement(stmt *influxql.DropSeriesStatement,
return nil, ErrDatabaseNotFound(database) return nil, ErrDatabaseNotFound(database)
} }
// Get the list of measurements we're interested in. // Expand regex expressions in the FROM clause.
measurements, err := measurementsFromSourceOrDB(stmt.Source, db) sources, err := s.expandSources(stmt.Sources)
if err != nil {
return nil, err
}
measurements, err := measurementsFromSourcesOrDB(db, sources...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3053,6 +3046,37 @@ func measurementsFromSourceOrDB(stmt influxql.Source, db *database) (Measurement
return measurements, nil return measurements, nil
} }
// measurementsFromSourcesOrDB returns a list of measurements from the
// sources passed in or, if sources is empty, a list of all
// measurement names from the database passed in.
func measurementsFromSourcesOrDB(db *database, sources ...influxql.Source) (Measurements, error) {
var measurements Measurements
if len(sources) > 0 {
for _, source := range sources {
if m, ok := source.(*influxql.Measurement); ok {
measurement := db.measurements[m.Name]
if measurement == nil {
return nil, ErrMeasurementNotFound(m.Name)
}
measurements = append(measurements, measurement)
} else {
return nil, errors.New("identifiers in FROM clause must be measurement names")
}
}
} else {
// No measurements specified in FROM clause so get all measurements that have series.
for _, m := range db.Measurements() {
if len(m.seriesIDs) > 0 {
measurements = append(measurements, m)
}
}
}
sort.Sort(measurements)
return measurements, nil
}
func (s *Server) executeShowUsersStatement(q *influxql.ShowUsersStatement, user *User) *Result { func (s *Server) executeShowUsersStatement(q *influxql.ShowUsersStatement, user *User) *Result {
row := &influxql.Row{Columns: []string{"user", "admin"}} row := &influxql.Row{Columns: []string{"user", "admin"}}
for _, user := range s.Users() { for _, user := range s.Users() {