Skip to content

Commit

Permalink
Merge pull request #467 from influxdb/fix-466-allow-any-characters-in…
Browse files Browse the repository at this point in the history
…-column-names

Fix #466 - allow any characters in column names.
  • Loading branch information
jvshahid committed Apr 22, 2014
2 parents 0bb06d5 + a064e61 commit 08821ae
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/integration/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1435,3 +1435,24 @@ func (self *SingleServerSuite) SeriesNameWithWeirdCharacters(c *C) (Fun, Fun) {
c.Assert(data[0].Name, Equals, "/blah ( ) ; : ! @ # $ \n \t,foo\"=bar/baz")
}
}

// For issue #466 - allow all characters in column names - https://github.com/influxdb/influxdb/issues/267
func (self *SingleServerSuite) ColumnNameWithWeirdCharacters(c *C) (Fun, Fun) {
return func(client Client) {
data := `[
{
"name": "foo",
"columns": ["foo.-239(*@&#$!#)(* #$@"],
"points": [[1]]
}
]`
client.WriteJsonData(data, c, "s")
}, func(client Client) {
data := client.RunQuery("select \"foo.-239(*@&#$!#)(* #$@\" from foo", c)
c.Assert(data, HasLen, 1)
c.Assert(data[0].Points, HasLen, 1)
c.Assert(data[0].Name, Equals, "foo")
c.Assert(data[0].Columns, HasLen, 1)
c.Assert(data[0].Columns[0], Equals, "foo.-239(*@&#$!#)(* #$@")
}
}
13 changes: 13 additions & 0 deletions src/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,19 @@ func (self *QueryParserSuite) TestParseContinuousQueryList(c *C) {
c.Assert(queries[0].IsListContinuousQueriesQuery(), Equals, true)
}

// For issue #466 - allow all characters in column names - https://github.com/influxdb/influxdb/issues/267
func (self *QueryParserSuite) TestParseColumnWithPeriodOrDash(c *C) {
query := "select count(\"column-a.foo\") as \"count-column-a.foo\" from seriesA;"
q, err := ParseSelectQuery(query)
c.Assert(err, IsNil)
c.Assert(q.GetColumnNames(), HasLen, 1)
column := q.GetColumnNames()[0]
c.Assert(column.Name, Equals, "count")
c.Assert(column.Elems, HasLen, 1)
c.Assert(column.Elems[0].Name, Equals, "column-a.foo")
c.Assert(column.Alias, Equals, "count-column-a.foo")
}

// TODO:
// insert into user.events.count.per_day select count(*) from user.events where time<forever group by time(1d)
// insert into :series_name.percentiles.95 select percentile(95,value) from stats.* where time<forever group by time(1d)
15 changes: 15 additions & 0 deletions src/parser/query.lex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static int yycolumn = 1;
%s FROM_CLAUSE REGEX_CONDITION
%x IN_REGEX
%x IN_TABLE_NAME
%x IN_SIMPLE_NAME
%%

; { return *yytext; }
Expand Down Expand Up @@ -99,6 +100,20 @@ true|false { yylval->string = strdup(yy

[a-zA-Z0-9_]* { yylval->string = strdup(yytext); return SIMPLE_NAME; }

\" { BEGIN(IN_SIMPLE_NAME); yylval->string=calloc(1, sizeof(char)); }
<IN_SIMPLE_NAME>\\\" {
yylval->string = realloc(yylval->string, strlen(yylval->string) + 1);
strcat(yylval->string, "\"");
}
<IN_SIMPLE_NAME>\" {
BEGIN(INITIAL);
return SIMPLE_NAME;
}
<IN_SIMPLE_NAME>[^\\"]* {
yylval->string=realloc(yylval->string, strlen(yylval->string) + strlen(yytext) + 1);
strcat(yylval->string, yytext);
}

[a-zA-Z0-9_][a-zA-Z0-9._-]* { yylval->string = strdup(yytext); return TABLE_NAME; }

\" { BEGIN(IN_TABLE_NAME); yylval->string=calloc(1, sizeof(char)); }
Expand Down

0 comments on commit 08821ae

Please sign in to comment.