mirror of
https://github.com/grafana/grafana.git
synced 2025-02-03 12:11:09 -06:00
postgres: tests: improved number->timestamp tests (#81495)
* postgres: tests: nicer values * postgres: tests: add float-to-timestamp tests
This commit is contained in:
parent
2d432d6ff3
commit
ba544e5b33
@ -127,6 +127,8 @@ func TestIntegrationPostgresSnapshots(t *testing.T) {
|
||||
{format: "table", name: "types_other"},
|
||||
{format: "table", name: "timestamp_convert_bigint"},
|
||||
{format: "table", name: "timestamp_convert_integer"},
|
||||
{format: "table", name: "timestamp_convert_real"},
|
||||
{format: "table", name: "timestamp_convert_double"},
|
||||
}
|
||||
|
||||
for _, test := range tt {
|
||||
|
@ -14,9 +14,9 @@
|
||||
// | Labels: | Labels: | Labels: | Labels: |
|
||||
// | Type: []*time.Time | Type: []*time.Time | Type: []*int64 | Type: []*time.Time |
|
||||
// +--------------------------------------+-----------------------------------+---------------------+-----------------------------------+
|
||||
// | 2023-12-24 14:21:27 +0000 UTC | 2023-12-21 12:21:27 +0000 UTC | 1703161287 | 2023-12-21 12:21:52 +0000 UTC |
|
||||
// | 2023-12-24 14:21:27.724 +0000 UTC | 2023-12-21 12:21:27.724 +0000 UTC | 1703161287724 | 2023-12-21 12:21:52.522 +0000 UTC |
|
||||
// | 2023-12-24 14:21:27.724919 +0000 UTC | 2023-12-21 12:21:27.724 +0000 UTC | 1703161287724919000 | 2023-12-21 12:21:52.522 +0000 UTC |
|
||||
// | 2023-12-21 12:21:27 +0000 UTC | 2023-12-21 12:21:27 +0000 UTC | 1703161287 | 2023-12-21 12:21:52 +0000 UTC |
|
||||
// | 2023-12-21 12:21:27.724 +0000 UTC | 2023-12-21 12:21:27.724 +0000 UTC | 1703161287724 | 2023-12-21 12:21:52.522 +0000 UTC |
|
||||
// | 2023-12-21 12:21:27.724919 +0000 UTC | 2023-12-21 12:21:27.724 +0000 UTC | 1703161287724919000 | 2023-12-21 12:21:52.522 +0000 UTC |
|
||||
// | null | null | null | null |
|
||||
// +--------------------------------------+-----------------------------------+---------------------+-----------------------------------+
|
||||
//
|
||||
@ -72,9 +72,9 @@
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
1703427687000,
|
||||
1703427687724,
|
||||
1703427687724,
|
||||
1703161287000,
|
||||
1703161287724,
|
||||
1703161287724,
|
||||
null
|
||||
],
|
||||
[
|
||||
|
@ -8,7 +8,7 @@ CREATE TEMPORARY TABLE tbl (
|
||||
);
|
||||
|
||||
INSERT INTO tbl (reallyt, "time", n, timeend) VALUES
|
||||
('2023-12-24T14:21:27 UTC', 1703161287, 1703161287, 1703161312),
|
||||
('2023-12-24T14:21:27.724 UTC', 1703161287724, 1703161287724, 1703161312522),
|
||||
('2023-12-24T14:21:27.724919 UTC', 1703161287724919000, 1703161287724919000, 1703161312522186000),
|
||||
('2023-12-21T12:21:27 UTC', 1703161287, 1703161287, 1703161312),
|
||||
('2023-12-21T12:21:27.724 UTC', 1703161287724, 1703161287724, 1703161312522),
|
||||
('2023-12-21T12:21:27.724919 UTC', 1703161287724919000, 1703161287724919000, 1703161312522186000),
|
||||
(NULL, NULL, NULL, NULL);
|
113
pkg/tsdb/grafana-postgresql-datasource/testdata/table/timestamp_convert_double.golden.jsonc
vendored
Normal file
113
pkg/tsdb/grafana-postgresql-datasource/testdata/table/timestamp_convert_double.golden.jsonc
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
//
|
||||
// Frame[0] {
|
||||
// "typeVersion": [
|
||||
// 0,
|
||||
// 0
|
||||
// ],
|
||||
// "executedQueryString": "SELECT * FROM tbl"
|
||||
// }
|
||||
// Name:
|
||||
// Dimensions: 4 Fields by 4 Rows
|
||||
// +--------------------------------------+-----------------------------------+-----------------------+-----------------------------------+
|
||||
// | Name: reallyt | Name: time | Name: n | Name: timeend |
|
||||
// | Labels: | Labels: | Labels: | Labels: |
|
||||
// | Type: []*time.Time | Type: []*time.Time | Type: []*float64 | Type: []*time.Time |
|
||||
// +--------------------------------------+-----------------------------------+-----------------------+-----------------------------------+
|
||||
// | 2023-12-21 12:21:27 +0000 UTC | 2023-12-21 12:21:27 +0000 UTC | 1.703161287e+09 | 2023-12-21 12:21:52 +0000 UTC |
|
||||
// | 2023-12-21 12:21:27.724 +0000 UTC | 2023-12-21 12:21:27.724 +0000 UTC | 1.703161287724e+12 | 2023-12-21 12:21:52.522 +0000 UTC |
|
||||
// | 2023-12-21 12:21:27.724919 +0000 UTC | 2023-12-21 12:21:27.724 +0000 UTC | 1.703161287724919e+18 | 2023-12-21 12:21:52.522 +0000 UTC |
|
||||
// | null | null | null | null |
|
||||
// +--------------------------------------+-----------------------------------+-----------------------+-----------------------------------+
|
||||
//
|
||||
//
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
{
|
||||
"status": 200,
|
||||
"frames": [
|
||||
{
|
||||
"schema": {
|
||||
"meta": {
|
||||
"typeVersion": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"executedQueryString": "SELECT * FROM tbl"
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"name": "reallyt",
|
||||
"type": "time",
|
||||
"typeInfo": {
|
||||
"frame": "time.Time",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "time",
|
||||
"type": "time",
|
||||
"typeInfo": {
|
||||
"frame": "time.Time",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "n",
|
||||
"type": "number",
|
||||
"typeInfo": {
|
||||
"frame": "float64",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "timeend",
|
||||
"type": "time",
|
||||
"typeInfo": {
|
||||
"frame": "time.Time",
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
1703161287000,
|
||||
1703161287724,
|
||||
1703161287724,
|
||||
null
|
||||
],
|
||||
[
|
||||
1703161287000,
|
||||
1703161287724,
|
||||
1703161287724,
|
||||
null
|
||||
],
|
||||
[
|
||||
1703161287,
|
||||
1703161287724,
|
||||
1703161287724919000,
|
||||
null
|
||||
],
|
||||
[
|
||||
1703161312000,
|
||||
1703161312522,
|
||||
1703161312522,
|
||||
null
|
||||
]
|
||||
],
|
||||
"nanos": [
|
||||
[
|
||||
0,
|
||||
0,
|
||||
919000,
|
||||
0
|
||||
],
|
||||
null,
|
||||
null,
|
||||
null
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
14
pkg/tsdb/grafana-postgresql-datasource/testdata/table/timestamp_convert_double.sql
vendored
Normal file
14
pkg/tsdb/grafana-postgresql-datasource/testdata/table/timestamp_convert_double.sql
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
-- SELECT * FROM tbl
|
||||
-- the time-field and time-end field gets converted to time.Time
|
||||
CREATE TEMPORARY TABLE tbl (
|
||||
reallyt timestamp with time zone, -- reference real timestamp
|
||||
"time" double precision,
|
||||
n double precision, -- normal number, it should not get converted to a timestamp
|
||||
timeend bigint
|
||||
);
|
||||
|
||||
INSERT INTO tbl (reallyt, "time", n, timeend) VALUES
|
||||
('2023-12-21T12:21:27 UTC', 1703161287, 1703161287, 1703161312),
|
||||
('2023-12-21T12:21:27.724 UTC', 1703161287724, 1703161287724, 1703161312522),
|
||||
('2023-12-21T12:21:27.724919 UTC', 1703161287724919000, 1703161287724919000, 1703161312522186000),
|
||||
(NULL, NULL, NULL, NULL);
|
@ -14,7 +14,7 @@
|
||||
// | Labels: | Labels: | Labels: | Labels: |
|
||||
// | Type: []*time.Time | Type: []*time.Time | Type: []*int32 | Type: []*time.Time |
|
||||
// +-------------------------------+-------------------------------+----------------+-------------------------------+
|
||||
// | 2023-12-24 14:21:27 +0000 UTC | 2023-12-21 12:21:27 +0000 UTC | 1703161287 | 2023-12-21 12:21:52 +0000 UTC |
|
||||
// | 2023-12-21 12:21:27 +0000 UTC | 2023-12-21 12:21:27 +0000 UTC | 1703161287 | 2023-12-21 12:21:52 +0000 UTC |
|
||||
// | null | null | null | null |
|
||||
// +-------------------------------+-------------------------------+----------------+-------------------------------+
|
||||
//
|
||||
@ -70,7 +70,7 @@
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
1703427687000,
|
||||
1703161287000,
|
||||
null
|
||||
],
|
||||
[
|
||||
|
@ -8,5 +8,5 @@ CREATE TEMPORARY TABLE tbl (
|
||||
);
|
||||
|
||||
INSERT INTO tbl (reallyt, "time", n, timeend) VALUES
|
||||
('2023-12-24T14:21:27 UTC', 1703161287, 1703161287, 1703161312),
|
||||
('2023-12-21T12:21:27 UTC', 1703161287, 1703161287, 1703161312),
|
||||
(NULL, NULL, NULL, NULL);
|
113
pkg/tsdb/grafana-postgresql-datasource/testdata/table/timestamp_convert_real.golden.jsonc
vendored
Normal file
113
pkg/tsdb/grafana-postgresql-datasource/testdata/table/timestamp_convert_real.golden.jsonc
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
//
|
||||
// Frame[0] {
|
||||
// "typeVersion": [
|
||||
// 0,
|
||||
// 0
|
||||
// ],
|
||||
// "executedQueryString": "SELECT * FROM tbl"
|
||||
// }
|
||||
// Name:
|
||||
// Dimensions: 4 Fields by 4 Rows
|
||||
// +--------------------------------------+-------------------------------+------------------+-----------------------------------+
|
||||
// | Name: reallyt | Name: time | Name: n | Name: timeend |
|
||||
// | Labels: | Labels: | Labels: | Labels: |
|
||||
// | Type: []*time.Time | Type: []*time.Time | Type: []*float64 | Type: []*time.Time |
|
||||
// +--------------------------------------+-------------------------------+------------------+-----------------------------------+
|
||||
// | 2023-12-21 12:21:27 +0000 UTC | 2023-12-21 12:21:40 +0000 UTC | 1.7031613e+09 | 2023-12-21 12:21:52 +0000 UTC |
|
||||
// | 2023-12-21 12:21:27.724 +0000 UTC | 2023-12-21 12:20:00 +0000 UTC | 1.7031612e+12 | 2023-12-21 12:21:52.522 +0000 UTC |
|
||||
// | 2023-12-21 12:21:27.724919 +0000 UTC | 2023-12-21 12:20:00 +0000 UTC | 1.7031612e+18 | 2023-12-21 12:21:52.522 +0000 UTC |
|
||||
// | null | null | null | null |
|
||||
// +--------------------------------------+-------------------------------+------------------+-----------------------------------+
|
||||
//
|
||||
//
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
{
|
||||
"status": 200,
|
||||
"frames": [
|
||||
{
|
||||
"schema": {
|
||||
"meta": {
|
||||
"typeVersion": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"executedQueryString": "SELECT * FROM tbl"
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"name": "reallyt",
|
||||
"type": "time",
|
||||
"typeInfo": {
|
||||
"frame": "time.Time",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "time",
|
||||
"type": "time",
|
||||
"typeInfo": {
|
||||
"frame": "time.Time",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "n",
|
||||
"type": "number",
|
||||
"typeInfo": {
|
||||
"frame": "float64",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "timeend",
|
||||
"type": "time",
|
||||
"typeInfo": {
|
||||
"frame": "time.Time",
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
1703161287000,
|
||||
1703161287724,
|
||||
1703161287724,
|
||||
null
|
||||
],
|
||||
[
|
||||
1703161300000,
|
||||
1703161200000,
|
||||
1703161200000,
|
||||
null
|
||||
],
|
||||
[
|
||||
1703161300,
|
||||
1703161200000,
|
||||
1703161200000000000,
|
||||
null
|
||||
],
|
||||
[
|
||||
1703161312000,
|
||||
1703161312522,
|
||||
1703161312522,
|
||||
null
|
||||
]
|
||||
],
|
||||
"nanos": [
|
||||
[
|
||||
0,
|
||||
0,
|
||||
919000,
|
||||
0
|
||||
],
|
||||
null,
|
||||
null,
|
||||
null
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
14
pkg/tsdb/grafana-postgresql-datasource/testdata/table/timestamp_convert_real.sql
vendored
Normal file
14
pkg/tsdb/grafana-postgresql-datasource/testdata/table/timestamp_convert_real.sql
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
-- SELECT * FROM tbl
|
||||
-- the time-field and time-end field gets converted to time.Time
|
||||
CREATE TEMPORARY TABLE tbl (
|
||||
reallyt timestamp with time zone, -- reference real timestamp
|
||||
"time" real,
|
||||
n real, -- normal number, it should not get converted to a timestamp
|
||||
timeend bigint
|
||||
);
|
||||
|
||||
INSERT INTO tbl (reallyt, "time", n, timeend) VALUES
|
||||
('2023-12-21T12:21:27 UTC', 1703161287, 1703161287, 1703161312),
|
||||
('2023-12-21T12:21:27.724 UTC', 1703161287724, 1703161287724, 1703161312522),
|
||||
('2023-12-21T12:21:27.724919 UTC', 1703161287724919000, 1703161287724919000, 1703161312522186000),
|
||||
(NULL, NULL, NULL, NULL);
|
Loading…
Reference in New Issue
Block a user