mirror of
https://github.com/grafana/grafana.git
synced 2025-01-15 19:22:34 -06:00
PostgreSQL: __unixEpochGroup to support arithmetic expression as argument (#46764)
* __unixEpochGroup to support arithmetic argument Following call generates wrong expression : $__unixEpochGroupAlias(height+42,$__interval) => floor(height+42/60)*60 AS "time" instead of => floor((height+42)/60)*60 AS "time" * Update test of __unixEpochGroup related to issue #46764
This commit is contained in:
parent
7bc821baf2
commit
f4b6c4019c
@ -146,7 +146,7 @@ func (m *postgresMacroEngine) evaluateMacro(timeRange backend.TimeRange, query *
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("floor(%s/%v)*%v", args[0], interval.Seconds(), interval.Seconds()), nil
|
||||
return fmt.Sprintf("floor((%s)/%v)*%v", args[0], interval.Seconds(), interval.Seconds()), nil
|
||||
case "__unixEpochGroupAlias":
|
||||
tg, err := m.evaluateMacro(timeRange, query, "__unixEpochGroup", args)
|
||||
if err == nil {
|
||||
|
@ -137,11 +137,11 @@ func TestMacroEngine(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("interpolate __unixEpochGroup function", func(t *testing.T) {
|
||||
sql, err := engine.Interpolate(query, timeRange, "SELECT $__unixEpochGroup(time_column,'5m')")
|
||||
sql, err := engine.Interpolate(query, timeRange, "SELECT $__unixEpochGroup(time_column+time_adjustment,'5m')")
|
||||
require.NoError(t, err)
|
||||
sql2, err := engine.Interpolate(query, timeRange, "SELECT $__unixEpochGroupAlias(time_column,'5m')")
|
||||
sql2, err := engine.Interpolate(query, timeRange, "SELECT $__unixEpochGroupAlias(time_column+time_adjustment,'5m')")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "SELECT floor(time_column/300)*300", sql)
|
||||
require.Equal(t, "SELECT floor((time_column+time_adjustment)/300)*300", sql)
|
||||
require.Equal(t, sql2, sql+" AS \"time\"")
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user