mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 01:15:46 +08:00
add compatibility code to handle pre 5.3 usage
This commit is contained in:
@ -30,6 +30,23 @@ func (m *postgresMacroEngine) Interpolate(query *tsdb.Query, timeRange *tsdb.Tim
|
||||
var macroError error
|
||||
|
||||
sql = replaceAllStringSubmatchFunc(rExp, sql, func(groups []string) string {
|
||||
|
||||
// detect if $__timeGroup is supposed to add AS time for pre 5.3 compatibility
|
||||
// if there is a ',' directly after the macro call $__timeGroup is probably used
|
||||
// in the old way. Inside window function ORDER BY $__timeGroup will be followed
|
||||
// by ')'
|
||||
if groups[1] == "__timeGroup" {
|
||||
if index := strings.Index(sql, groups[0]); index >= 0 {
|
||||
index += len(groups[0])
|
||||
if len(sql) > index {
|
||||
// check for character after macro expression
|
||||
if sql[index] == ',' {
|
||||
groups[1] = "__timeGroupAlias"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
args := strings.Split(groups[2], ",")
|
||||
for i, arg := range args {
|
||||
args[i] = strings.Trim(arg, " ")
|
||||
|
Reference in New Issue
Block a user