Skip to content

Commit

Permalink
Support int64 data types
Browse files Browse the repository at this point in the history
  • Loading branch information
otoolep committed Apr 13, 2015
1 parent 0a38117 commit c292364
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Bugfixes
- [#2255](https://github.com/influxdb/influxdb/pull/2255): Fix panic when changing default retention policy.
- [#2261](https://github.com/influxdb/influxdb/pull/2261): Support int64 value types.

## v0.9.0-rc23 [2015-04-11]

Expand Down
26 changes: 15 additions & 11 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,17 +780,14 @@ func (f *FieldCodec) EncodeFields(values map[string]interface{}) ([]byte, error)
var buf []byte

switch field.Type {
case influxql.Number:
var value float64
// Convert integers to floats.
if intval, ok := v.(int); ok {
value = float64(intval)
} else {
value = v.(float64)
}

case influxql.Float:
value := v.(float64)
buf = make([]byte, 9)
binary.BigEndian.PutUint64(buf[1:9], math.Float64bits(value))
case influxql.Integer:
value := v.(int64)
buf = make([]byte, 9)
binary.BigEndian.PutUint64(buf[1:9], uint64(value))
case influxql.Boolean:
value := v.(bool)

Expand Down Expand Up @@ -850,10 +847,13 @@ func (f *FieldCodec) DecodeByID(targetID uint8, b []byte) (interface{}, error) {

var value interface{}
switch field.Type {
case influxql.Number:
case influxql.Float:
// Move bytes forward.
value = math.Float64frombits(binary.BigEndian.Uint64(b[1:9]))
b = b[9:]
case influxql.Integer:
value = int64(binary.BigEndian.Uint16(b[1:9]))
b = b[9:]
case influxql.Boolean:
if b[1] == 1 {
value = true
Expand Down Expand Up @@ -904,10 +904,14 @@ func (f *FieldCodec) DecodeFields(b []byte) (map[uint8]interface{}, error) {

var value interface{}
switch field.Type {
case influxql.Number:
case influxql.Float:
value = math.Float64frombits(binary.BigEndian.Uint64(b[1:9]))
// Move bytes forward.
b = b[9:]
case influxql.Integer:
value = int64(binary.BigEndian.Uint64(b[1:9]))
// Move bytes forward.
b = b[9:]
case influxql.Boolean:
if b[1] == 1 {
value = true
Expand Down
12 changes: 7 additions & 5 deletions influxql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ type DataType string
const (
// Unknown primitive data type.
Unknown = DataType("")
// Number means the data type is an int or float.
Number = DataType("number")
// Float means the data type is a float
Float = DataType("float")
// Integer means the data type is a integer
Integer = DataType("integer")
// Boolean means the data type is a boolean.
Boolean = DataType("boolean")
// String means the data type is a string of text.
Expand All @@ -33,9 +35,9 @@ const (
func InspectDataType(v interface{}) DataType {
switch v.(type) {
case float64:
return Number
case int:
return Number
return Float
case int64, int32, int:
return Integer
case bool:
return Boolean
case string:
Expand Down

0 comments on commit c292364

Please sign in to comment.