You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2022/05/15 01:03:00 UTC

[skywalking-banyandb] 01/01: Correct the behaviour of group by

This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch query-groupby
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit 6272a51a1218adedb1b858dbf71427f8b6f586ce
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Sun May 15 00:57:13 2022 +0000

    Correct the behaviour of group by
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 banyand/query/processor.go                       |  5 +++-
 pkg/query/logical/measure_plan_execution_test.go | 29 ++++++++++++++++++------
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/banyand/query/processor.go b/banyand/query/processor.go
index 9de1645..923bad7 100644
--- a/banyand/query/processor.go
+++ b/banyand/query/processor.go
@@ -165,7 +165,10 @@ func (p *measureQueryProcessor) Rev(message bus.Message) (resp bus.Message) {
 	}()
 	result := make([]*measurev1.DataPoint, 0)
 	for mIterator.Next() {
-		result = append(result, mIterator.Current()...)
+		current := mIterator.Current()
+		if len(current) > 0 {
+			result = append(result, current[0])
+		}
 	}
 	now := time.Now().UnixNano()
 	resp = bus.NewMessage(bus.MessageID(now), result)
diff --git a/pkg/query/logical/measure_plan_execution_test.go b/pkg/query/logical/measure_plan_execution_test.go
index 873f836..03ae303 100644
--- a/pkg/query/logical/measure_plan_execution_test.go
+++ b/pkg/query/logical/measure_plan_execution_test.go
@@ -164,6 +164,19 @@ func TestMeasurePlanExecution_GroupByAndIndexScan(t *testing.T) {
 			tagLength:   []int{1},
 			fieldLength: 1,
 		},
+		{
+			name: "Group By without Field",
+			unresolvedPlan: logical.GroupBy(
+				logical.MeasureIndexScan(sT, eT, metadata, nil, tsdb.Entity{tsdb.AnyEntry},
+					[][]*logical.Tag{logical.NewTags("default", "entity_id")},
+					[]*logical.Field{}, true),
+				[][]*logical.Tag{logical.NewTags("default", "entity_id")},
+				true,
+			),
+			wantLength:  1,
+			tagLength:   []int{1},
+			fieldLength: 0,
+		},
 	}
 
 	for _, tt := range tests {
@@ -185,13 +198,15 @@ func TestMeasurePlanExecution_GroupByAndIndexScan(t *testing.T) {
 			dataSize := 0
 			for iter.Next() {
 				dataPoints := iter.Current()
-				for _, dp := range dataPoints {
-					dataSize++
-					tester.Len(dp.GetFields(), tt.fieldLength)
-					tester.Len(dp.GetTagFamilies(), len(tt.tagLength))
-					for tagFamilyIdx, tagFamily := range dp.GetTagFamilies() {
-						tester.Len(tagFamily.GetTags(), tt.tagLength[tagFamilyIdx])
-					}
+				if len(dataPoints) < 1 {
+					continue
+				}
+				dp := dataPoints[0]
+				dataSize++
+				tester.Len(dp.GetFields(), tt.fieldLength)
+				tester.Len(dp.GetTagFamilies(), len(tt.tagLength))
+				for tagFamilyIdx, tagFamily := range dp.GetTagFamilies() {
+					tester.Len(tagFamily.GetTags(), tt.tagLength[tagFamilyIdx])
 				}
 			}
 			tester.Equal(dataSize, tt.wantLength)