From 222e21bc3be64c9da07bdae35ab75d6f213662c3 Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Mon, 29 Apr 2019 18:29:18 +0530 Subject: [PATCH] Return an empty iterator when no chunks are present Signed-off-by: Goutham Veeramachaneni --- pkg/chunk/encoding/bigchunk.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/chunk/encoding/bigchunk.go b/pkg/chunk/encoding/bigchunk.go index 0282c08e997..e3eec71ad77 100644 --- a/pkg/chunk/encoding/bigchunk.go +++ b/pkg/chunk/encoding/bigchunk.go @@ -170,6 +170,10 @@ func (b *bigchunk) Size() int { } func (b *bigchunk) NewIterator() Iterator { + if len(b.chunks) == 0 { + return emptyIterator{} + } + return &bigchunkIterator{ bigchunk: b, curr: b.chunks[0].Iterator(), @@ -332,3 +336,12 @@ func firstAndLastTimes(c chunkenc.Chunk) (int64, int64, error) { } return first, last, iter.Err() } + +// emptyIterator has no samples. +type emptyIterator struct{} + +func (emptyIterator) Scan() bool { return false } +func (emptyIterator) FindAtOrAfter(model.Time) bool { return false } +func (emptyIterator) Value() model.SamplePair { return model.SamplePair{} } +func (emptyIterator) Batch(size int) Batch { return Batch{} } +func (emptyIterator) Err() error { return nil }