fix #37. Support the negation of the regex matcher !~

pull/47/head
John Shahid 2013-11-11 18:52:19 -05:00
parent 8d9b2ecda0
commit e1325ac8e1
5 changed files with 40 additions and 1 deletions

View File

@ -89,6 +89,8 @@
### Features
- [Issue #37](https://github.com/influxdb/influxdb/issues/37). Support the negation of the regex matcher !~
### Bugfixes
- [Issue #36](https://github.com/influxdb/influxdb/issues/36). The regex operator should be =~ not ~=

View File

@ -19,6 +19,7 @@ func init() {
registeredOperators["<"] = not(GreaterThanOrEqualOperator)
registeredOperators["<="] = not(GreaterThanOperator)
registeredOperators["=~"] = RegexMatcherOperator
registeredOperators["!~"] = not(RegexMatcherOperator)
}
func not(op BooleanOperation) BooleanOperation {

View File

@ -113,6 +113,30 @@ func (self *FilteringSuite) TestRegexFiltering(c *C) {
c.Assert(*result.Points[0].Values[0].StringValue, Equals, "foobar")
}
func (self *FilteringSuite) TestNotRegexFiltering(c *C) {
queryStr := "select * from t where column_one !~ /.*foo.*/ and time > now() - 1d;"
query, err := parser.ParseQuery(queryStr)
c.Assert(err, IsNil)
series, err := common.StringToSeriesArray(`
[
{
"points": [
{"values": [{"string_value": "100"}], "timestamp": 1381346631, "sequence_number": 1},
{"values": [{"string_value": "foobar"}], "timestamp": 1381346631, "sequence_number": 1}
],
"name": "t",
"fields": ["column_one"]
}
]
`)
c.Assert(err, IsNil)
result, err := Filter(query, series[0])
c.Assert(err, IsNil)
c.Assert(result, NotNil)
c.Assert(result.Points, HasLen, 1)
c.Assert(*result.Points[0].Values[0].StringValue, Equals, "100")
}
func (self *FilteringSuite) TestInequalityFiltering(c *C) {
queryStr := "select * from t where column_one >= 100 and column_two > 6 and time > now() - 1d;"
query, err := parser.ParseQuery(queryStr)

View File

@ -46,6 +46,7 @@ static int yycolumn = 1;
"or" { return OR; }
"==" { yylval->string = strdup(yytext); return OPERATION_EQUAL; }
"=~" { yylval->string = strdup(yytext); return REGEX_OP; }
"!~" { yylval->string = strdup(yytext); return NEGATION_REGEX_OP; }
"!=" { yylval->string = strdup(yytext); return OPERATION_NE; }
"<" { yylval->string = strdup(yytext); return OPERATION_LT; }
">" { yylval->string = strdup(yytext); return OPERATION_GT; }

View File

@ -61,7 +61,7 @@ value *create_value(char *name, int type, char is_case_insensitive, value_array
// define types of tokens (terminals)
%token SELECT FROM WHERE EQUAL GROUP BY FIRST LAST LIMIT ORDER ASC DESC MERGE INNER JOIN
%token <string> STRING_VALUE INT_VALUE FLOAT_VALUE TABLE_NAME SIMPLE_NAME REGEX_OP REGEX_STRING INSENSITIVE_REGEX_STRING DURATION
%token <string> STRING_VALUE INT_VALUE FLOAT_VALUE TABLE_NAME SIMPLE_NAME REGEX_OP NEGATION_REGEX_OP REGEX_STRING INSENSITIVE_REGEX_STRING DURATION
// define the precedence of these operators
%left OR
@ -385,6 +385,17 @@ BOOL_EXPRESSION:
$$->right->op = '\0';
$$->right->right = NULL;
}
|
EXPRESSION NEGATION_REGEX_OP REGEX_VALUE
{
$$ = malloc(sizeof(bool_expression));
$$->left = $1;
$$->op = $2;
$$->right = malloc(sizeof(expression));
$$->right->left = $3;
$$->right->op = '\0';
$$->right->right = NULL;
}
CONDITION:
BOOL_EXPRESSION