fix #437. Note the previous fix in 6cb9413 broke other functionality

pull/443/head
John Shahid 2014-04-15 16:00:01 -04:00
parent afb76a8183
commit 876de6b745
5 changed files with 33 additions and 6 deletions

View File

@ -147,16 +147,16 @@ func (self *SingleServerSuite) TestDataResurrectionAfterRestartWithDeleteQuery(c
s := CreatePoints("data_resurrection_with_delete", 1, 10)
self.server.WriteData(s, c)
self.server.WaitForServerToSync()
series := self.server.RunQuery("select count(column0) from data_resurrection_with_delete", "s", c)
series := self.server.RunQueryAsRoot("select count(column0) from data_resurrection_with_delete", "s", c)
c.Assert(series, HasLen, 1)
c.Assert(series[0].Points[0][1], Equals, 10.0)
self.server.RunQuery("delete from data_resurrection_with_delete", "s", c)
series = self.server.RunQuery("select count(column0) from data_resurrection_with_delete", "s", c)
self.server.RunQueryAsRoot("delete from data_resurrection_with_delete", "s", c)
series = self.server.RunQueryAsRoot("select count(column0) from data_resurrection_with_delete", "s", c)
c.Assert(series, HasLen, 0)
self.server.Stop()
c.Assert(self.server.Start(), IsNil)
self.server.WaitForServerToStart()
series = self.server.RunQuery("select count(column0) from data_resurrection_with_delete", "s", c)
series = self.server.RunQueryAsRoot("select count(column0) from data_resurrection_with_delete", "s", c)
c.Assert(series, HasLen, 0)
}

View File

@ -704,6 +704,9 @@ func (self *QueryParserSuite) TestQueryWithArithmeticColumns(c *C) {
c.Assert(err, IsNil)
c.Assert(q.ColumnNames, HasLen, 1)
c.Assert(int(q.ColumnNames[0].Type), Equals, ValueExpression)
c.Assert(q.ColumnNames[0].Name, Equals, "*")
c.Assert(q.ColumnNames[0].Elems[0].Name, Equals, "-1")
c.Assert(q.ColumnNames[0].Elems[1].Name, Equals, "value")
}
func (self *QueryParserSuite) TestParseSelectWithComplexArithmeticOperations(c *C) {

View File

@ -87,11 +87,11 @@ static int yycolumn = 1;
"<=" { yylval->string = strdup(yytext); return OPERATION_LE; }
">=" { yylval->string = strdup(yytext); return OPERATION_GE; }
-?[0-9]+ { yylval->string = strdup(yytext); return INT_VALUE; }
[0-9]+ { yylval->string = strdup(yytext); return INT_VALUE; }
([0-9]+|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)[usmhdw] { yylval->string = strdup(yytext); return DURATION; }
-?[0-9]*\.[0-9]+|[0-9]+\.[0-9]* { yylval->string = strdup(yytext); return FLOAT_VALUE; }
[0-9]*\.[0-9]+|[0-9]+\.[0-9]* { yylval->string = strdup(yytext); return FLOAT_VALUE; }
true|false { yylval->string = strdup(yytext); return BOOLEAN_VALUE; }

View File

@ -430,11 +430,31 @@ VALUE:
$$ = create_value($1, VALUE_INT, FALSE, NULL);
}
|
'-' INT_VALUE
{
size_t len = strlen($2) + 2;
char *new_value = malloc(len);
new_value[0] = '-';
strncpy(new_value+1, $2, len-1);
free($2);
$$ = create_value(new_value, VALUE_INT, FALSE, NULL);
}
|
FLOAT_VALUE
{
$$ = create_value($1, VALUE_FLOAT, FALSE, NULL);
}
|
'-' FLOAT_VALUE
{
size_t len = strlen($2) + 2;
char *new_value = malloc(len);
new_value[0] = '-';
strncpy(new_value+1, $2, len-1);
free($2);
$$ = create_value(new_value, VALUE_FLOAT, FALSE, NULL);
}
|
BOOLEAN_VALUE
{
$$ = create_value($1, VALUE_BOOLEAN, FALSE, NULL);

View File

@ -26,6 +26,10 @@ int main(int argc, char **argv) {
q = parse_query("select value from t where c == 5 and b == 6;");
close_query(&q);
// test freeing where conditions
q = parse_query("select -1 * value from t where c == 5 and b == 6;");
close_query(&q);
// test freeing simple query
q = parse_query("select value from t where c == '5';");
close_query(&q);