OmCheeLin commented on code in PR #932:
URL:
https://github.com/apache/skywalking-banyandb/pull/932#discussion_r2675077132
##########
pkg/query/logical/measure/measure_plan_distributed.go:
##########
@@ -556,3 +566,64 @@ func deduplicateAggregatedDataPoints(dataPoints
[]*measurev1.DataPoint, groupByT
}
return result, nil
}
+
+// aggregateCountDataPoints aggregates count results by summing values per
group.
+func aggregateCountDataPoints(dataPoints []*measurev1.DataPoint,
groupByTagsRefs [][]*logical.TagRef, fieldName string) ([]*measurev1.DataPoint,
error) {
+ groupMap := make(map[uint64][]*measurev1.DataPoint)
+ for _, dp := range dataPoints {
+ key, err := formatGroupByKey(dp, groupByTagsRefs)
+ if err != nil {
+ return nil, err
+ }
+ groupMap[key] = append(groupMap[key], dp)
+ }
+ result := make([]*measurev1.DataPoint, 0, len(groupMap))
+ for _, dps := range groupMap {
+ if len(dps) == 0 {
+ continue
+ }
+ // First deduplicate: collect unique count values (for replica
deduplication)
+ uniqueCounts := make(map[int64]struct{})
+ var firstDp *measurev1.DataPoint
+ for _, dp := range dps {
+ if firstDp == nil {
+ firstDp = dp
+ }
+ for _, field := range dp.GetFields() {
+ if field.GetName() == fieldName {
+ fieldValue := field.GetValue()
+ var countVal int64
+ switch v :=
fieldValue.GetValue().(type) {
+ case *modelv1.FieldValue_Int:
+ countVal = v.Int.GetValue()
+ case *modelv1.FieldValue_Float:
+ countVal =
int64(v.Float.GetValue())
+ default:
+ continue
+ }
+ uniqueCounts[countVal] = struct{}{}
+ break
+ }
+ }
+ }
+ // Then sum all unique count values
+ var sumValue int64
+ for countVal := range uniqueCounts {
+ sumValue += countVal
+ }
Review Comment:
The data has been grouped by formatGroupByKey. Now we need to be able to
distinguish between "replicas of the same shard" and "replicas of different
shards"? @hanahmily
--
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]