mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-28 00:31:58 +08:00
31 lines
747 B
Go
31 lines
747 B
Go
package helpers
|
|
|
|
import (
|
|
"fmt"
|
|
v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3"
|
|
)
|
|
|
|
func AddSecondaryAggregation(seriesAggregator v3.SecondaryAggregation, query string) string {
|
|
queryImpl := "SELECT %s as aggregated_value, ts" +
|
|
" FROM (%s)" +
|
|
" GROUP BY ts" +
|
|
" ORDER BY ts"
|
|
|
|
var op string
|
|
switch seriesAggregator {
|
|
case v3.SecondaryAggregationAvg:
|
|
op = "avg(value)"
|
|
query = fmt.Sprintf(queryImpl, op, query)
|
|
case v3.SecondaryAggregationSum:
|
|
op = "sum(value)"
|
|
query = fmt.Sprintf(queryImpl, op, query)
|
|
case v3.SecondaryAggregationMin:
|
|
op = "min(value)"
|
|
query = fmt.Sprintf(queryImpl, op, query)
|
|
case v3.SecondaryAggregationMax:
|
|
op = "max(value)"
|
|
query = fmt.Sprintf(queryImpl, op, query)
|
|
}
|
|
return query
|
|
}
|