From e7c40e5cae65636a9125315de45f0457b6ffb417 Mon Sep 17 00:00:00 2001 From: Todd Persen Date: Wed, 20 May 2015 14:27:33 -0700 Subject: [PATCH 1/6] Remove references to SeriesID in `DROP SERIES` handlers. --- influxql/ast.go | 18 +++++------------- influxql/parser.go | 7 ++----- server.go | 14 +------------- 3 files changed, 8 insertions(+), 31 deletions(-) diff --git a/influxql/ast.go b/influxql/ast.go index 0a6ced7d24d..f983abbb7f5 100644 --- a/influxql/ast.go +++ b/influxql/ast.go @@ -1448,9 +1448,6 @@ func (s *ShowSeriesStatement) RequiredPrivileges() ExecutionPrivileges { // DropSeriesStatement represents a command for removing a series from the database. type DropSeriesStatement struct { - // The Id of the series being dropped (optional) - SeriesID uint64 - // Data source that fields are extracted from (optional) Source Source @@ -1461,20 +1458,15 @@ type DropSeriesStatement struct { // String returns a string representation of the drop series statement. func (s *DropSeriesStatement) String() string { var buf bytes.Buffer - i, _ := buf.WriteString("DROP SERIES") + buf.WriteString("DROP SERIES") if s.Source != nil { - _, _ = buf.WriteString(" FROM ") - _, _ = buf.WriteString(s.Source.String()) + buf.WriteString(" FROM ") + buf.WriteString(s.Source.String()) } if s.Condition != nil { - _, _ = buf.WriteString(" WHERE ") - _, _ = 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)) + buf.WriteString(" WHERE ") + buf.WriteString(s.Condition.String()) } return buf.String() diff --git a/influxql/parser.go b/influxql/parser.go index 03179c39ddd..897205b52e3 100644 --- a/influxql/parser.go +++ b/influxql/parser.go @@ -1039,12 +1039,9 @@ func (p *Parser) parseDropSeriesStatement() (*DropSeriesStatement, error) { // If they didn't provide a FROM or a WHERE, they need to provide the SeriesID if stmt.Condition == nil && stmt.Source == nil { - id, err := p.parseUInt64() - if err != nil { - return nil, err - } - stmt.SeriesID = id + return nil, fmt.Errorf("DROP SERIES requires a FROM or WHERE clause") } + return stmt, nil } diff --git a/server.go b/server.go index 1a18b709be1..5640184e7dd 100644 --- a/server.go +++ b/server.go @@ -2547,20 +2547,8 @@ func (s *Server) executeDropSeriesStatement(stmt *influxql.DropSeriesStatement, defer s.mu.RUnlock() seriesByMeasurement := make(map[string][]uint64) - // Handle the simple `DROP SERIES ` 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 the more complicated `DROP SERIES` with sources and/or conditions... + // Handle `DROP SERIES` with sources and/or conditions... // Find the database. db := s.databases[database] From 344db8ff1e625aca46203ef7d87837c25c6b754e Mon Sep 17 00:00:00 2001 From: Todd Persen Date: Wed, 20 May 2015 14:55:19 -0700 Subject: [PATCH 2/6] Fix up parser and handle new error message. --- influxql/parser.go | 8 +++++--- influxql/parser_test.go | 10 +--------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/influxql/parser.go b/influxql/parser.go index 897205b52e3..62db65dc6ab 100644 --- a/influxql/parser.go +++ b/influxql/parser.go @@ -1023,7 +1023,9 @@ func (p *Parser) parseDropSeriesStatement() (*DropSeriesStatement, error) { stmt := &DropSeriesStatement{} var err error - if tok, _, _ := p.scanIgnoreWhitespace(); tok == FROM { + tok, pos, lit := p.scanIgnoreWhitespace() + + if tok == FROM { // Parse source. if stmt.Source, err = p.parseSource(); err != nil { return nil, err @@ -1037,9 +1039,9 @@ func (p *Parser) parseDropSeriesStatement() (*DropSeriesStatement, error) { 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 { - return nil, fmt.Errorf("DROP SERIES requires a FROM or WHERE clause") + return nil, newParseError(tokstr(tok, lit), []string{"FROM", "WHERE"}, pos) } return stmt, nil diff --git a/influxql/parser_test.go b/influxql/parser_test.go index 3b40a2015de..6ae5b79ee72 100644 --- a/influxql/parser_test.go +++ b/influxql/parser_test.go @@ -717,10 +717,6 @@ func TestParser_ParseStatement(t *testing.T) { }, // DROP SERIES statement - { - s: `DROP SERIES 1`, - stmt: &influxql.DropSeriesStatement{SeriesID: 1}, - }, { s: `DROP SERIES FROM src`, stmt: &influxql.DropSeriesStatement{Source: &influxql.Measurement{Name: "src"}}, @@ -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 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 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 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`}, @@ -1530,10 +1526,6 @@ func TestDropSeriesStatement_String(t *testing.T) { s string stmt influxql.Statement }{ - { - s: `DROP SERIES 1`, - stmt: &influxql.DropSeriesStatement{SeriesID: 1}, - }, { s: `DROP SERIES FROM src`, stmt: &influxql.DropSeriesStatement{Source: &influxql.Measurement{Name: "src"}}, From 57fd3f406dfa46af8fa52a7e329bea7a414d0594 Mon Sep 17 00:00:00 2001 From: Todd Persen Date: Wed, 20 May 2015 17:32:01 -0700 Subject: [PATCH 3/6] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8f64e6a5c3..98326510e35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ ## PRs - [#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 +- [#2624](https://github.com/influxdb/influxdb/pull/2624): Remove references to SeriesID in `DROP SERIES` handlers. ## v0.9.0-rc30 [2015-05-12] From 7828af48fd541f4129a2bee0bdb99cd53fe47821 Mon Sep 17 00:00:00 2001 From: Todd Persen Date: Thu, 21 May 2015 11:18:21 -0700 Subject: [PATCH 4/6] Make `DROP SERIES` take `Sources` instead of `Source` --- influxql/ast.go | 6 +++--- influxql/parser.go | 4 ++-- server.go | 17 +++++++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/influxql/ast.go b/influxql/ast.go index f983abbb7f5..b279a6d5fce 100644 --- a/influxql/ast.go +++ b/influxql/ast.go @@ -1449,7 +1449,7 @@ func (s *ShowSeriesStatement) RequiredPrivileges() ExecutionPrivileges { // DropSeriesStatement represents a command for removing a series from the database. type DropSeriesStatement struct { // Data source that fields are extracted from (optional) - Source Source + Sources Sources // An expression evaluated on data point (optional) Condition Expr @@ -1460,9 +1460,9 @@ func (s *DropSeriesStatement) String() string { var buf bytes.Buffer buf.WriteString("DROP SERIES") - if s.Source != nil { + if s.Sources != nil { buf.WriteString(" FROM ") - buf.WriteString(s.Source.String()) + buf.WriteString(s.Sources.String()) } if s.Condition != nil { buf.WriteString(" WHERE ") diff --git a/influxql/parser.go b/influxql/parser.go index 62db65dc6ab..2e488812192 100644 --- a/influxql/parser.go +++ b/influxql/parser.go @@ -1027,7 +1027,7 @@ func (p *Parser) parseDropSeriesStatement() (*DropSeriesStatement, error) { if tok == FROM { // Parse source. - if stmt.Source, err = p.parseSource(); err != nil { + if stmt.Sources, err = p.parseSources(); err != nil { return nil, err } } else { @@ -1040,7 +1040,7 @@ func (p *Parser) parseDropSeriesStatement() (*DropSeriesStatement, error) { } // 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 { return nil, newParseError(tokstr(tok, lit), []string{"FROM", "WHERE"}, pos) } diff --git a/server.go b/server.go index 5640184e7dd..3e9efa98d95 100644 --- a/server.go +++ b/server.go @@ -2556,10 +2556,19 @@ func (s *Server) executeDropSeriesStatement(stmt *influxql.DropSeriesStatement, return nil, ErrDatabaseNotFound(database) } - // Get the list of measurements we're interested in. - measurements, err := measurementsFromSourceOrDB(stmt.Source, db) - if err != nil { - return nil, err + var measurements Measurements + var err error + + for _, source := range stmt.Sources { + // Get the list of measurements we're interested in. + sourceMeasurements, err := measurementsFromSourceOrDB(source, db) + if err != nil { + return nil, err + } + + for _, measurement := range sourceMeasurements { + measurements = append(measurements, measurement) + } } for _, m := range measurements { From 074b3bf099983953186fefbf8128b474f966c3f8 Mon Sep 17 00:00:00 2001 From: Todd Persen Date: Thu, 21 May 2015 12:38:35 -0700 Subject: [PATCH 5/6] Update the way that `DROP SERIES` handles `Sources` --- influxql/parser_test.go | 10 ++++----- server.go | 47 +++++++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/influxql/parser_test.go b/influxql/parser_test.go index 6ae5b79ee72..b0d69557819 100644 --- a/influxql/parser_test.go +++ b/influxql/parser_test.go @@ -719,7 +719,7 @@ func TestParser_ParseStatement(t *testing.T) { // DROP SERIES statement { 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'`, @@ -734,7 +734,7 @@ func TestParser_ParseStatement(t *testing.T) { { s: `DROP SERIES FROM src WHERE host = 'hosta.influxdb.org'`, stmt: &influxql.DropSeriesStatement{ - Source: &influxql.Measurement{Name: "src"}, + Sources: []influxql.Source{&influxql.Measurement{Name: "src"}}, Condition: &influxql.BinaryExpr{ Op: influxql.EQ, LHS: &influxql.VarRef{Val: "host"}, @@ -1528,12 +1528,12 @@ func TestDropSeriesStatement_String(t *testing.T) { }{ { 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'`, stmt: &influxql.DropSeriesStatement{ - Source: &influxql.Measurement{Name: "src"}, + Sources: []influxql.Source{&influxql.Measurement{Name: "src"}}, Condition: &influxql.BinaryExpr{ Op: influxql.EQ, LHS: &influxql.VarRef{Val: "host"}, @@ -1544,7 +1544,7 @@ func TestDropSeriesStatement_String(t *testing.T) { { s: `DROP SERIES FROM src WHERE host = 'hosta.influxdb.org'`, stmt: &influxql.DropSeriesStatement{ - Source: &influxql.Measurement{Name: "src"}, + Sources: []influxql.Source{&influxql.Measurement{Name: "src"}}, Condition: &influxql.BinaryExpr{ Op: influxql.EQ, LHS: &influxql.VarRef{Val: "host"}, diff --git a/server.go b/server.go index 3e9efa98d95..1e237418cde 100644 --- a/server.go +++ b/server.go @@ -2556,19 +2556,9 @@ func (s *Server) executeDropSeriesStatement(stmt *influxql.DropSeriesStatement, return nil, ErrDatabaseNotFound(database) } - var measurements Measurements - var err error - - for _, source := range stmt.Sources { - // Get the list of measurements we're interested in. - sourceMeasurements, err := measurementsFromSourceOrDB(source, db) - if err != nil { - return nil, err - } - - for _, measurement := range sourceMeasurements { - measurements = append(measurements, measurement) - } + measurements, err := measurementsFromSourcesOrDB(db, stmt.Sources...) + if err != nil { + return nil, err } for _, m := range measurements { @@ -3053,6 +3043,37 @@ func measurementsFromSourceOrDB(stmt influxql.Source, db *database) (Measurement 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 { row := &influxql.Row{Columns: []string{"user", "admin"}} for _, user := range s.Users() { From 0c4cb89d670ae653f486da20326ca9a7820de217 Mon Sep 17 00:00:00 2001 From: Todd Persen Date: Thu, 21 May 2015 13:09:14 -0700 Subject: [PATCH 6/6] Expand sources. --- server.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server.go b/server.go index 1e237418cde..0daa5a3a654 100644 --- a/server.go +++ b/server.go @@ -2556,7 +2556,13 @@ func (s *Server) executeDropSeriesStatement(stmt *influxql.DropSeriesStatement, return nil, ErrDatabaseNotFound(database) } - measurements, err := measurementsFromSourcesOrDB(db, stmt.Sources...) + // Expand regex expressions in the FROM clause. + sources, err := s.expandSources(stmt.Sources) + if err != nil { + return nil, err + } + + measurements, err := measurementsFromSourcesOrDB(db, sources...) if err != nil { return nil, err }