Expose NewChainSampleIterator func (#9475)

* expose NewChainSampleIterator func

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* add comment

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* update comments

Signed-off-by: Ben Ye <ben.ye@bytedance.com>
This commit is contained in:
Ben Ye 2021-10-14 02:19:00 -07:00 committed by GitHub
parent e261eccb35
commit fdbc40a9ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -431,7 +431,7 @@ func ChainedSeriesMerge(series ...Series) Series {
for _, s := range series {
iterators = append(iterators, s.Iterator())
}
return newChainSampleIterator(iterators)
return NewChainSampleIterator(iterators)
},
}
}
@ -447,7 +447,10 @@ type chainSampleIterator struct {
lastt int64
}
func newChainSampleIterator(iterators []chunkenc.Iterator) chunkenc.Iterator {
// NewChainSampleIterator returns a single iterator that iterates over the samples from the given iterators in a sorted
// fashion. If samples overlap, one sample from overlapped ones is kept (randomly) and all others with the same
// timestamp are dropped.
func NewChainSampleIterator(iterators []chunkenc.Iterator) chunkenc.Iterator {
return &chainSampleIterator{
iterators: iterators,
h: nil,

View file

@ -631,7 +631,7 @@ func TestChainSampleIterator(t *testing.T) {
expected: []tsdbutil.Sample{sample{0, 0}, sample{1, 1}, sample{2, 2}, sample{3, 3}},
},
} {
merged := newChainSampleIterator(tc.input)
merged := NewChainSampleIterator(tc.input)
actual, err := ExpandSamples(merged, nil)
require.NoError(t, err)
require.Equal(t, tc.expected, actual)
@ -677,7 +677,7 @@ func TestChainSampleIteratorSeek(t *testing.T) {
expected: []tsdbutil.Sample{sample{0, 0}, sample{1, 1}, sample{2, 2}, sample{3, 3}},
},
} {
merged := newChainSampleIterator(tc.input)
merged := NewChainSampleIterator(tc.input)
actual := []tsdbutil.Sample{}
if merged.Seek(tc.seek) {
t, v := merged.At()