-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
cursor.go
101 lines (80 loc) · 2.14 KB
/
cursor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package cursors
import (
"context"
"github.com/influxdata/influxdb/models"
)
const DefaultMaxPointsPerBlock = 1000
type Cursor interface {
Close()
Err() error
Stats() CursorStats
}
type IntegerArrayCursor interface {
Cursor
Next() *IntegerArray
}
type FloatArrayCursor interface {
Cursor
Next() *FloatArray
}
type UnsignedArrayCursor interface {
Cursor
Next() *UnsignedArray
}
type StringArrayCursor interface {
Cursor
Next() *StringArray
}
type BooleanArrayCursor interface {
Cursor
Next() *BooleanArray
}
type MeanCountArrayCursor interface {
Cursor
Next() *MeanCountArray
}
// CursorRequest is a request to the storage engine for a cursor to be
// created with the given name, tags, and field for a given direction
// and time range.
type CursorRequest struct {
// Name is the measurement name a cursor is requested for.
Name []byte
// Tags is the set of series tags a cursor is requested for.
Tags models.Tags
// Field is the selected field for the cursor that is requested.
Field string
// Ascending is whether the cursor should move in an ascending
// or descending time order.
Ascending bool
// StartTime is the start time of the cursor. It is the lower
// absolute time regardless of the Ascending flag. This value
// is an inclusive bound.
StartTime int64
// EndTime is the end time of the cursor. It is the higher
// absolute time regardless of the Ascending flag. This value
// is an inclusive bound.
EndTime int64
}
type CursorIterator interface {
Next(ctx context.Context, r *CursorRequest) (Cursor, error)
Stats() CursorStats
}
type CursorIterators []CursorIterator
// Stats returns the aggregate stats of all cursor iterators.
func (a CursorIterators) Stats() CursorStats {
var stats CursorStats
for _, itr := range a {
stats.Add(itr.Stats())
}
return stats
}
// CursorStats represents stats collected by a cursor.
type CursorStats struct {
ScannedValues int // number of values scanned
ScannedBytes int // number of uncompressed bytes scanned
}
// Add adds other to s and updates s.
func (s *CursorStats) Add(other CursorStats) {
s.ScannedValues += other.ScannedValues
s.ScannedBytes += other.ScannedBytes
}