mirror of
https://github.com/grafana/grafana.git
synced 2025-09-23 16:43:35 +08:00
Nanosecond timestamp support postgresql
This commit is contained in:
@ -122,6 +122,11 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string,
|
|||||||
return "", fmt.Errorf("missing time column argument for macro %v", name)
|
return "", fmt.Errorf("missing time column argument for macro %v", name)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsSecondsEpoch(), args[0], m.timeRange.GetToAsSecondsEpoch()), nil
|
return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsSecondsEpoch(), args[0], m.timeRange.GetToAsSecondsEpoch()), nil
|
||||||
|
case "__unixEpochFilterNano":
|
||||||
|
if len(args) == 0 {
|
||||||
|
return "", fmt.Errorf("missing time column argument for macro %v", name)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsTimeUTC().UnixNano(), args[0], m.timeRange.GetToAsTimeUTC().UnixNano()), nil
|
||||||
case "__unixEpochGroup":
|
case "__unixEpochGroup":
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
return "", fmt.Errorf("macro %v needs time column and interval and optional fill value", name)
|
return "", fmt.Errorf("macro %v needs time column and interval and optional fill value", name)
|
||||||
|
@ -115,6 +115,12 @@ func TestMacroEngine(t *testing.T) {
|
|||||||
|
|
||||||
So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix()))
|
So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix()))
|
||||||
})
|
})
|
||||||
|
Convey("interpolate __unixEpochFilterNano function", func() {
|
||||||
|
sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilterNano(time)")
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano()))
|
||||||
|
})
|
||||||
|
|
||||||
Convey("interpolate __unixEpochGroup function", func() {
|
Convey("interpolate __unixEpochGroup function", func() {
|
||||||
|
|
||||||
@ -147,6 +153,12 @@ func TestMacroEngine(t *testing.T) {
|
|||||||
|
|
||||||
So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix()))
|
So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix()))
|
||||||
})
|
})
|
||||||
|
Convey("interpolate __unixEpochFilterNano function", func() {
|
||||||
|
sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilterNano(time)")
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano()))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Given a time range between 1960-02-01 07:00 and 1980-02-03 08:00", func() {
|
Convey("Given a time range between 1960-02-01 07:00 and 1980-02-03 08:00", func() {
|
||||||
@ -167,6 +179,12 @@ func TestMacroEngine(t *testing.T) {
|
|||||||
|
|
||||||
So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix()))
|
So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix()))
|
||||||
})
|
})
|
||||||
|
Convey("interpolate __unixEpochFilterNano function", func() {
|
||||||
|
sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilterNano(time)")
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano()))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user