mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
unexport iterator stuff and make NopInternalClient less pointery
This commit is contained in:
parent
de138f690b
commit
62e0d185dc
4 changed files with 80 additions and 86 deletions
74
client.go
74
client.go
|
|
@ -75,66 +75,62 @@ var _ InternalQueryClient = NewNopInternalQueryClient()
|
|||
|
||||
type NopInternalClient struct{}
|
||||
|
||||
func NewNopInternalClient() *NopInternalClient {
|
||||
return &NopInternalClient{}
|
||||
func NewNopInternalClient() NopInternalClient {
|
||||
return NopInternalClient{}
|
||||
}
|
||||
|
||||
var _ InternalClient = NewNopInternalClient()
|
||||
|
||||
func (n *NopInternalClient) MaxShardByIndex(ctx context.Context) (map[string]uint64, error) {
|
||||
func (n NopInternalClient) MaxShardByIndex(context.Context) (map[string]uint64, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (n *NopInternalClient) Schema(ctx context.Context) ([]*IndexInfo, error) {
|
||||
func (n NopInternalClient) Schema(ctx context.Context) ([]*IndexInfo, error) { return nil, nil }
|
||||
func (n NopInternalClient) CreateIndex(ctx context.Context, index string, opt IndexOptions) error {
|
||||
return nil
|
||||
}
|
||||
func (n NopInternalClient) FragmentNodes(ctx context.Context, index string, shard uint64) ([]*Node, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (n *NopInternalClient) CreateIndex(ctx context.Context, index string, opt IndexOptions) error {
|
||||
return nil
|
||||
}
|
||||
func (n *NopInternalClient) FragmentNodes(ctx context.Context, index string, shard uint64) ([]*Node, error) {
|
||||
func (n NopInternalClient) Query(ctx context.Context, index string, queryRequest *internal.QueryRequest) (*internal.QueryResponse, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (n *NopInternalClient) Query(ctx context.Context, index string, queryRequest *internal.QueryRequest) (*internal.QueryResponse, error) {
|
||||
func (n NopInternalClient) QueryNode(ctx context.Context, uri *URI, index string, queryRequest *internal.QueryRequest) (*internal.QueryResponse, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (n *NopInternalClient) QueryNode(ctx context.Context, uri *URI, index string, queryRequest *internal.QueryRequest) (*internal.QueryResponse, error) {
|
||||
func (n NopInternalClient) Import(ctx context.Context, index, field string, shard uint64, bits []Bit) error {
|
||||
return nil
|
||||
}
|
||||
func (n NopInternalClient) ImportK(ctx context.Context, index, field string, bits []Bit) error {
|
||||
return nil
|
||||
}
|
||||
func (n NopInternalClient) EnsureIndex(ctx context.Context, name string, options IndexOptions) error {
|
||||
return nil
|
||||
}
|
||||
func (n NopInternalClient) EnsureField(ctx context.Context, indexName string, fieldName string) error {
|
||||
return nil
|
||||
}
|
||||
func (n NopInternalClient) ImportValue(ctx context.Context, index, field string, shard uint64, vals []FieldValue) error {
|
||||
return nil
|
||||
}
|
||||
func (n NopInternalClient) ExportCSV(ctx context.Context, index, field string, shard uint64, w io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
func (n NopInternalClient) CreateField(ctx context.Context, index, field string) error { return nil }
|
||||
func (n NopInternalClient) FragmentBlocks(ctx context.Context, uri *URI, index, field string, shard uint64) ([]FragmentBlock, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (n *NopInternalClient) Import(ctx context.Context, index, field string, shard uint64, bits []Bit) error {
|
||||
return nil
|
||||
}
|
||||
func (n *NopInternalClient) ImportK(ctx context.Context, index, field string, bits []Bit) error {
|
||||
return nil
|
||||
}
|
||||
func (n *NopInternalClient) EnsureIndex(ctx context.Context, name string, options IndexOptions) error {
|
||||
return nil
|
||||
}
|
||||
func (n *NopInternalClient) EnsureField(ctx context.Context, indexName string, fieldName string) error {
|
||||
return nil
|
||||
}
|
||||
func (n *NopInternalClient) ImportValue(ctx context.Context, index, field string, shard uint64, vals []FieldValue) error {
|
||||
return nil
|
||||
}
|
||||
func (n *NopInternalClient) ExportCSV(ctx context.Context, index, field string, shard uint64, w io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
func (n *NopInternalClient) CreateField(ctx context.Context, index, field string) error {
|
||||
return nil
|
||||
}
|
||||
func (n *NopInternalClient) FragmentBlocks(ctx context.Context, uri *URI, index, field string, shard uint64) ([]FragmentBlock, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (n *NopInternalClient) BlockData(ctx context.Context, uri *URI, index, field string, shard uint64, block int) ([]uint64, []uint64, error) {
|
||||
func (n NopInternalClient) BlockData(ctx context.Context, uri *URI, index, field string, shard uint64, block int) ([]uint64, []uint64, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
func (n *NopInternalClient) ColumnAttrDiff(ctx context.Context, uri *URI, index string, blks []AttrBlock) (map[uint64]map[string]interface{}, error) {
|
||||
func (n NopInternalClient) ColumnAttrDiff(ctx context.Context, uri *URI, index string, blks []AttrBlock) (map[uint64]map[string]interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (n *NopInternalClient) RowAttrDiff(ctx context.Context, uri *URI, index, field string, blks []AttrBlock) (map[uint64]map[string]interface{}, error) {
|
||||
func (n NopInternalClient) RowAttrDiff(ctx context.Context, uri *URI, index, field string, blks []AttrBlock) (map[uint64]map[string]interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (n *NopInternalClient) SendMessage(ctx context.Context, uri *URI, pb proto.Message) error {
|
||||
func (n NopInternalClient) SendMessage(ctx context.Context, uri *URI, pb proto.Message) error {
|
||||
return nil
|
||||
}
|
||||
func (n *NopInternalClient) RetrieveShardFromURI(ctx context.Context, index, field string, shard uint64, uri URI) (io.ReadCloser, error) {
|
||||
func (n NopInternalClient) RetrieveShardFromURI(ctx context.Context, index, field string, shard uint64, uri URI) (io.ReadCloser, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
14
fragment.go
14
fragment.go
|
|
@ -1193,18 +1193,18 @@ func (f *fragment) mergeBlock(id int, data []pairSet) (sets, clears []pairSet, e
|
|||
maxColumnID := uint64(ShardWidth)
|
||||
|
||||
// Create buffered iterator for local block.
|
||||
itrs := make([]*BufIterator, 1, len(data)+1)
|
||||
itrs[0] = NewBufIterator(
|
||||
NewLimitIterator(
|
||||
NewRoaringIterator(f.storage.Iterator()), maxRowID, maxColumnID,
|
||||
itrs := make([]*bufIterator, 1, len(data)+1)
|
||||
itrs[0] = newBufIterator(
|
||||
newLimitIterator(
|
||||
newRoaringIterator(f.storage.Iterator()), maxRowID, maxColumnID,
|
||||
),
|
||||
)
|
||||
|
||||
// Append buffered iterators for each incoming block.
|
||||
for i := range data {
|
||||
var itr Iterator = NewSliceIterator(data[i].rowIDs, data[i].columnIDs)
|
||||
itr = NewLimitIterator(itr, maxRowID, maxColumnID)
|
||||
itrs = append(itrs, NewBufIterator(itr))
|
||||
var itr iterator = newSliceIterator(data[i].rowIDs, data[i].columnIDs)
|
||||
itr = newLimitIterator(itr, maxRowID, maxColumnID)
|
||||
itrs = append(itrs, newBufIterator(itr))
|
||||
}
|
||||
|
||||
// Seek to initial pair.
|
||||
|
|
|
|||
68
iterator.go
68
iterator.go
|
|
@ -20,37 +20,37 @@ import (
|
|||
"github.com/pilosa/pilosa/roaring"
|
||||
)
|
||||
|
||||
// Iterator is an interface for looping over row/column pairs.
|
||||
type Iterator interface {
|
||||
// iterator is an interface for looping over row/column pairs.
|
||||
type iterator interface {
|
||||
Seek(rowID, columnID uint64)
|
||||
Next() (rowID, columnID uint64, eof bool)
|
||||
}
|
||||
|
||||
// BufIterator wraps an iterator to provide the ability to unread values.
|
||||
type BufIterator struct {
|
||||
// bufIterator wraps an iterator to provide the ability to unread values.
|
||||
type bufIterator struct {
|
||||
buf struct {
|
||||
rowID uint64
|
||||
columnID uint64
|
||||
eof bool
|
||||
full bool
|
||||
}
|
||||
itr Iterator
|
||||
itr iterator
|
||||
}
|
||||
|
||||
// NewBufIterator returns a buffered iterator that wraps itr.
|
||||
func NewBufIterator(itr Iterator) *BufIterator {
|
||||
return &BufIterator{itr: itr}
|
||||
// newBufIterator returns a buffered iterator that wraps itr.
|
||||
func newBufIterator(itr iterator) *bufIterator {
|
||||
return &bufIterator{itr: itr}
|
||||
}
|
||||
|
||||
// Seek moves to the first pair equal to or greater than pseek/bseek.
|
||||
func (itr *BufIterator) Seek(rowID, columnID uint64) {
|
||||
func (itr *bufIterator) Seek(rowID, columnID uint64) {
|
||||
itr.buf.full = false
|
||||
itr.itr.Seek(rowID, columnID)
|
||||
}
|
||||
|
||||
// Next returns the next pair in the row.
|
||||
// If a value has been buffered then it is returned and the buffer is cleared.
|
||||
func (itr *BufIterator) Next() (rowID, columnID uint64, eof bool) {
|
||||
func (itr *bufIterator) Next() (rowID, columnID uint64, eof bool) {
|
||||
if itr.buf.full {
|
||||
itr.buf.full = false
|
||||
return itr.buf.rowID, itr.buf.columnID, itr.buf.eof
|
||||
|
|
@ -63,7 +63,7 @@ func (itr *BufIterator) Next() (rowID, columnID uint64, eof bool) {
|
|||
}
|
||||
|
||||
// Peek reads the next value but leaves it on the buffer.
|
||||
func (itr *BufIterator) Peek() (rowID, columnID uint64, eof bool) {
|
||||
func (itr *bufIterator) Peek() (rowID, columnID uint64, eof bool) {
|
||||
rowID, columnID, eof = itr.Next()
|
||||
itr.Unread()
|
||||
return
|
||||
|
|
@ -71,25 +71,25 @@ func (itr *BufIterator) Peek() (rowID, columnID uint64, eof bool) {
|
|||
|
||||
// Unread pushes previous pair on to the buffer.
|
||||
// Panics if the buffer is already full.
|
||||
func (itr *BufIterator) Unread() {
|
||||
func (itr *bufIterator) Unread() {
|
||||
if itr.buf.full {
|
||||
panic("pilosa.BufIterator: buffer full")
|
||||
}
|
||||
itr.buf.full = true
|
||||
}
|
||||
|
||||
// LimitIterator wraps an Iterator and limits it to a max column/row pair.
|
||||
type LimitIterator struct {
|
||||
itr Iterator
|
||||
// limitIterator wraps an Iterator and limits it to a max column/row pair.
|
||||
type limitIterator struct {
|
||||
itr iterator
|
||||
maxRowID uint64
|
||||
maxColumnID uint64
|
||||
|
||||
eof bool
|
||||
}
|
||||
|
||||
// NewLimitIterator returns a new LimitIterator.
|
||||
func NewLimitIterator(itr Iterator, maxRowID, maxColumnID uint64) *LimitIterator {
|
||||
return &LimitIterator{
|
||||
// newLimitIterator returns a new LimitIterator.
|
||||
func newLimitIterator(itr iterator, maxRowID, maxColumnID uint64) *limitIterator {
|
||||
return &limitIterator{
|
||||
itr: itr,
|
||||
maxRowID: maxRowID,
|
||||
maxColumnID: maxColumnID,
|
||||
|
|
@ -97,11 +97,11 @@ func NewLimitIterator(itr Iterator, maxRowID, maxColumnID uint64) *LimitIterator
|
|||
}
|
||||
|
||||
// Seek moves the underlying iterator to a column/row pair.
|
||||
func (itr *LimitIterator) Seek(rowID, columnID uint64) { itr.itr.Seek(rowID, columnID) }
|
||||
func (itr *limitIterator) Seek(rowID, columnID uint64) { itr.itr.Seek(rowID, columnID) }
|
||||
|
||||
// Next returns the next row/column ID pair.
|
||||
// If the underlying iterator returns a pair higher than the max then EOF is returned.
|
||||
func (itr *LimitIterator) Next() (rowID, columnID uint64, eof bool) {
|
||||
func (itr *limitIterator) Next() (rowID, columnID uint64, eof bool) {
|
||||
// Always return EOF once it is reached by limit or the underlying iterator.
|
||||
if itr.eof {
|
||||
return 0, 0, true
|
||||
|
|
@ -118,22 +118,22 @@ func (itr *LimitIterator) Next() (rowID, columnID uint64, eof bool) {
|
|||
return rowID, columnID, false
|
||||
}
|
||||
|
||||
// SliceIterator iterates over a pair of row/column ID slices.
|
||||
type SliceIterator struct {
|
||||
// sliceIterator iterates over a pair of row/column ID slices.
|
||||
type sliceIterator struct {
|
||||
rowIDs []uint64
|
||||
columnIDs []uint64
|
||||
|
||||
i, n int
|
||||
}
|
||||
|
||||
// NewSliceIterator returns an iterator to iterate over a set of row/column ID pairs.
|
||||
// newSliceIterator returns an iterator to iterate over a set of row/column ID pairs.
|
||||
// Both slices MUST have an equal length. Otherwise the function will panic.
|
||||
func NewSliceIterator(rowIDs, columnIDs []uint64) *SliceIterator {
|
||||
func newSliceIterator(rowIDs, columnIDs []uint64) *sliceIterator {
|
||||
if len(columnIDs) != len(rowIDs) {
|
||||
panic(fmt.Sprintf("pilosa.SliceIterator: pair length mismatch: %d != %d", len(rowIDs), len(columnIDs)))
|
||||
}
|
||||
|
||||
return &SliceIterator{
|
||||
return &sliceIterator{
|
||||
rowIDs: rowIDs,
|
||||
columnIDs: columnIDs,
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ func NewSliceIterator(rowIDs, columnIDs []uint64) *SliceIterator {
|
|||
|
||||
// Seek moves the cursor to a given pair.
|
||||
// If the pair is not found, the iterator seeks to the next pair.
|
||||
func (itr *SliceIterator) Seek(bseek, pseek uint64) {
|
||||
func (itr *sliceIterator) Seek(bseek, pseek uint64) {
|
||||
for i := 0; i < itr.n; i++ {
|
||||
rowID := itr.rowIDs[i]
|
||||
columnID := itr.columnIDs[i]
|
||||
|
|
@ -159,7 +159,7 @@ func (itr *SliceIterator) Seek(bseek, pseek uint64) {
|
|||
}
|
||||
|
||||
// Next returns the next row/column ID pair.
|
||||
func (itr *SliceIterator) Next() (rowID, columnID uint64, eof bool) {
|
||||
func (itr *sliceIterator) Next() (rowID, columnID uint64, eof bool) {
|
||||
if itr.i >= itr.n {
|
||||
return 0, 0, true
|
||||
}
|
||||
|
|
@ -171,24 +171,24 @@ func (itr *SliceIterator) Next() (rowID, columnID uint64, eof bool) {
|
|||
return rowID, columnID, false
|
||||
}
|
||||
|
||||
// RoaringIterator converts a roaring.Iterator to output column/row pairs.
|
||||
type RoaringIterator struct {
|
||||
// roaringIterator converts a roaring.Iterator to output column/row pairs.
|
||||
type roaringIterator struct {
|
||||
itr *roaring.Iterator
|
||||
}
|
||||
|
||||
// NewRoaringIterator returns a new iterator wrapping itr.
|
||||
func NewRoaringIterator(itr *roaring.Iterator) *RoaringIterator {
|
||||
return &RoaringIterator{itr: itr}
|
||||
// newRoaringIterator returns a new iterator wrapping itr.
|
||||
func newRoaringIterator(itr *roaring.Iterator) *roaringIterator {
|
||||
return &roaringIterator{itr: itr}
|
||||
}
|
||||
|
||||
// Seek moves the cursor to a pair matching bseek/pseek.
|
||||
// If the pair is not found then it moves to the next pair.
|
||||
func (itr *RoaringIterator) Seek(bseek, pseek uint64) {
|
||||
func (itr *roaringIterator) Seek(bseek, pseek uint64) {
|
||||
itr.itr.Seek((bseek * ShardWidth) + pseek)
|
||||
}
|
||||
|
||||
// Next returns the next column/row ID pair.
|
||||
func (itr *RoaringIterator) Next() (rowID, columnID uint64, eof bool) {
|
||||
func (itr *roaringIterator) Next() (rowID, columnID uint64, eof bool) {
|
||||
v, eof := itr.itr.Next()
|
||||
return v / ShardWidth, v % ShardWidth, eof
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,19 +12,17 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package pilosa_test
|
||||
package pilosa
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/pilosa/pilosa"
|
||||
)
|
||||
|
||||
// Ensure slice iterator and iterate over a set of pairs.
|
||||
func TestSliceIterator(t *testing.T) {
|
||||
// Initialize iterator.
|
||||
itr := pilosa.NewSliceIterator(
|
||||
itr := newSliceIterator(
|
||||
[]uint64{0, 0, 2, 4},
|
||||
[]uint64{0, 1, 0, 10},
|
||||
)
|
||||
|
|
@ -48,7 +46,7 @@ func TestSliceIterator(t *testing.T) {
|
|||
|
||||
// Ensure buffered iterator can unread values on to the buffer.
|
||||
func TestBufIterator(t *testing.T) {
|
||||
itr := pilosa.NewBufIterator(pilosa.NewSliceIterator(
|
||||
itr := newBufIterator(newSliceIterator(
|
||||
[]uint64{0, 0, 1, 2},
|
||||
[]uint64{1, 3, 0, 100},
|
||||
))
|
||||
|
|
@ -77,7 +75,7 @@ func TestBufIterator_DoubleFillPanic(t *testing.T) {
|
|||
func() {
|
||||
defer func() { v = recover() }()
|
||||
|
||||
itr := pilosa.NewBufIterator(pilosa.NewSliceIterator(nil, nil))
|
||||
itr := newBufIterator(newSliceIterator(nil, nil))
|
||||
itr.Unread()
|
||||
itr.Unread()
|
||||
}()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue