Skip to content

Commit

Permalink
fix #37. Support the negation of the regex matcher !~
Browse files Browse the repository at this point in the history
  • Loading branch information
jvshahid committed Nov 11, 2013
1 parent 8d9b2ec commit e1325ac
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ~=
1 change: 1 addition & 0 deletions src/datastore/boolean_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func init() {
registeredOperators["<"] = not(GreaterThanOrEqualOperator)
registeredOperators["<="] = not(GreaterThanOperator)
registeredOperators["=~"] = RegexMatcherOperator
registeredOperators["!~"] = not(RegexMatcherOperator)
}

func not(op BooleanOperation) BooleanOperation {
Expand Down
24 changes: 24 additions & 0 deletions src/datastore/filtering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/parser/query.lex
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
13 changes: 12 additions & 1 deletion src/parser/query.yacc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e1325ac

Please sign in to comment.