Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
97f67ddc
Unverified
Commit
97f67ddc
authored
Apr 10, 2018
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tsdb: improved floating point support when converting sql time column to epoch (ms)
parent
9d84e6f3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
12 deletions
+15
-12
pkg/tsdb/sql_engine_test.go
+9
-6
pkg/tsdb/time_range.go
+6
-6
No files found.
pkg/tsdb/sql_engine_test.go
View file @
97f67ddc
package
tsdb
package
tsdb
import
(
import
(
"fmt"
"testing"
"testing"
"time"
"time"
...
@@ -9,7 +10,7 @@ import (
...
@@ -9,7 +10,7 @@ import (
func
TestSqlEngine
(
t
*
testing
.
T
)
{
func
TestSqlEngine
(
t
*
testing
.
T
)
{
Convey
(
"SqlEngine"
,
t
,
func
()
{
Convey
(
"SqlEngine"
,
t
,
func
()
{
dt
:=
time
.
Date
(
2018
,
3
,
14
,
21
,
20
,
6
,
527e6
,
time
.
UTC
)
dt
:=
time
.
Date
(
2018
,
3
,
14
,
21
,
20
,
6
,
int
(
527345
*
time
.
Microsecond
)
,
time
.
UTC
)
Convey
(
"Given row values with time.Time as time columns"
,
func
()
{
Convey
(
"Given row values with time.Time as time columns"
,
func
()
{
var
nilPointer
*
time
.
Time
var
nilPointer
*
time
.
Time
...
@@ -24,7 +25,7 @@ func TestSqlEngine(t *testing.T) {
...
@@ -24,7 +25,7 @@ func TestSqlEngine(t *testing.T) {
}
}
Convey
(
"When converting them should return epoch time with millisecond precision "
,
func
()
{
Convey
(
"When converting them should return epoch time with millisecond precision "
,
func
()
{
expected
:=
float64
(
dt
.
UnixNano
()
/
1e6
)
expected
:=
float64
(
dt
.
UnixNano
()
)
/
float64
(
time
.
Millisecond
)
So
(
fixtures
[
0
]
.
(
float64
),
ShouldEqual
,
expected
)
So
(
fixtures
[
0
]
.
(
float64
),
ShouldEqual
,
expected
)
So
(
fixtures
[
1
]
.
(
float64
),
ShouldEqual
,
expected
)
So
(
fixtures
[
1
]
.
(
float64
),
ShouldEqual
,
expected
)
So
(
fixtures
[
2
],
ShouldBeNil
)
So
(
fixtures
[
2
],
ShouldBeNil
)
...
@@ -132,8 +133,8 @@ func TestSqlEngine(t *testing.T) {
...
@@ -132,8 +133,8 @@ func TestSqlEngine(t *testing.T) {
})
})
Convey
(
"Given row values with float64 as time columns"
,
func
()
{
Convey
(
"Given row values with float64 as time columns"
,
func
()
{
tSeconds
:=
float64
(
dt
.
Unix
()
)
tSeconds
:=
float64
(
dt
.
Unix
Nano
())
/
float64
(
time
.
Second
)
tMilliseconds
:=
float64
(
dt
.
UnixNano
()
/
1e6
)
tMilliseconds
:=
float64
(
dt
.
UnixNano
()
)
/
float64
(
time
.
Millisecond
)
tNanoSeconds
:=
float64
(
dt
.
UnixNano
())
tNanoSeconds
:=
float64
(
dt
.
UnixNano
())
var
nilPointer
*
float64
var
nilPointer
*
float64
...
@@ -151,10 +152,12 @@ func TestSqlEngine(t *testing.T) {
...
@@ -151,10 +152,12 @@ func TestSqlEngine(t *testing.T) {
}
}
Convey
(
"When converting them should return epoch time with millisecond precision "
,
func
()
{
Convey
(
"When converting them should return epoch time with millisecond precision "
,
func
()
{
So
(
fixtures
[
0
]
.
(
float64
),
ShouldEqual
,
t
Seconds
*
1e3
)
So
(
fixtures
[
0
]
.
(
float64
),
ShouldEqual
,
t
Milliseconds
)
So
(
fixtures
[
1
]
.
(
float64
),
ShouldEqual
,
t
Seconds
*
1e3
)
So
(
fixtures
[
1
]
.
(
float64
),
ShouldEqual
,
t
Milliseconds
)
So
(
fixtures
[
2
]
.
(
float64
),
ShouldEqual
,
tMilliseconds
)
So
(
fixtures
[
2
]
.
(
float64
),
ShouldEqual
,
tMilliseconds
)
So
(
fixtures
[
3
]
.
(
float64
),
ShouldEqual
,
tMilliseconds
)
So
(
fixtures
[
3
]
.
(
float64
),
ShouldEqual
,
tMilliseconds
)
fmt
.
Println
(
fixtures
[
4
]
.
(
float64
))
fmt
.
Println
(
tMilliseconds
)
So
(
fixtures
[
4
]
.
(
float64
),
ShouldEqual
,
tMilliseconds
)
So
(
fixtures
[
4
]
.
(
float64
),
ShouldEqual
,
tMilliseconds
)
So
(
fixtures
[
5
]
.
(
float64
),
ShouldEqual
,
tMilliseconds
)
So
(
fixtures
[
5
]
.
(
float64
),
ShouldEqual
,
tMilliseconds
)
So
(
fixtures
[
6
],
ShouldBeNil
)
So
(
fixtures
[
6
],
ShouldBeNil
)
...
...
pkg/tsdb/time_range.go
View file @
97f67ddc
...
@@ -92,14 +92,14 @@ func (tr *TimeRange) ParseTo() (time.Time, error) {
...
@@ -92,14 +92,14 @@ func (tr *TimeRange) ParseTo() (time.Time, error) {
// EpochPrecisionToMs converts epoch precision to millisecond, if needed.
// EpochPrecisionToMs converts epoch precision to millisecond, if needed.
// Only seconds to milliseconds supported right now
// Only seconds to milliseconds supported right now
func
EpochPrecisionToMs
(
value
float64
)
float64
{
func
EpochPrecisionToMs
(
value
float64
)
float64
{
if
int64
(
value
)
/
1e10
==
0
{
s
:=
strconv
.
FormatFloat
(
value
,
'e'
,
-
1
,
64
)
return
float64
(
value
*
1e3
)
if
strings
.
HasSuffix
(
s
,
"e+09"
)
{
return
value
*
float64
(
1e3
)
}
}
s
:=
strconv
.
FormatFloat
(
value
,
'f'
,
-
1
,
64
)
if
strings
.
HasSuffix
(
s
,
"e+18"
)
{
if
len
(
s
)
==
19
{
return
value
/
float64
(
time
.
Millisecond
)
return
float64
(
value
/
1e6
)
}
}
return
float64
(
value
)
return
value
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment