Commit d56c5285 by Ricky Putra Committed by GitHub

Postgres: Fix timeGroup macro converts long intervals to invalid numbers when…

Postgres: Fix timeGroup macro converts long intervals to invalid numbers when TimescaleDB is enabled (#31179)

Fixes #27253
parent 9c08b34e
...@@ -107,7 +107,7 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string, ...@@ -107,7 +107,7 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string,
} }
if m.timescaledb { if m.timescaledb {
return fmt.Sprintf("time_bucket('%vs',%s)", interval.Seconds(), args[0]), nil return fmt.Sprintf("time_bucket('%.0fs',%s)", interval.Seconds(), args[0]), nil
} }
return fmt.Sprintf( return fmt.Sprintf(
......
...@@ -104,6 +104,13 @@ func TestMacroEngine(t *testing.T) { ...@@ -104,6 +104,13 @@ func TestMacroEngine(t *testing.T) {
So(sql, ShouldEqual, "GROUP BY time_bucket('300s',time_column)") So(sql, ShouldEqual, "GROUP BY time_bucket('300s',time_column)")
}) })
Convey("interpolate __timeGroup function with large time range as an argument and TimescaleDB enabled", func() {
sql, err := engineTS.Interpolate(query, timeRange, "GROUP BY $__timeGroup(time_column , '12d')")
So(err, ShouldBeNil)
So(sql, ShouldEqual, "GROUP BY time_bucket('1036800s',time_column)")
})
Convey("interpolate __unixEpochFilter function", func() { Convey("interpolate __unixEpochFilter function", func() {
sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilter(time)") sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilter(time)")
So(err, ShouldBeNil) So(err, ShouldBeNil)
......
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