hanahmily commented on code in PR #957:
URL:
https://github.com/apache/skywalking-banyandb/pull/957#discussion_r2753000712
##########
pkg/query/aggregation/aggregation.go:
##########
@@ -36,6 +36,15 @@ type Func[N Number] interface {
In(N)
Review Comment:
```suggestion
In(...N)
```
##########
pkg/query/aggregation/aggregation.go:
##########
@@ -36,6 +36,15 @@ type Func[N Number] interface {
In(N)
Val() N
Reset()
+ // Sum returns the sum of values for distributed mean aggregation.
+ Sum() N
+ // Count returns the count of values for distributed mean aggregation.
+ Count() N
+}
+
+// DistributedMean is an interface that identifies distributed mean
aggregation functions.
+type DistributedMean interface {
+ IsDistributedMean() bool
}
Review Comment:
```suggestion
```
##########
pkg/query/aggregation/aggregation.go:
##########
@@ -36,6 +36,15 @@ type Func[N Number] interface {
In(N)
Val() N
Reset()
+ // Sum returns the sum of values for distributed mean aggregation.
+ Sum() N
+ // Count returns the count of values for distributed mean aggregation.
+ Count() N
Review Comment:
```suggestion
```
##########
pkg/query/aggregation/aggregation.go:
##########
@@ -64,6 +73,19 @@ func NewFunc[N Number](af modelv1.AggregationFunction)
(Func[N], error) {
return result, nil
}
+// NewDistributedMeanFunc returns a distributed mean aggregation function that
returns sum and count instead of mean.
+func NewDistributedMeanFunc[N Number]() Func[N] {
+ return &distributedMeanFunc[N]{zero: zero[N]()}
+}
+
+// IsDistributedMean checks if the aggregation function is a distributed mean
function.
+func IsDistributedMean[N Number](f Func[N]) bool {
+ if dm, ok := f.(DistributedMean); ok {
+ return dm.IsDistributedMean()
+ }
+ return false
+}
+
Review Comment:
```suggestion
```
##########
pkg/query/aggregation/function.go:
##########
@@ -115,3 +147,45 @@ func (m minFunc[N]) Val() N {
func (m *minFunc[N]) Reset() {
m.val = m.max
}
+
+func (m *minFunc[N]) Sum() N {
+ return m.max
+}
+
+func (m *minFunc[N]) Count() N {
+ return m.max
+}
+
+// distributedMeanFunc is used for distributed mean aggregation, returning sum
and count instead of mean.
+type distributedMeanFunc[N Number] struct {
+ sum N
+ count N
+ zero N
+}
+
+func (m *distributedMeanFunc[N]) In(val N) {
+ m.sum += val
+ m.count++
Review Comment:
```suggestion
func (m *distributedMeanFunc[N]) In(vals ...N) {
if len(vals) != 2 {
panic("expected 2 values for distributed mean")
}
m.sum += vals[0]
m.count += vals[1]
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]