mssql: fix timeGroup macro so that it properly creates correct groups

Earlier the division of interval was done using whole numbers resulting in that important information
was lost/too many time series merged to the same group. Now using division of floating point and rounding
up to solve the problem
This commit is contained in:
Marcus Efraimsson
2018-03-22 14:49:40 +01:00
parent 42299eb328
commit 3ccadff800
3 changed files with 44 additions and 34 deletions

View File

@@ -113,7 +113,7 @@ func (m *MsSqlMacroEngine) evaluateMacro(name string, args []string) (string, er
m.Query.Model.Set("fillValue", floatVal)
}
}
return fmt.Sprintf("cast(cast(DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), %s))/%.0f as int)*%.0f as int)", args[0], interval.Seconds(), interval.Seconds()), nil
return fmt.Sprintf("CAST(ROUND(DATEDIFF(second, '1970-01-01', %s)/%.1f, 0) as bigint)*%.0f", args[0], interval.Seconds(), interval.Seconds()), nil
case "__unixEpochFilter":
if len(args) == 0 {
return "", fmt.Errorf("missing time column argument for macro %v", name)