diff --git a/executor.go b/executor.go index 34fc5c87a..bc65a978c 100644 --- a/executor.go +++ b/executor.go @@ -2876,10 +2876,12 @@ func (e *executor) executeGroupBy(ctx context.Context, qcx *Qcx, index string, c } } + ignoreLimit := sorter != nil // Execute calls in bulk on each remote node and merge. mapFn := func(ctx context.Context, shard uint64) (_ interface{}, err error) { - return e.executeGroupByShard(ctx, qcx, index, c, filter, shard, childRows, bases) + return e.executeGroupByShard(ctx, qcx, index, c, filter, shard, childRows, bases, ignoreLimit) } + // Merge returned results at coordinating node. reduceFn := func(ctx context.Context, prev, v interface{}) interface{} { other := findGroupCounts(prev) @@ -3434,7 +3436,7 @@ func applyConditionToGroupCounts(gcs []GroupCount, subj string, cond *pql.Condit return gcs[:i] } -func (e *executor) executeGroupByShard(ctx context.Context, qcx *Qcx, index string, c *pql.Call, filter *pql.Call, shard uint64, childRows []RowIDs, bases map[int]int64) (_ []GroupCount, err error) { +func (e *executor) executeGroupByShard(ctx context.Context, qcx *Qcx, index string, c *pql.Call, filter *pql.Call, shard uint64, childRows []RowIDs, bases map[int]int64, ignoreLimit bool) (_ []GroupCount, err error) { span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeGroupByShard") defer span.Finish() @@ -3464,7 +3466,7 @@ func (e *executor) executeGroupByShard(ctx context.Context, qcx *Qcx, index stri limit := int(^uint(0) >> 1) if lim, hasLimit, err := c.UintArg("limit"); err != nil { return nil, err - } else if hasLimit { + } else if !ignoreLimit && hasLimit { limit = int(lim) } diff --git a/executor_test.go b/executor_test.go index 3cb51cac7..d3b959302 100644 --- a/executor_test.go +++ b/executor_test.go @@ -7013,6 +7013,17 @@ func variousQueries(t *testing.T, clusterSize int) { {"icecream", "userF"}, }) + // Create and populate "dinner" field. + c.CreateField(t, "users", pilosa.IndexOptions{Keys: true, TrackExistence: true}, "dinner", pilosa.OptFieldKeys()) + c.ImportKeyKey(t, "users", "dinner", [][2]string{ + {"leftovers", "userB"}, + {"pizza", "userA"}, + {"pizza", "userB"}, + {"chinese", "userA"}, + {"chinese", "userB"}, + {"chinese", "userF"}, + }) + // Create and populate "places_visited" time field. c.CreateField(t, "users", pilosa.IndexOptions{Keys: true, TrackExistence: true}, "places_visited", pilosa.OptFieldKeys(), pilosa.OptFieldTypeTime(pilosa.TimeQuantum("YM"))) ts2019Jan01 := int64(1546300800) * 1e+9 // 2019 January 1st 0:00:00 @@ -7388,6 +7399,12 @@ pangolin,1,100 0,1,1 5,1,1 10,1,1 +`, + }, + { + query: "GroupBy(Rows(field=dinner), sort=\"count desc\", limit=2)", + csvVerifier: `chinese,3 +pizza,2 `, }, }