console: simplify SQL request by computing target resolution in Go

This commit is contained in:
Vincent Bernat
2022-07-26 23:51:32 +02:00
parent 0fb5107bf9
commit fad0c5db16
6 changed files with 48 additions and 33 deletions

View File

@@ -40,7 +40,7 @@ type graphHandlerOutput struct {
// graphHandlerInputToSQL converts a graph input to an SQL request
func (input graphHandlerInput) toSQL() (string, error) {
interval := int64((input.End.Sub(input.Start).Seconds())) / int64(input.Points)
slot := fmt.Sprintf(`max2(intDiv(%d, {resolution})*{resolution}, 1)`, interval)
slot := fmt.Sprintf(`{resolution->%d}`, interval)
// Filter
where := input.Filter.filter
@@ -105,7 +105,7 @@ GROUP BY time, dimensions
ORDER BY time WITH FILL
FROM toStartOfInterval({timefilter.Start}, INTERVAL %s second)
TO {timefilter.Stop}
STEP toUInt32(%s)`, withStr, strings.Join(fields, ",\n "), where, slot, slot)
STEP %s`, withStr, strings.Join(fields, ",\n "), where, slot, slot)
return sqlQuery, nil
}