From 6216c4fb8a03a450277dfce9976bb2f4b475a91b Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Mon, 6 Mar 2017 15:34:57 -0600 Subject: [PATCH] don't panic if 'n' not supplied to TopN --- executor.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/executor.go b/executor.go index 26b2f4747..728e22cee 100644 --- a/executor.go +++ b/executor.go @@ -168,7 +168,10 @@ func (e *Executor) executeBitmapCallSlice(ctx context.Context, db string, c *pql // requeries to retrieve the full counts for each of the top results. func (e *Executor) executeTopN(ctx context.Context, db string, c *pql.Call, slices []uint64, opt *ExecOptions) ([]Pair, error) { bitmapIDs, _ := c.Args["ids"].([]uint64) - n := c.Args["n"].(uint64) + var n uint64 + if nval, ok := c.Args["n"]; ok { + n = nval.(uint64) + } // Execute original query. pairs, err := e.executeTopNSlices(ctx, db, c, slices, opt) @@ -197,7 +200,7 @@ func (e *Executor) executeTopN(ctx context.Context, db string, c *pql.Call, slic return nil, err } - if int(n) < len(trimmedList) { + if n != 0 && int(n) < len(trimmedList) { trimmedList = trimmedList[0:n] } return trimmedList, nil