Skip to content

Commit

Permalink
Parse big int in query's where clause properly
Browse files Browse the repository at this point in the history
Fix #964
  • Loading branch information
jvshahid committed Sep 23, 2014
1 parent 059d308 commit de68a38
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
11 changes: 8 additions & 3 deletions engine/filtering_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ func getExpressionValue(values []*parser.Value, fields []string, point *protocol
switch value.Type {
case parser.ValueFunctionCall:
return nil, fmt.Errorf("Cannot process function call %s in expression", value.Name)
case parser.ValueInt:
value, err := strconv.ParseInt(value.Name, 10, 64)
if err == nil {
fieldValues = append(fieldValues, &protocol.FieldValue{Int64Value: &value})
continue
}
// an error will happen only if the integer is out of range
fallthrough
case parser.ValueFloat:
value, _ := strconv.ParseFloat(value.Name, 64)
fieldValues = append(fieldValues, &protocol.FieldValue{DoubleValue: &value})
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})
Expand Down
30 changes: 30 additions & 0 deletions integration/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,36 @@ func (self *DataTestSuite) TestFillingEntireRange(c *C) {
}
}

func (self *DataTestSuite) TestBigInts(c *C) {
data := `
[
{
"name": "test_mode",
"columns": ["value"],
"points": [
[7335093126128605887],
[15028546720250474530]
]
}
]`
self.client.WriteJsonData(data, c, influxdb.Millisecond)
for _, i := range []uint64{7335093126128605887, 15028546720250474530} {
q := fmt.Sprintf("select count(value) from test_mode where value = %d", i)
serieses := self.client.RunQuery(q, c, "m")
c.Assert(serieses, HasLen, 1)
maps := ToMap(serieses[0])
c.Assert(maps, HasLen, 1)
c.Assert(maps[0]["count"], Equals, 1.0)
}

q := "select count(value) from test_mode where value >= 15028546720250474530 and value <= 15028546720250474530"
serieses := self.client.RunQuery(q, c, "m")
c.Assert(serieses, HasLen, 1)
maps := ToMap(serieses[0])
c.Assert(maps, HasLen, 1)
c.Assert(maps[0]["count"], Equals, 1.0)
}

func (self *DataTestSuite) TestModeWithInt(c *C) {
data := `
[
Expand Down

0 comments on commit de68a38

Please sign in to comment.