Skip to content

Commit

Permalink
Allow 'INF' to indicate infinite retention
Browse files Browse the repository at this point in the history
  • Loading branch information
otoolep committed Mar 5, 2015
1 parent 77d8986 commit a2e4556
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion influxql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,14 @@ func (p *Parser) parseUInt32() (uint32, error) {
// This function assumes the DURATION token has already been consumed.
func (p *Parser) parseDuration() (time.Duration, error) {
tok, pos, lit := p.scanIgnoreWhitespace()
if tok != DURATION_VAL {
if tok != DURATION_VAL && tok != INF {
return 0, newParseError(tokstr(tok, lit), []string{"duration"}, pos)
}

if tok == INF {
return 0, nil
}

d, err := ParseDuration(lit)
if err != nil {
return 0, &ParseError{Message: err.Error(), Pos: pos}
Expand Down
17 changes: 17 additions & 0 deletions influxql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,17 @@ func TestParser_ParseStatement(t *testing.T) {
},
},

// CREATE RETENTION POLICY with infinite retention
{
s: `CREATE RETENTION POLICY policy1 ON testdb DURATION INF REPLICATION 2`,
stmt: &influxql.CreateRetentionPolicyStatement{
Name: "policy1",
Database: "testdb",
Duration: 0,
Replication: 2,
},
},

// CREATE RETENTION POLICY ... DEFAULT
{
s: `CREATE RETENTION POLICY policy1 ON testdb DURATION 2m REPLICATION 4 DEFAULT`,
Expand All @@ -661,6 +672,12 @@ func TestParser_ParseStatement(t *testing.T) {
stmt: newAlterRetentionPolicyStatement("policy1", "testdb", time.Minute, 4, true),
},

// ALTER RETENTION POLICY with infinite retention
{
s: `ALTER RETENTION POLICY policy1 ON testdb DEFAULT REPLICATION 4 DURATION INF`,
stmt: newAlterRetentionPolicyStatement("policy1", "testdb", 0, 4, true),
},

// ALTER RETENTION POLICY without optional DURATION
{
s: `ALTER RETENTION POLICY policy1 ON testdb DEFAULT REPLICATION 4`,
Expand Down
2 changes: 2 additions & 0 deletions influxql/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const (
GROUP
IF
IN
INF
INNER
INSERT
INTO
Expand Down Expand Up @@ -176,6 +177,7 @@ var tokens = [...]string{
GROUP: "GROUP",
IF: "IF",
IN: "IN",
INF: "INF",
INNER: "INNER",
INSERT: "INSERT",
INTO: "INTO",
Expand Down

0 comments on commit a2e4556

Please sign in to comment.