New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

max() and min() get weird with large integer values #3130

Closed
desa opened this Issue Jun 24, 2015 · 2 comments

Comments

Projects
None yet
4 participants
@desa
Member

desa commented Jun 24, 2015

On OSX with influx version 0.9 built from source

Playing around with large integer values, I got some weird results:

Adding largest signed 64-bit integer

> insert large value=9223372036854775807
> select min(value) from large
name: large
-----------
time            min
1970-01-01T00:00:00Z    -9223372036854775808

Gradually decreasing the number:

> insert large value=9223372036854775700
> select min(value) from large
name: large
-----------
time            min
1970-01-01T00:00:00Z    -9223372036854775808

Til things get even weirder:

> insert large value=922337203685477570
> select min(value) from large
name: large
-----------
time            min
1970-01-01T00:00:00Z    922337203685477632
> insert large value=922337203685477560
> select min(value) from large
name: large
-----------
time            min
1970-01-01T00:00:00Z    922337203685477504

The returned min is always off by a little.

> select * from large
name: large
-----------
time                value
2015-06-24T21:24:42.658912887Z  9223372036854775807
2015-06-24T21:26:03.033411599Z  9223372036854775700
2015-06-24T21:27:13.4970835Z    922337203685477570
2015-06-24T21:27:51.591725309Z  922337203685477560
@jbcrail

This comment has been minimized.

Show comment
Hide comment
@jbcrail

jbcrail Jun 28, 2015

Contributor

I've identified why and where this bug occurs, but I don't have a fix since I'm not familiar enough with the code base. I've attached sample code to simulate the behavior.

package main

import (
    "fmt"
)

// ReduceMin/ReduceMax in influxql/functions.go shoehorns all numeric
// values into float64
func testMinimum(n int64) int64 {
    return int64(float64(n))
}

func main() {
    values := []int64{
        9223372036854775807,
        9223372036854775700,
        922337203685477570,
        922337203685477560,
    }
    for _, value := range values {
        fmt.Printf("%v becomes %v\n", value, testMinimum(value))
    }
}

This is the output:

9223372036854775807 becomes -9223372036854775808
9223372036854775700 becomes -9223372036854775808
922337203685477570 becomes 922337203685477632
922337203685477560 becomes 922337203685477504
Contributor

jbcrail commented Jun 28, 2015

I've identified why and where this bug occurs, but I don't have a fix since I'm not familiar enough with the code base. I've attached sample code to simulate the behavior.

package main

import (
    "fmt"
)

// ReduceMin/ReduceMax in influxql/functions.go shoehorns all numeric
// values into float64
func testMinimum(n int64) int64 {
    return int64(float64(n))
}

func main() {
    values := []int64{
        9223372036854775807,
        9223372036854775700,
        922337203685477570,
        922337203685477560,
    }
    for _, value := range values {
        fmt.Printf("%v becomes %v\n", value, testMinimum(value))
    }
}

This is the output:

9223372036854775807 becomes -9223372036854775808
9223372036854775700 becomes -9223372036854775808
922337203685477570 becomes 922337203685477632
922337203685477560 becomes 922337203685477504

@beckettsean beckettsean added this to the 0.9.3 milestone Jul 15, 2015

@beckettsean beckettsean modified the milestones: Next Point Release, 0.9.3 Aug 6, 2015

@jsternberg

This comment has been minimized.

Show comment
Hide comment
@jsternberg

jsternberg Apr 6, 2016

Contributor

This seems to be fixed in the new query engine and TSM. I'm not sure exactly where the fix came from, but this works:

Connected to http://localhost:8086 version unknown
InfluxDB shell 0.9
> create database mydb
> use mydb
Using database mydb
> insert large value=9223372036854775807
> select min(value) from large
name: large
-----------
time    min
0       9.223372036854776e+18

> insert largei value=9223372036854775807i
> select min(value) from largei
name: largei
------------
time    min
0       9223372036854775807
Contributor

jsternberg commented Apr 6, 2016

This seems to be fixed in the new query engine and TSM. I'm not sure exactly where the fix came from, but this works:

Connected to http://localhost:8086 version unknown
InfluxDB shell 0.9
> create database mydb
> use mydb
Using database mydb
> insert large value=9223372036854775807
> select min(value) from large
name: large
-----------
time    min
0       9.223372036854776e+18

> insert largei value=9223372036854775807i
> select min(value) from largei
name: largei
------------
time    min
0       9223372036854775807
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment