Commit af626466 by Marcus Efraimsson

mysql: fix precision for time columns in time series query mode

parent 5c120c2c
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"math" "math"
"reflect" "reflect"
"strconv" "strconv"
"time"
"github.com/go-sql-driver/mysql" "github.com/go-sql-driver/mysql"
"github.com/go-xorm/core" "github.com/go-xorm/core"
...@@ -239,15 +238,18 @@ func (e MysqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core. ...@@ -239,15 +238,18 @@ func (e MysqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
return err return err
} }
// converts column named time to unix timestamp in milliseconds to make
// native mysql datetime types and epoch dates work in
// annotation and table queries.
tsdb.ConvertSqlTimeColumnToEpochMs(values, timeIndex)
switch columnValue := values[timeIndex].(type) { switch columnValue := values[timeIndex].(type) {
case int64: case int64:
timestamp = float64(columnValue * 1000) timestamp = float64(columnValue)
case float64: case float64:
timestamp = columnValue * 1000 timestamp = columnValue
case time.Time:
timestamp = float64(columnValue.UnixNano() / 1e6)
default: default:
return fmt.Errorf("Invalid type for column time, must be of type timestamp or unix timestamp, got: %T %v", columnValue, columnValue) return fmt.Errorf("Invalid type for column time/time_sec, must be of type timestamp or unix timestamp, got: %T %v", columnValue, columnValue)
} }
if metricIndex >= 0 { if metricIndex >= 0 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment