From 83ce30f1c474b39e89e4f0670e2bf5f7b311d2f7 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Fri, 8 Jan 2021 13:35:46 -0600 Subject: [PATCH] Fix GroupBy Distinct aggregate on int field --- executor.go | 7 ++++++- executor_test.go | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/executor.go b/executor.go index 6536c17f6..20143bffa 100644 --- a/executor.go +++ b/executor.go @@ -2829,7 +2829,12 @@ func (e *executor) executeGroupBy(ctx context.Context, qcx *Qcx, index string, c for n, gc := range results { intersectRows := make([]*pql.Call, 0, len(gc.Group)) for _, fr := range gc.Group { - intersectRows = append(intersectRows, &pql.Call{Name: "Row", Args: map[string]interface{}{fr.Field: fr.RowID}}) + var value interface{} = fr.RowID + // use fr.Value instead of fr.RowID if set (from int fields) + if fr.Value != nil { + value = &pql.Condition{Op: pql.EQ, Value: *fr.Value} + } + intersectRows = append(intersectRows, &pql.Call{Name: "Row", Args: map[string]interface{}{fr.Field: value}}) } // apply any filter, if present if filter != nil { diff --git a/executor_test.go b/executor_test.go index cfb2d555d..e6d83b469 100644 --- a/executor_test.go +++ b/executor_test.go @@ -7108,6 +7108,15 @@ toucan,1,10000 csvVerifier: `toucan,1,10000 zebra,1,1000 pangolin,1,100 +`, + }, + { + query: "GroupBy(Rows(field=affinity), aggregate=Count(Distinct(field=zip_code)))", + csvVerifier: `-10,1,1 +-5,1,1 +0,1,1 +5,1,1 +10,1,1 `, }, }