| 1 |
package storage |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
|
| 6 |
"github.com/influxdata/influxdb/models" |
| 7 |
"github.com/influxdata/influxdb/tsdb" |
| 8 |
"github.com/influxdata/influxql" |
| 9 |
) |
| 10 |
|
| 11 |
type ResultSet struct { |
| 12 |
cur seriesCursor |
| 13 |
row seriesRow |
| 14 |
ci CursorIterator |
| 15 |
} |
| 16 |
|
| 17 |
func newResultSet(ctx context.Context, req *ReadRequest, cur seriesCursor) *ResultSet { |
| 18 |
return &ResultSet{ |
| 19 |
cur: cur, |
| 20 |
ci: CursorIterator{ |
| 21 |
ctx: ctx, |
| 22 |
req: tsdb.CursorRequest{ |
| 23 |
Ascending: true, |
| 24 |
StartTime: req.Start, |
| 25 |
EndTime: req.End, |
| 26 |
}, |
| 27 |
}, |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
func (r *ResultSet) Close() { |
| 32 |
r.row.query = nil |
| 33 |
r.cur.Close() |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
func (r *ResultSet) Next() bool { |
| 38 |
row := r.cur.Next() |
| 39 |
if row == nil { |
| 40 |
return false |
| 41 |
} |
| 42 |
|
| 43 |
r.row = *row |
| 44 |
|
| 45 |
return true |
| 46 |
} |
| 47 |
|
| 48 |
func (r *ResultSet) Name() []byte { return r.row.name } |
| 49 |
func (r *ResultSet) Tags() models.Tags { return r.row.tags } |
| 50 |
func (r *ResultSet) Field() []byte { return []byte(r.row.field.n) } |
| 51 |
func (r *ResultSet) FieldType() influxql.DataType { return r.row.field.d } |
| 52 |
|
| 53 |
func (r *ResultSet) CursorIterator() *CursorIterator { |
| 54 |
r.ci.req.Name = r.row.name |
| 55 |
r.ci.req.Tags = r.row.tags |
| 56 |
r.ci.req.Field = r.row.field.n |
| 57 |
r.ci.itrs = r.row.query |
| 58 |
|
| 59 |
return &r.ci |
| 60 |
} |
| 61 |
|
| 62 |
type CursorIterator struct { |
| 63 |
ctx context.Context |
| 64 |
req tsdb.CursorRequest |
| 65 |
itrs tsdb.CursorIterators |
| 66 |
cur tsdb.Cursor |
| 67 |
} |
| 68 |
|
| 69 |
func (ci *CursorIterator) Next() bool { |
| 70 |
if len(ci.itrs) == 0 { |
| 71 |
return false |
| 72 |
} |
| 73 |
|
| 74 |
var shard tsdb.CursorIterator |
| 75 |
ci.cur = nil |
| 76 |
for ci.cur == nil && len(ci.itrs) > 0 { |
| 77 |
shard, ci.itrs = ci.itrs[0], ci.itrs[1:] |
| 78 |
ci.cur, _ = shard.Next(ci.ctx, &ci.req) |
| 79 |
} |
| 80 |
|
| 81 |
return ci.cur != nil |
| 82 |
} |
| 83 |
|
| 84 |
func (ci *CursorIterator) Cursor() tsdb.Cursor { |
| 85 |
return ci.cur |
| 86 |
} |