Skip to content

Commit

Permalink
Merge pull request #379 from influxdb/fix-379-boolean-columns-where-c…
Browse files Browse the repository at this point in the history
…onditions

boolean attribute in where clause
  • Loading branch information
jvshahid committed Mar 31, 2014
2 parents f76762d + d369e51 commit 8c5bb2a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/engine/filtering.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func getExpressionValue(values []*parser.Value, fields []string, point *protocol
case parser.ValueInt:
value, _ := strconv.ParseInt(value.Name, 10, 64)
fieldValues = append(fieldValues, &protocol.FieldValue{Int64Value: &value})
case parser.ValueBool:
value, _ := strconv.ParseBool(value.Name)
fieldValues = append(fieldValues, &protocol.FieldValue{BoolValue: &value})
case parser.ValueString, parser.ValueRegex:
fieldValues = append(fieldValues, &protocol.FieldValue{StringValue: &value.Name})

Expand Down
21 changes: 21 additions & 0 deletions src/integration/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,27 @@ func (self *IntegrationSuite) TestSinglePointSelectWithNullValues(c *C) {
}
}

func (self *IntegrationSuite) TestBooleanColumnsWorkWithWhereQuery(c *C) {
err := self.server.WriteData(`
[
{
"name": "test_boolean_columns_where",
"columns": ["a"],
"points":[[true], [false], [true]]
}
]`)
c.Assert(err, IsNil)

bs, err := self.server.RunQuery("select count(a) from test_boolean_columns_where where a = true", "m")
c.Assert(err, IsNil)
data := []*SerializedSeries{}
err = json.Unmarshal(bs, &data)
c.Assert(err, IsNil)
c.Assert(data, HasLen, 1)
c.Assert(data[0].Points, HasLen, 1)
c.Assert(data[0].Points[0][1], Equals, 2.0)
}

func (self *IntegrationSuite) TestColumnsWithOnlySomeValuesWorkWithWhereQuery(c *C) {
err := self.server.WriteData(`
[
Expand Down
1 change: 1 addition & 0 deletions src/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ValueType int
const (
ValueRegex ValueType = C.VALUE_REGEX
ValueInt = C.VALUE_INT
ValueBool = C.VALUE_BOOLEAN
ValueFloat = C.VALUE_FLOAT
ValueString = C.VALUE_STRING
ValueIntoName = C.VALUE_INTO_NAME
Expand Down
2 changes: 2 additions & 0 deletions src/parser/query.lex
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ static int yycolumn = 1;

[0-9]*\.[0-9]+|[0-9]+\.[0-9]* { yylval->string = strdup(yytext); return FLOAT_VALUE; }

true|false { yylval->string = strdup(yytext); return BOOLEAN_VALUE; }

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

[a-zA-Z0-9_][a-zA-Z0-9._-]* { yylval->string = strdup(yytext); return TABLE_NAME; }
Expand Down
7 changes: 6 additions & 1 deletion src/parser/query.yacc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ value *create_expression_value(char *operator, size_t size, ...) {

// define types of tokens (terminals)
%token SELECT DELETE FROM WHERE EQUAL GROUP BY LIMIT ORDER ASC DESC MERGE INNER JOIN AS LIST SERIES INTO CONTINUOUS_QUERIES CONTINUOUS_QUERY DROP DROP_SERIES EXPLAIN
%token <string> STRING_VALUE INT_VALUE FLOAT_VALUE TABLE_NAME SIMPLE_NAME INTO_NAME REGEX_OP
%token <string> STRING_VALUE INT_VALUE FLOAT_VALUE BOOLEAN_VALUE TABLE_NAME SIMPLE_NAME INTO_NAME REGEX_OP
%token <string> NEGATION_REGEX_OP REGEX_STRING INSENSITIVE_REGEX_STRING DURATION

// define the precedence of these operators
Expand Down Expand Up @@ -435,6 +435,11 @@ VALUE:
$$ = create_value($1, VALUE_FLOAT, FALSE, NULL);
}
|
BOOLEAN_VALUE
{
$$ = create_value($1, VALUE_BOOLEAN, FALSE, NULL);
}
|
DURATION_VALUE
{
$$ = $1;
Expand Down
1 change: 1 addition & 0 deletions src/parser/query_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct value_t {
VALUE_REGEX,
VALUE_INT,
VALUE_FLOAT,
VALUE_BOOLEAN,
VALUE_STRING,
VALUE_INTO_NAME,
VALUE_TABLE_NAME,
Expand Down

0 comments on commit 8c5bb2a

Please sign in to comment.