[postgres] fix timeGroup macro rounding (#12468)

* fix timeGroup tests to check for correct grouping

* do explicit floor rounding in $__timeGroup macro

* fix typo in comments
This commit is contained in:
Sven Klemm
2018-07-01 15:55:46 +02:00
committed by Torkel Ödegaard
parent c03d527d25
commit c2c22c142b
3 changed files with 20 additions and 12 deletions

View File

@ -53,7 +53,7 @@ func TestMacroEngine(t *testing.T) {
sql, err := engine.Interpolate(query, timeRange, "GROUP BY $__timeGroup(time_column,'5m')")
So(err, ShouldBeNil)
So(sql, ShouldEqual, "GROUP BY (extract(epoch from time_column)/300)::bigint*300 AS time")
So(sql, ShouldEqual, "GROUP BY floor(extract(epoch from time_column)/300)*300 AS time")
})
Convey("interpolate __timeGroup function with spaces between args", func() {
@ -61,7 +61,7 @@ func TestMacroEngine(t *testing.T) {
sql, err := engine.Interpolate(query, timeRange, "GROUP BY $__timeGroup(time_column , '5m')")
So(err, ShouldBeNil)
So(sql, ShouldEqual, "GROUP BY (extract(epoch from time_column)/300)::bigint*300 AS time")
So(sql, ShouldEqual, "GROUP BY floor(extract(epoch from time_column)/300)*300 AS time")
})
Convey("interpolate __timeTo function", func() {