Merge branch 'master' into contributing

pull/1323/head
Cory LaNou 2015-01-13 18:04:15 -07:00
commit 5ecbcc925b
5 changed files with 91 additions and 5 deletions

View File

@ -14,6 +14,9 @@ ALTER RETENTION POLICY <rp-name> ON <db-name> (DURATION <duration> | REPLICATION
-- drop a database -- drop a database
DROP DATABASE <name> DROP DATABASE <name>
-- drop a retention policy
DROP RETENTION POLICY <rp-name> ON <db.name>
``` ```
# Users and permissions # Users and permissions

View File

@ -110,6 +110,7 @@ statement = alter_retention_policy_stmt |
delete_stmt | delete_stmt |
drop_continuous_query_stmt | drop_continuous_query_stmt |
drop_database_stmt | drop_database_stmt |
drop_retention_policy_stmt |
drop_series_stmt | drop_series_stmt |
drop_user_stmt | drop_user_stmt |
grant_stmt | grant_stmt |
@ -246,7 +247,22 @@ delete_stmt = "DELETE" from_clause where_clause .
#### Example: #### Example:
```sql ```sql
DELETE FROM cpu WHERE region = 'uswest' -- delete data points from the cpu measurement where the region tag
-- equals 'uswest'
DELETE FROM cpu WHERE region = 'uswest';
```
### DROP RETENTION POLICY
```
drop_retention_policy_stmt = "DROP RETENTION POLICY" policy_name "ON" db_name .
```
#### Example:
```sql
-- drop the retention policy named 1h.cpu from mydb
DROP RETENTION POLICY "1h.cpu" ON mydb;
``` ```
### GRANT ### GRANT
@ -268,7 +284,7 @@ GRANT READ ON mydb TO jdoe;
### LIST DATABASES ### LIST DATABASES
``` ```
list_databases_stmt = "LIST DATABASES" list_databases_stmt = "LIST DATABASES" .
``` ```
#### Example: #### Example:
@ -281,7 +297,7 @@ LIST DATABASES;
### LIST RETENTION POLICIES ### LIST RETENTION POLICIES
``` ```
list_retention_policies = "LIST RETENTION POLICIES" db_name list_retention_policies = "LIST RETENTION POLICIES" db_name .
``` ```
#### Example: #### Example:
@ -310,9 +326,11 @@ expr =
measurements = measurements =
user_name = identifier .
password = identifier . password = identifier .
policy_name = identifier .
user_name = identifier .
privilege = "ALL" [ "PRIVILEGES" ] | "READ" | "WRITE" . privilege = "ALL" [ "PRIVILEGES" ] | "READ" | "WRITE" .
``` ```

View File

@ -55,6 +55,7 @@ func (_ *CreateUserStatement) node() {}
func (_ *DeleteStatement) node() {} func (_ *DeleteStatement) node() {}
func (_ *DropContinuousQueryStatement) node() {} func (_ *DropContinuousQueryStatement) node() {}
func (_ *DropDatabaseStatement) node() {} func (_ *DropDatabaseStatement) node() {}
func (_ *DropRetentionPolicyStatement) node() {}
func (_ *DropSeriesStatement) node() {} func (_ *DropSeriesStatement) node() {}
func (_ *DropUserStatement) node() {} func (_ *DropUserStatement) node() {}
func (_ *GrantStatement) node() {} func (_ *GrantStatement) node() {}
@ -126,6 +127,7 @@ func (_ *CreateUserStatement) stmt() {}
func (_ *DeleteStatement) stmt() {} func (_ *DeleteStatement) stmt() {}
func (_ *DropContinuousQueryStatement) stmt() {} func (_ *DropContinuousQueryStatement) stmt() {}
func (_ *DropDatabaseStatement) stmt() {} func (_ *DropDatabaseStatement) stmt() {}
func (_ *DropRetentionPolicyStatement) stmt() {}
func (_ *DropSeriesStatement) stmt() {} func (_ *DropSeriesStatement) stmt() {}
func (_ *DropUserStatement) stmt() {} func (_ *DropUserStatement) stmt() {}
func (_ *GrantStatement) stmt() {} func (_ *GrantStatement) stmt() {}
@ -226,6 +228,25 @@ func (s *DropDatabaseStatement) String() string {
return buf.String() return buf.String()
} }
// DropRetentionPolicyStatement represents a command to drop a retention policy from a database.
type DropRetentionPolicyStatement struct {
// Name of the policy to drop.
Name string
// Name of the database to drop the policy from.
Database string
}
// String returns a string representation of the drop retention policy statement.
func (s *DropRetentionPolicyStatement) String() string {
var buf bytes.Buffer
_, _ = buf.WriteString("DROP RETENTION POLICY ")
_, _ = buf.WriteString(s.Name)
_, _ = buf.WriteString(" ON ")
_, _ = buf.WriteString(s.Database)
return buf.String()
}
// CreateUserStatement represents a command for creating a new user. // CreateUserStatement represents a command for creating a new user.
type CreateUserStatement struct { type CreateUserStatement struct {
// Name of the user to be created. // Name of the user to be created.

View File

@ -155,6 +155,12 @@ func (p *Parser) parseDropStatement() (Statement, error) {
return p.parseDropContinuousQueryStatement() return p.parseDropContinuousQueryStatement()
} else if tok == DATABASE { } else if tok == DATABASE {
return p.parseDropDatabaseStatement() return p.parseDropDatabaseStatement()
} else if tok == RETENTION {
if tok, pos, lit := p.scanIgnoreWhitespace(); tok == POLICY {
return p.parseDropRetentionPolicyStatement()
} else {
return nil, newParseError(tokstr(tok, lit), []string{"POLICY"}, pos)
}
} else if tok == USER { } else if tok == USER {
return p.parseDropUserStatement() return p.parseDropUserStatement()
} }
@ -932,6 +938,31 @@ func (p *Parser) parseDropDatabaseStatement() (*DropDatabaseStatement, error) {
return stmt, nil return stmt, nil
} }
// parseDropRetentionPolicyStatement parses a string and returns a DropRetentionPolicyStatement.
// This function assumes the DROP RETENTION POLICY tokens have been consumed.
func (p *Parser) parseDropRetentionPolicyStatement() (*DropRetentionPolicyStatement, error) {
stmt := &DropRetentionPolicyStatement{}
// Parse the policy name.
ident, err := p.parseIdentifier()
if err != nil {
return nil, err
}
stmt.Name = ident
// Consume the required ON token.
if tok, pos, lit := p.scanIgnoreWhitespace(); tok != ON {
return nil, newParseError(tokstr(tok, lit), []string{"ON"}, pos)
}
// Parse the database name.
if stmt.Database, err = p.parseIdentifier(); err != nil {
return nil, err
}
return stmt, nil
}
// parseCreateUserStatement parses a string and returns a CreateUserStatement. // parseCreateUserStatement parses a string and returns a CreateUserStatement.
// This function assumes the "CREATE USER" tokens have already been consumed. // This function assumes the "CREATE USER" tokens have already been consumed.
func (p *Parser) parseCreateUserStatement() (*CreateUserStatement, error) { func (p *Parser) parseCreateUserStatement() (*CreateUserStatement, error) {

View File

@ -361,6 +361,15 @@ func TestParser_ParseStatement(t *testing.T) {
stmt: &influxql.DropDatabaseStatement{Name: "testdb"}, stmt: &influxql.DropDatabaseStatement{Name: "testdb"},
}, },
// DROP RETENTION POLICY
{
s: `DROP RETENTION POLICY "1h.cpu" ON mydb`,
stmt: &influxql.DropRetentionPolicyStatement{
Name: "1h.cpu",
Database: "mydb",
},
},
// DROP USER statement // DROP USER statement
{ {
s: `DROP USER jdoe`, s: `DROP USER jdoe`,
@ -548,6 +557,10 @@ func TestParser_ParseStatement(t *testing.T) {
{s: `DROP CONTINUOUS QUERY`, err: `found EOF, expected identifier, string at line 1, char 23`}, {s: `DROP CONTINUOUS QUERY`, err: `found EOF, expected identifier, string at line 1, char 23`},
{s: `DROP FOO`, err: `found FOO, expected SERIES, CONTINUOUS at line 1, char 6`}, {s: `DROP FOO`, err: `found FOO, expected SERIES, CONTINUOUS at line 1, char 6`},
{s: `DROP DATABASE`, err: `found EOF, expected identifier at line 1, char 15`}, {s: `DROP DATABASE`, err: `found EOF, expected identifier at line 1, char 15`},
{s: `DROP RETENTION`, err: `found EOF, expected POLICY at line 1, char 16`},
{s: `DROP RETENTION POLICY`, err: `found EOF, expected identifier at line 1, char 23`},
{s: `DROP RETENTION POLICY "1h.cpu"`, err: `found EOF, expected ON at line 1, char 31`},
{s: `DROP RETENTION POLICY "1h.cpu" ON`, err: `found EOF, expected identifier at line 1, char 35`},
{s: `DROP USER`, err: `found EOF, expected identifier at line 1, char 11`}, {s: `DROP USER`, err: `found EOF, expected identifier at line 1, char 11`},
{s: `CREATE USER testuser`, err: `found EOF, expected WITH at line 1, char 22`}, {s: `CREATE USER testuser`, err: `found EOF, expected WITH at line 1, char 22`},
{s: `CREATE USER testuser WITH`, err: `found EOF, expected PASSWORD at line 1, char 27`}, {s: `CREATE USER testuser WITH`, err: `found EOF, expected PASSWORD at line 1, char 27`},