Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing error on multiple queries when CREATE RETENTION POLICY doesn't end in DEFAULT #6398

Closed
caitlinelfring opened this issue Apr 15, 2016 · 1 comment
Assignees
Milestone

Comments

@caitlinelfring
Copy link

Bug report

When running multiple queries separated by semicolon, when one of the queries (which is not the last query) is a CREATE REPLICATION POLICY query does not end in DEFAULT (for example, CREATE RETENTION POLICY "10m.events" ON somedb DURATION 60m REPLICATION <int>; SELECT a from somedb), the query fails with an error unexpected error: found SELECT, expected ; at line 1, char 61

I've tried a lot of other multiple queries, but the only ones that fail are when it CREATE RETENTION POLICY does not end with DEFAULT.

System info: InfluxDB 0.12.1-1 running on Ubuntu 14.04.4 LTS (GNU/Linux 3.13.0-79-generic x86_64) installed via RPM, within docker image tutum/influxdb:0.12, and installed from source using your build-docker.sh script.

Steps to reproduce:

  1. Using InfluxCLI, HTTP query, client libraries, admin interface, run multiple queries where the first query is CREATE RETENTION POLICY "10m.events" ON somedb DURATION 60m REPLICATION <int> {SHARD DURATION 30m} and the second query is anything, and the two queries are separated by a ; semicolon.
  2. error is returned: ERR: error parsing query: found SELECT, expected ; at line 1, char 86
  3. Retention policy is not created

Expected behavior: Creation of retention policy and results from second query

Actual behavior: Parsing Error ERR: error parsing query: found SELECT, expected ; at line 1, char 86, retention policy not created, no results returned

Additional info:

Sample of multiple queries that work and do not work. If you switch the queries to SELECT is first and CREATE RETENTION POLICY is last, it works as expected. But if you add another query after CREATE RETENTION POLICY, you receive an error.

Also, there are no errors if you use two semicolons ;; after CREATE RETENTION POLICY.

> CREATE RETENTION POLICY rp_90d2 on db duration 90d REPLICATION 2 SHARD DURATION 30m DEFAULT; select * from db;
> show retention policies
ERR: error parsing query: found EOF, expected ON at line 1, char 25
> show retention policies on db
name    duration    shardGroupDuration  replicaN    default
default 0       168h0m0s        1       false
rp_90d2 2160h0m0s   30m0s           2       true

> CREATE RETENTION POLICY rp_90d3 on db duration 90d REPLICATION 2 SHARD DURATION 30m; select * from db;
ERR: error parsing query: found SELECT, expected ; at line 1, char 86
> show retention policies on db
name    duration    shardGroupDuration  replicaN    default
default 0       168h0m0s        1       false
rp_90d2 2160h0m0s   30m0s           2       true

> CREATE RETENTION POLICY rp_90d4 on db duration 90d REPLICATION 2; select * from db;
ERR: error parsing query: found SELECT, expected ; at line 1, char 67
> show retention policies on db
name    duration    shardGroupDuration  replicaN    default
default 0       168h0m0s        1       false
rp_90d2 2160h0m0s   30m0s           2       true

> CREATE RETENTION POLICY rp_90d4 on db duration 90d REPLICATION 2 DEFAULT; select * from db;
> show retention policies on db
name    duration    shardGroupDuration  replicaN    default
default 0       168h0m0s        1       false
rp_90d2 2160h0m0s   30m0s           2       false
rp_90d4 2160h0m0s   24h0m0s         2       true
@caitlinelfring
Copy link
Author

Additionally, I added a test to the influxql/parser_test.go code, which failed:

func TestParser_ParseQuery_MultipleCreateRP(t *testing.T) {
    s := `CREATE RETENTION POLICY rp on d duration 90d replication 1; select a from d;`
    q, err := influxql.NewParser(strings.NewReader(s)).ParseQuery()
    if err != nil {
        t.Fatalf("unexpected error: %s", err)
    } else if len(q.Statements) != 2 {
        t.Fatalf("unexpected statement count: %d", len(q.Statements))
    }
}

It looks like it's the parse is ignoring the semicolon on these specific queries.

@jsternberg jsternberg self-assigned this Apr 17, 2016
@jsternberg jsternberg added this to the 0.13.0 milestone Apr 17, 2016
jsternberg added a commit that referenced this issue Apr 17, 2016
…houldn't

The optional sections of the command consumed the semicolon token and
didn't put it back for the outer loop. The code shouldn't explicitly
check for a semicolon or EOF anyway, so these checks were removed and
the token gets unscanned if it doesn't match the optional token that the
parser is looking for.

Fixes #6398.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants