From d628f2e329a7ecbbf0a31d70a1386db0cf29c0f7 Mon Sep 17 00:00:00 2001 From: Ahsan Barkati Date: Thu, 17 Jun 2021 16:10:19 +0530 Subject: [PATCH] fix(sroar): Fix TestAuthWithCustomDQL failure because of roaring bitmaps (#7902) We should consider the state of UIdMatrix (whether it was in the form of SortedUids or bitmap) in order to set the result after pagination. Pagination with cascade is handled separately, where it is possible to have no order. --- codec/codec.go | 10 ++++++++++ query/query.go | 7 +++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/codec/codec.go b/codec/codec.go index 763d5165b78..8c7e8eda1fe 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -82,6 +82,16 @@ func GetUids(l *pb.List) []uint64 { return FromList(l).ToArray() } +func SetUids(l *pb.List, uids []uint64) { + if len(l.SortedUids) > 0 { + l.SortedUids = uids + } else { + r := sroar.NewBitmap() + r.SetMany(uids) + l.Bitmap = ToBytes(r) + } +} + func BitmapToSorted(l *pb.List) { if l == nil { return diff --git a/query/query.go b/query/query.go index db5c0117949..ea274c11e39 100644 --- a/query/query.go +++ b/query/query.go @@ -1415,14 +1415,13 @@ func (sg *SubGraph) populateVarMap(doneVars map[string]varValue, sgPath []*SubGr child.updateUidMatrix() // Apply pagination after the @cascade. - if len(child.Params.Cascade.Fields) > 0 && (child.Params.Cascade.First != 0 || child.Params.Cascade.Offset != 0) { + if len(child.Params.Cascade.Fields) > 0 && (child.Params.Cascade.First != 0 || + child.Params.Cascade.Offset != 0) { for i := 0; i < len(child.uidMatrix); i++ { uids := codec.GetUids(child.uidMatrix[i]) start, end := x.PageRange(child.Params.Cascade.First, child.Params.Cascade.Offset, len(uids)) - r := sroar.NewBitmap() - r.SetMany(uids[start:end]) - child.uidMatrix[i].Bitmap = codec.ToBytes(r) + codec.SetUids(child.uidMatrix[i], uids[start:end]) } } }