2018-10-05 22:02:31 +00:00
|
|
|
// Generated by tmpl
|
|
|
|
// https://github.com/benbjohnson/tmpl
|
|
|
|
//
|
|
|
|
// DO NOT EDIT!
|
2020-03-10 05:00:52 +00:00
|
|
|
// Source: table.gen.go.tmpl
|
2018-10-05 22:02:31 +00:00
|
|
|
|
2020-03-10 05:00:52 +00:00
|
|
|
package storageflux
|
2018-10-05 22:02:31 +00:00
|
|
|
|
|
|
|
import (
|
2019-01-10 23:23:34 +00:00
|
|
|
"sync"
|
2018-10-31 23:21:54 +00:00
|
|
|
|
2020-06-01 22:57:50 +00:00
|
|
|
"github.com/apache/arrow/go/arrow/array"
|
2018-10-05 22:02:31 +00:00
|
|
|
"github.com/influxdata/flux"
|
2019-02-25 20:44:18 +00:00
|
|
|
"github.com/influxdata/flux/arrow"
|
2018-10-05 22:02:31 +00:00
|
|
|
"github.com/influxdata/flux/execute"
|
2019-02-25 20:44:18 +00:00
|
|
|
"github.com/influxdata/flux/memory"
|
2020-04-09 21:40:41 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/models"
|
|
|
|
storage "github.com/influxdata/influxdb/v2/storage/reads"
|
|
|
|
"github.com/influxdata/influxdb/v2/tsdb/cursors"
|
2018-10-05 22:02:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
//
|
|
|
|
// *********** Float ***********
|
|
|
|
//
|
|
|
|
|
|
|
|
type floatTable struct {
|
|
|
|
table
|
2019-05-16 01:40:29 +00:00
|
|
|
mu sync.Mutex
|
|
|
|
cur cursors.FloatArrayCursor
|
|
|
|
alloc *memory.Allocator
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newFloatTable(
|
2018-10-31 23:21:54 +00:00
|
|
|
done chan struct{},
|
2018-10-05 22:02:31 +00:00
|
|
|
cur cursors.FloatArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
2019-11-27 14:31:53 +00:00
|
|
|
cache *tagsCache,
|
2019-03-06 21:29:45 +00:00
|
|
|
alloc *memory.Allocator,
|
2018-10-05 22:02:31 +00:00
|
|
|
) *floatTable {
|
|
|
|
t := &floatTable{
|
2019-11-27 14:31:53 +00:00
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
2018-10-05 22:02:31 +00:00
|
|
|
cur: cur,
|
|
|
|
}
|
|
|
|
t.readTags(tags)
|
2019-07-03 14:26:08 +00:00
|
|
|
t.advance()
|
2018-10-05 22:02:31 +00:00
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *floatTable) Close() {
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Lock()
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.cur != nil {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
}
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Unlock()
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 20:44:18 +00:00
|
|
|
func (t *floatTable) Statistics() cursors.CursorStats {
|
2018-11-07 16:31:42 +00:00
|
|
|
t.mu.Lock()
|
2018-12-13 18:05:14 +00:00
|
|
|
defer t.mu.Unlock()
|
2018-11-07 16:31:42 +00:00
|
|
|
cur := t.cur
|
|
|
|
if cur == nil {
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{}
|
2018-11-07 16:31:42 +00:00
|
|
|
}
|
|
|
|
cs := cur.Stats()
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{
|
2018-11-07 16:31:42 +00:00
|
|
|
ScannedValues: cs.ScannedValues,
|
|
|
|
ScannedBytes: cs.ScannedBytes,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
func (t *floatTable) Do(f func(flux.ColReader) error) error {
|
2019-07-03 14:26:08 +00:00
|
|
|
return t.do(f, t.advance)
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
func (t *floatTable) advance() bool {
|
2018-10-05 22:02:31 +00:00
|
|
|
a := t.cur.Next()
|
2019-05-30 17:31:54 +00:00
|
|
|
l := a.Len()
|
|
|
|
if l == 0 {
|
2019-07-03 14:26:08 +00:00
|
|
|
return false
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 17:31:54 +00:00
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2019-07-03 14:26:08 +00:00
|
|
|
cr := t.allocateBuffer(l)
|
2019-05-30 17:31:54 +00:00
|
|
|
cr.cols[timeColIdx] = arrow.NewInt(a.Timestamps, t.alloc)
|
|
|
|
cr.cols[valueColIdx] = t.toArrowBuffer(a.Values)
|
|
|
|
t.appendTags(cr)
|
|
|
|
t.appendBounds(cr)
|
2019-07-03 14:26:08 +00:00
|
|
|
return true
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 18:42:38 +00:00
|
|
|
// window table
|
|
|
|
type floatWindowTable struct {
|
|
|
|
floatTable
|
|
|
|
windowEvery int64
|
|
|
|
arr *cursors.FloatArray
|
2020-06-01 22:57:50 +00:00
|
|
|
nextTS int64
|
2020-05-28 18:42:38 +00:00
|
|
|
idxInArr int
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty bool
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newFloatWindowTable(
|
|
|
|
done chan struct{},
|
|
|
|
cur cursors.FloatArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
every int64,
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty bool,
|
2020-05-28 18:42:38 +00:00
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
|
|
|
cache *tagsCache,
|
|
|
|
alloc *memory.Allocator,
|
|
|
|
) *floatWindowTable {
|
|
|
|
t := &floatWindowTable{
|
|
|
|
floatTable: floatTable{
|
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
|
|
|
cur: cur,
|
|
|
|
},
|
|
|
|
windowEvery: every,
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty: createEmpty,
|
|
|
|
}
|
|
|
|
if t.createEmpty {
|
|
|
|
start := int64(bounds.Start)
|
|
|
|
t.nextTS = start + (every - start%every)
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
|
|
|
t.readTags(tags)
|
|
|
|
t.advance()
|
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2020-06-01 22:57:50 +00:00
|
|
|
func (t *floatWindowTable) Do(f func(flux.ColReader) error) error {
|
|
|
|
return t.do(f, t.advance)
|
|
|
|
}
|
|
|
|
|
|
|
|
// createNextWindow will read the timestamps from the array
|
|
|
|
// cursor and construct the values for the next window.
|
|
|
|
func (t *floatWindowTable) createNextWindow() (start, stop *array.Int64, ok bool) {
|
|
|
|
var stopT int64
|
|
|
|
if t.createEmpty {
|
|
|
|
stopT = t.nextTS
|
|
|
|
t.nextTS += t.windowEvery
|
|
|
|
} else {
|
|
|
|
if !t.nextBuffer() {
|
|
|
|
return nil, nil, false
|
|
|
|
}
|
|
|
|
stopT = t.arr.Timestamps[t.idxInArr]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Regain the window start time from the window end time.
|
|
|
|
startT := stopT - t.windowEvery
|
|
|
|
if startT < int64(t.bounds.Start) {
|
|
|
|
startT = int64(t.bounds.Start)
|
|
|
|
}
|
|
|
|
if stopT > int64(t.bounds.Stop) {
|
|
|
|
stopT = int64(t.bounds.Stop)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the start time is after our stop boundary,
|
|
|
|
// we exit here when create empty is true.
|
|
|
|
if t.createEmpty && startT >= int64(t.bounds.Stop) {
|
|
|
|
return nil, nil, false
|
|
|
|
}
|
|
|
|
start = arrow.NewInt([]int64{startT}, t.alloc)
|
|
|
|
stop = arrow.NewInt([]int64{stopT}, t.alloc)
|
|
|
|
return start, stop, true
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextAt will retrieve the next value that can be used with
|
|
|
|
// the given stop timestamp. If no values can be used with the timestamp,
|
|
|
|
// it will return the default value and false.
|
|
|
|
func (t *floatWindowTable) nextAt(ts int64) (v float64, ok bool) {
|
|
|
|
if !t.nextBuffer() {
|
|
|
|
return
|
|
|
|
} else if !t.isInWindow(ts, t.arr.Timestamps[t.idxInArr]) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
v, ok = t.arr.Values[t.idxInArr], true
|
|
|
|
t.idxInArr++
|
|
|
|
return v, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// isInWindow will check if the given time at stop can be used within
|
|
|
|
// the window stop time for ts. The ts may be a truncated stop time
|
|
|
|
// because of a restricted boundary while stop will be the true
|
|
|
|
// stop time returned by storage.
|
|
|
|
func (t *floatWindowTable) isInWindow(ts int64, stop int64) bool {
|
|
|
|
// This method checks if the stop time is a valid stop time for
|
|
|
|
// that interval. This calculation is different from the calculation
|
|
|
|
// of the window itself. For example, for a 10 second window that
|
|
|
|
// starts at 20 seconds, we would include points between [20, 30).
|
|
|
|
// The stop time for this interval would be 30, but because the stop
|
|
|
|
// time can be truncated, valid stop times range from anywhere between
|
|
|
|
// (20, 30]. The storage engine will always produce 30 as the end time
|
|
|
|
// but we may have truncated the stop time because of the boundary
|
|
|
|
// and this is why we are checking for this range instead of checking
|
|
|
|
// if the two values are equal.
|
|
|
|
start := stop - t.windowEvery
|
|
|
|
return start < ts && ts <= stop
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextBuffer will ensure the array cursor is filled
|
|
|
|
// and will return true if there is at least one value
|
|
|
|
// that can be read from it.
|
|
|
|
func (t *floatWindowTable) nextBuffer() bool {
|
|
|
|
// Discard the current array cursor if we have
|
|
|
|
// exceeded it.
|
|
|
|
if t.arr != nil && t.idxInArr >= t.arr.Len() {
|
|
|
|
t.arr = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the next array cursor if needed.
|
2020-05-28 18:42:38 +00:00
|
|
|
if t.arr == nil {
|
2020-06-01 22:57:50 +00:00
|
|
|
arr := t.cur.Next()
|
|
|
|
if arr.Len() == 0 {
|
2020-05-28 18:42:38 +00:00
|
|
|
return false
|
|
|
|
}
|
2020-06-01 22:57:50 +00:00
|
|
|
t.arr, t.idxInArr = arr, 0
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// appendValues will scan the timestamps and append values
|
|
|
|
// that match those timestamps from the buffer.
|
|
|
|
func (t *floatWindowTable) appendValues(intervals []int64, appendValue func(v float64), appendNull func()) {
|
|
|
|
for i := 0; i < len(intervals); i++ {
|
|
|
|
if v, ok := t.nextAt(intervals[i]); ok {
|
|
|
|
appendValue(v)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
appendNull()
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
2020-06-01 22:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *floatWindowTable) advance() bool {
|
|
|
|
// Create the timestamps for the next window.
|
|
|
|
start, stop, ok := t.createNextWindow()
|
|
|
|
if !ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
values := t.mergeValues(stop.Int64Values())
|
2020-05-28 18:42:38 +00:00
|
|
|
|
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2020-06-01 22:57:50 +00:00
|
|
|
cr := t.allocateBuffer(stop.Len())
|
|
|
|
cr.cols[startColIdx] = start
|
|
|
|
cr.cols[stopColIdx] = stop
|
|
|
|
cr.cols[windowedValueColIdx] = values
|
|
|
|
t.appendTags(cr)
|
2020-05-28 18:42:38 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
// group table
|
|
|
|
|
|
|
|
type floatGroupTable struct {
|
|
|
|
table
|
2019-05-16 01:40:29 +00:00
|
|
|
mu sync.Mutex
|
2020-03-10 05:00:52 +00:00
|
|
|
gc storage.GroupCursor
|
2019-05-16 01:40:29 +00:00
|
|
|
cur cursors.FloatArrayCursor
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newFloatGroupTable(
|
2018-10-31 23:21:54 +00:00
|
|
|
done chan struct{},
|
2020-03-10 05:00:52 +00:00
|
|
|
gc storage.GroupCursor,
|
2018-10-05 22:02:31 +00:00
|
|
|
cur cursors.FloatArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
2019-11-27 14:31:53 +00:00
|
|
|
cache *tagsCache,
|
2019-03-06 21:29:45 +00:00
|
|
|
alloc *memory.Allocator,
|
2018-10-05 22:02:31 +00:00
|
|
|
) *floatGroupTable {
|
|
|
|
t := &floatGroupTable{
|
2019-11-27 14:31:53 +00:00
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
2018-10-05 22:02:31 +00:00
|
|
|
gc: gc,
|
|
|
|
cur: cur,
|
|
|
|
}
|
|
|
|
t.readTags(tags)
|
2019-07-03 14:26:08 +00:00
|
|
|
t.advance()
|
2018-10-05 22:02:31 +00:00
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *floatGroupTable) Close() {
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Lock()
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.cur != nil {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
}
|
|
|
|
if t.gc != nil {
|
|
|
|
t.gc.Close()
|
|
|
|
t.gc = nil
|
|
|
|
}
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Unlock()
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *floatGroupTable) Do(f func(flux.ColReader) error) error {
|
2019-07-03 14:26:08 +00:00
|
|
|
return t.do(f, t.advance)
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
func (t *floatGroupTable) advance() bool {
|
2018-10-05 22:02:31 +00:00
|
|
|
RETRY:
|
|
|
|
a := t.cur.Next()
|
2019-05-30 17:31:54 +00:00
|
|
|
l := a.Len()
|
|
|
|
if l == 0 {
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.advanceCursor() {
|
|
|
|
goto RETRY
|
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
return false
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 17:31:54 +00:00
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2019-07-03 14:26:08 +00:00
|
|
|
cr := t.allocateBuffer(l)
|
2019-05-30 17:31:54 +00:00
|
|
|
cr.cols[timeColIdx] = arrow.NewInt(a.Timestamps, t.alloc)
|
|
|
|
cr.cols[valueColIdx] = t.toArrowBuffer(a.Values)
|
|
|
|
t.appendTags(cr)
|
|
|
|
t.appendBounds(cr)
|
2019-07-03 14:26:08 +00:00
|
|
|
return true
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *floatGroupTable) advanceCursor() bool {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
for t.gc.Next() {
|
|
|
|
cur := t.gc.Cursor()
|
|
|
|
if cur == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-10-08 22:22:59 +00:00
|
|
|
if typedCur, ok := cur.(cursors.FloatArrayCursor); !ok {
|
2018-10-05 22:02:31 +00:00
|
|
|
// TODO(sgc): error or skip?
|
|
|
|
cur.Close()
|
2020-04-09 21:40:41 +00:00
|
|
|
t.err = &influxdb.Error{
|
|
|
|
Code: influxdb.EInvalid,
|
|
|
|
Err: &GroupCursorError{
|
|
|
|
typ: "float",
|
|
|
|
cursor: cur,
|
|
|
|
},
|
|
|
|
}
|
2018-10-05 22:02:31 +00:00
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
t.readTags(t.gc.Tags())
|
2018-10-08 22:22:59 +00:00
|
|
|
t.cur = typedCur
|
2018-10-05 22:02:31 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-25 20:44:18 +00:00
|
|
|
func (t *floatGroupTable) Statistics() cursors.CursorStats {
|
2018-11-07 16:31:42 +00:00
|
|
|
if t.cur == nil {
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{}
|
2018-11-07 16:31:42 +00:00
|
|
|
}
|
|
|
|
cs := t.cur.Stats()
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{
|
2018-11-07 16:31:42 +00:00
|
|
|
ScannedValues: cs.ScannedValues,
|
|
|
|
ScannedBytes: cs.ScannedBytes,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
//
|
|
|
|
// *********** Integer ***********
|
|
|
|
//
|
|
|
|
|
|
|
|
type integerTable struct {
|
|
|
|
table
|
2019-05-16 01:40:29 +00:00
|
|
|
mu sync.Mutex
|
|
|
|
cur cursors.IntegerArrayCursor
|
|
|
|
alloc *memory.Allocator
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newIntegerTable(
|
2018-10-31 23:21:54 +00:00
|
|
|
done chan struct{},
|
2018-10-05 22:02:31 +00:00
|
|
|
cur cursors.IntegerArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
2019-11-27 14:31:53 +00:00
|
|
|
cache *tagsCache,
|
2019-03-06 21:29:45 +00:00
|
|
|
alloc *memory.Allocator,
|
2018-10-05 22:02:31 +00:00
|
|
|
) *integerTable {
|
|
|
|
t := &integerTable{
|
2019-11-27 14:31:53 +00:00
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
2018-10-05 22:02:31 +00:00
|
|
|
cur: cur,
|
|
|
|
}
|
|
|
|
t.readTags(tags)
|
2019-07-03 14:26:08 +00:00
|
|
|
t.advance()
|
2018-10-05 22:02:31 +00:00
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *integerTable) Close() {
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Lock()
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.cur != nil {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
}
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Unlock()
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 20:44:18 +00:00
|
|
|
func (t *integerTable) Statistics() cursors.CursorStats {
|
2018-11-07 16:31:42 +00:00
|
|
|
t.mu.Lock()
|
2018-12-13 18:05:14 +00:00
|
|
|
defer t.mu.Unlock()
|
2018-11-07 16:31:42 +00:00
|
|
|
cur := t.cur
|
|
|
|
if cur == nil {
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{}
|
2018-11-07 16:31:42 +00:00
|
|
|
}
|
|
|
|
cs := cur.Stats()
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{
|
2018-11-07 16:31:42 +00:00
|
|
|
ScannedValues: cs.ScannedValues,
|
|
|
|
ScannedBytes: cs.ScannedBytes,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
func (t *integerTable) Do(f func(flux.ColReader) error) error {
|
2019-07-03 14:26:08 +00:00
|
|
|
return t.do(f, t.advance)
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
func (t *integerTable) advance() bool {
|
2018-10-05 22:02:31 +00:00
|
|
|
a := t.cur.Next()
|
2019-05-30 17:31:54 +00:00
|
|
|
l := a.Len()
|
|
|
|
if l == 0 {
|
2019-07-03 14:26:08 +00:00
|
|
|
return false
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 17:31:54 +00:00
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2019-07-03 14:26:08 +00:00
|
|
|
cr := t.allocateBuffer(l)
|
2019-05-30 17:31:54 +00:00
|
|
|
cr.cols[timeColIdx] = arrow.NewInt(a.Timestamps, t.alloc)
|
|
|
|
cr.cols[valueColIdx] = t.toArrowBuffer(a.Values)
|
|
|
|
t.appendTags(cr)
|
|
|
|
t.appendBounds(cr)
|
2019-07-03 14:26:08 +00:00
|
|
|
return true
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 18:42:38 +00:00
|
|
|
// window table
|
|
|
|
type integerWindowTable struct {
|
|
|
|
integerTable
|
|
|
|
windowEvery int64
|
|
|
|
arr *cursors.IntegerArray
|
2020-06-01 22:57:50 +00:00
|
|
|
nextTS int64
|
2020-05-28 18:42:38 +00:00
|
|
|
idxInArr int
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty bool
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newIntegerWindowTable(
|
|
|
|
done chan struct{},
|
|
|
|
cur cursors.IntegerArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
every int64,
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty bool,
|
2020-05-28 18:42:38 +00:00
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
|
|
|
cache *tagsCache,
|
|
|
|
alloc *memory.Allocator,
|
|
|
|
) *integerWindowTable {
|
|
|
|
t := &integerWindowTable{
|
|
|
|
integerTable: integerTable{
|
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
|
|
|
cur: cur,
|
|
|
|
},
|
|
|
|
windowEvery: every,
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty: createEmpty,
|
|
|
|
}
|
|
|
|
if t.createEmpty {
|
|
|
|
start := int64(bounds.Start)
|
|
|
|
t.nextTS = start + (every - start%every)
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
|
|
|
t.readTags(tags)
|
|
|
|
t.advance()
|
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2020-06-01 22:57:50 +00:00
|
|
|
func (t *integerWindowTable) Do(f func(flux.ColReader) error) error {
|
|
|
|
return t.do(f, t.advance)
|
|
|
|
}
|
|
|
|
|
|
|
|
// createNextWindow will read the timestamps from the array
|
|
|
|
// cursor and construct the values for the next window.
|
|
|
|
func (t *integerWindowTable) createNextWindow() (start, stop *array.Int64, ok bool) {
|
|
|
|
var stopT int64
|
|
|
|
if t.createEmpty {
|
|
|
|
stopT = t.nextTS
|
|
|
|
t.nextTS += t.windowEvery
|
|
|
|
} else {
|
|
|
|
if !t.nextBuffer() {
|
|
|
|
return nil, nil, false
|
|
|
|
}
|
|
|
|
stopT = t.arr.Timestamps[t.idxInArr]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Regain the window start time from the window end time.
|
|
|
|
startT := stopT - t.windowEvery
|
|
|
|
if startT < int64(t.bounds.Start) {
|
|
|
|
startT = int64(t.bounds.Start)
|
|
|
|
}
|
|
|
|
if stopT > int64(t.bounds.Stop) {
|
|
|
|
stopT = int64(t.bounds.Stop)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the start time is after our stop boundary,
|
|
|
|
// we exit here when create empty is true.
|
|
|
|
if t.createEmpty && startT >= int64(t.bounds.Stop) {
|
|
|
|
return nil, nil, false
|
|
|
|
}
|
|
|
|
start = arrow.NewInt([]int64{startT}, t.alloc)
|
|
|
|
stop = arrow.NewInt([]int64{stopT}, t.alloc)
|
|
|
|
return start, stop, true
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextAt will retrieve the next value that can be used with
|
|
|
|
// the given stop timestamp. If no values can be used with the timestamp,
|
|
|
|
// it will return the default value and false.
|
|
|
|
func (t *integerWindowTable) nextAt(ts int64) (v int64, ok bool) {
|
|
|
|
if !t.nextBuffer() {
|
|
|
|
return
|
|
|
|
} else if !t.isInWindow(ts, t.arr.Timestamps[t.idxInArr]) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
v, ok = t.arr.Values[t.idxInArr], true
|
|
|
|
t.idxInArr++
|
|
|
|
return v, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// isInWindow will check if the given time at stop can be used within
|
|
|
|
// the window stop time for ts. The ts may be a truncated stop time
|
|
|
|
// because of a restricted boundary while stop will be the true
|
|
|
|
// stop time returned by storage.
|
|
|
|
func (t *integerWindowTable) isInWindow(ts int64, stop int64) bool {
|
|
|
|
// This method checks if the stop time is a valid stop time for
|
|
|
|
// that interval. This calculation is different from the calculation
|
|
|
|
// of the window itself. For example, for a 10 second window that
|
|
|
|
// starts at 20 seconds, we would include points between [20, 30).
|
|
|
|
// The stop time for this interval would be 30, but because the stop
|
|
|
|
// time can be truncated, valid stop times range from anywhere between
|
|
|
|
// (20, 30]. The storage engine will always produce 30 as the end time
|
|
|
|
// but we may have truncated the stop time because of the boundary
|
|
|
|
// and this is why we are checking for this range instead of checking
|
|
|
|
// if the two values are equal.
|
|
|
|
start := stop - t.windowEvery
|
|
|
|
return start < ts && ts <= stop
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextBuffer will ensure the array cursor is filled
|
|
|
|
// and will return true if there is at least one value
|
|
|
|
// that can be read from it.
|
|
|
|
func (t *integerWindowTable) nextBuffer() bool {
|
|
|
|
// Discard the current array cursor if we have
|
|
|
|
// exceeded it.
|
|
|
|
if t.arr != nil && t.idxInArr >= t.arr.Len() {
|
|
|
|
t.arr = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the next array cursor if needed.
|
2020-05-28 18:42:38 +00:00
|
|
|
if t.arr == nil {
|
2020-06-01 22:57:50 +00:00
|
|
|
arr := t.cur.Next()
|
|
|
|
if arr.Len() == 0 {
|
2020-05-28 18:42:38 +00:00
|
|
|
return false
|
|
|
|
}
|
2020-06-01 22:57:50 +00:00
|
|
|
t.arr, t.idxInArr = arr, 0
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
2020-06-01 22:57:50 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// appendValues will scan the timestamps and append values
|
|
|
|
// that match those timestamps from the buffer.
|
|
|
|
func (t *integerWindowTable) appendValues(intervals []int64, appendValue func(v int64), appendNull func()) {
|
|
|
|
for i := 0; i < len(intervals); i++ {
|
|
|
|
if v, ok := t.nextAt(intervals[i]); ok {
|
|
|
|
appendValue(v)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
appendNull()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *integerWindowTable) advance() bool {
|
|
|
|
// Create the timestamps for the next window.
|
|
|
|
start, stop, ok := t.createNextWindow()
|
|
|
|
if !ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
values := t.mergeValues(stop.Int64Values())
|
2020-05-28 18:42:38 +00:00
|
|
|
|
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2020-06-01 22:57:50 +00:00
|
|
|
cr := t.allocateBuffer(stop.Len())
|
|
|
|
cr.cols[startColIdx] = start
|
|
|
|
cr.cols[stopColIdx] = stop
|
|
|
|
cr.cols[windowedValueColIdx] = values
|
|
|
|
t.appendTags(cr)
|
2020-05-28 18:42:38 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
// group table
|
|
|
|
|
|
|
|
type integerGroupTable struct {
|
|
|
|
table
|
2019-05-16 01:40:29 +00:00
|
|
|
mu sync.Mutex
|
2020-03-10 05:00:52 +00:00
|
|
|
gc storage.GroupCursor
|
2019-05-16 01:40:29 +00:00
|
|
|
cur cursors.IntegerArrayCursor
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newIntegerGroupTable(
|
2018-10-31 23:21:54 +00:00
|
|
|
done chan struct{},
|
2020-03-10 05:00:52 +00:00
|
|
|
gc storage.GroupCursor,
|
2018-10-05 22:02:31 +00:00
|
|
|
cur cursors.IntegerArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
2019-11-27 14:31:53 +00:00
|
|
|
cache *tagsCache,
|
2019-03-06 21:29:45 +00:00
|
|
|
alloc *memory.Allocator,
|
2018-10-05 22:02:31 +00:00
|
|
|
) *integerGroupTable {
|
|
|
|
t := &integerGroupTable{
|
2019-11-27 14:31:53 +00:00
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
2018-10-05 22:02:31 +00:00
|
|
|
gc: gc,
|
|
|
|
cur: cur,
|
|
|
|
}
|
|
|
|
t.readTags(tags)
|
2019-07-03 14:26:08 +00:00
|
|
|
t.advance()
|
2018-10-05 22:02:31 +00:00
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *integerGroupTable) Close() {
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Lock()
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.cur != nil {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
}
|
|
|
|
if t.gc != nil {
|
|
|
|
t.gc.Close()
|
|
|
|
t.gc = nil
|
|
|
|
}
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Unlock()
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *integerGroupTable) Do(f func(flux.ColReader) error) error {
|
2019-07-03 14:26:08 +00:00
|
|
|
return t.do(f, t.advance)
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
func (t *integerGroupTable) advance() bool {
|
2018-10-05 22:02:31 +00:00
|
|
|
RETRY:
|
|
|
|
a := t.cur.Next()
|
2019-05-30 17:31:54 +00:00
|
|
|
l := a.Len()
|
|
|
|
if l == 0 {
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.advanceCursor() {
|
|
|
|
goto RETRY
|
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
return false
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 17:31:54 +00:00
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2019-07-03 14:26:08 +00:00
|
|
|
cr := t.allocateBuffer(l)
|
2019-05-30 17:31:54 +00:00
|
|
|
cr.cols[timeColIdx] = arrow.NewInt(a.Timestamps, t.alloc)
|
|
|
|
cr.cols[valueColIdx] = t.toArrowBuffer(a.Values)
|
|
|
|
t.appendTags(cr)
|
|
|
|
t.appendBounds(cr)
|
2019-07-03 14:26:08 +00:00
|
|
|
return true
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *integerGroupTable) advanceCursor() bool {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
for t.gc.Next() {
|
|
|
|
cur := t.gc.Cursor()
|
|
|
|
if cur == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-10-08 22:22:59 +00:00
|
|
|
if typedCur, ok := cur.(cursors.IntegerArrayCursor); !ok {
|
2018-10-05 22:02:31 +00:00
|
|
|
// TODO(sgc): error or skip?
|
|
|
|
cur.Close()
|
2020-04-09 21:40:41 +00:00
|
|
|
t.err = &influxdb.Error{
|
|
|
|
Code: influxdb.EInvalid,
|
|
|
|
Err: &GroupCursorError{
|
|
|
|
typ: "integer",
|
|
|
|
cursor: cur,
|
|
|
|
},
|
|
|
|
}
|
2018-10-05 22:02:31 +00:00
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
t.readTags(t.gc.Tags())
|
2018-10-08 22:22:59 +00:00
|
|
|
t.cur = typedCur
|
2018-10-05 22:02:31 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-25 20:44:18 +00:00
|
|
|
func (t *integerGroupTable) Statistics() cursors.CursorStats {
|
2018-11-07 16:31:42 +00:00
|
|
|
if t.cur == nil {
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{}
|
2018-11-07 16:31:42 +00:00
|
|
|
}
|
|
|
|
cs := t.cur.Stats()
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{
|
2018-11-07 16:31:42 +00:00
|
|
|
ScannedValues: cs.ScannedValues,
|
|
|
|
ScannedBytes: cs.ScannedBytes,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
//
|
|
|
|
// *********** Unsigned ***********
|
|
|
|
//
|
|
|
|
|
|
|
|
type unsignedTable struct {
|
|
|
|
table
|
2019-05-16 01:40:29 +00:00
|
|
|
mu sync.Mutex
|
|
|
|
cur cursors.UnsignedArrayCursor
|
|
|
|
alloc *memory.Allocator
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newUnsignedTable(
|
2018-10-31 23:21:54 +00:00
|
|
|
done chan struct{},
|
2018-10-05 22:02:31 +00:00
|
|
|
cur cursors.UnsignedArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
2019-11-27 14:31:53 +00:00
|
|
|
cache *tagsCache,
|
2019-03-06 21:29:45 +00:00
|
|
|
alloc *memory.Allocator,
|
2018-10-05 22:02:31 +00:00
|
|
|
) *unsignedTable {
|
|
|
|
t := &unsignedTable{
|
2019-11-27 14:31:53 +00:00
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
2018-10-05 22:02:31 +00:00
|
|
|
cur: cur,
|
|
|
|
}
|
|
|
|
t.readTags(tags)
|
2019-07-03 14:26:08 +00:00
|
|
|
t.advance()
|
2018-10-05 22:02:31 +00:00
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *unsignedTable) Close() {
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Lock()
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.cur != nil {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
}
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Unlock()
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 20:44:18 +00:00
|
|
|
func (t *unsignedTable) Statistics() cursors.CursorStats {
|
2018-11-07 16:31:42 +00:00
|
|
|
t.mu.Lock()
|
2018-12-13 18:05:14 +00:00
|
|
|
defer t.mu.Unlock()
|
2018-11-07 16:31:42 +00:00
|
|
|
cur := t.cur
|
|
|
|
if cur == nil {
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{}
|
2018-11-07 16:31:42 +00:00
|
|
|
}
|
|
|
|
cs := cur.Stats()
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{
|
2018-11-07 16:31:42 +00:00
|
|
|
ScannedValues: cs.ScannedValues,
|
|
|
|
ScannedBytes: cs.ScannedBytes,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
func (t *unsignedTable) Do(f func(flux.ColReader) error) error {
|
2019-07-03 14:26:08 +00:00
|
|
|
return t.do(f, t.advance)
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
func (t *unsignedTable) advance() bool {
|
2018-10-05 22:02:31 +00:00
|
|
|
a := t.cur.Next()
|
2019-05-30 17:31:54 +00:00
|
|
|
l := a.Len()
|
|
|
|
if l == 0 {
|
2019-07-03 14:26:08 +00:00
|
|
|
return false
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 17:31:54 +00:00
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2019-07-03 14:26:08 +00:00
|
|
|
cr := t.allocateBuffer(l)
|
2019-05-30 17:31:54 +00:00
|
|
|
cr.cols[timeColIdx] = arrow.NewInt(a.Timestamps, t.alloc)
|
|
|
|
cr.cols[valueColIdx] = t.toArrowBuffer(a.Values)
|
|
|
|
t.appendTags(cr)
|
|
|
|
t.appendBounds(cr)
|
2019-07-03 14:26:08 +00:00
|
|
|
return true
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 18:42:38 +00:00
|
|
|
// window table
|
|
|
|
type unsignedWindowTable struct {
|
|
|
|
unsignedTable
|
|
|
|
windowEvery int64
|
|
|
|
arr *cursors.UnsignedArray
|
2020-06-01 22:57:50 +00:00
|
|
|
nextTS int64
|
2020-05-28 18:42:38 +00:00
|
|
|
idxInArr int
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty bool
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newUnsignedWindowTable(
|
|
|
|
done chan struct{},
|
|
|
|
cur cursors.UnsignedArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
every int64,
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty bool,
|
2020-05-28 18:42:38 +00:00
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
|
|
|
cache *tagsCache,
|
|
|
|
alloc *memory.Allocator,
|
|
|
|
) *unsignedWindowTable {
|
|
|
|
t := &unsignedWindowTable{
|
|
|
|
unsignedTable: unsignedTable{
|
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
|
|
|
cur: cur,
|
|
|
|
},
|
|
|
|
windowEvery: every,
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty: createEmpty,
|
|
|
|
}
|
|
|
|
if t.createEmpty {
|
|
|
|
start := int64(bounds.Start)
|
|
|
|
t.nextTS = start + (every - start%every)
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
|
|
|
t.readTags(tags)
|
|
|
|
t.advance()
|
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2020-06-01 22:57:50 +00:00
|
|
|
func (t *unsignedWindowTable) Do(f func(flux.ColReader) error) error {
|
|
|
|
return t.do(f, t.advance)
|
|
|
|
}
|
|
|
|
|
|
|
|
// createNextWindow will read the timestamps from the array
|
|
|
|
// cursor and construct the values for the next window.
|
|
|
|
func (t *unsignedWindowTable) createNextWindow() (start, stop *array.Int64, ok bool) {
|
|
|
|
var stopT int64
|
|
|
|
if t.createEmpty {
|
|
|
|
stopT = t.nextTS
|
|
|
|
t.nextTS += t.windowEvery
|
|
|
|
} else {
|
|
|
|
if !t.nextBuffer() {
|
|
|
|
return nil, nil, false
|
|
|
|
}
|
|
|
|
stopT = t.arr.Timestamps[t.idxInArr]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Regain the window start time from the window end time.
|
|
|
|
startT := stopT - t.windowEvery
|
|
|
|
if startT < int64(t.bounds.Start) {
|
|
|
|
startT = int64(t.bounds.Start)
|
|
|
|
}
|
|
|
|
if stopT > int64(t.bounds.Stop) {
|
|
|
|
stopT = int64(t.bounds.Stop)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the start time is after our stop boundary,
|
|
|
|
// we exit here when create empty is true.
|
|
|
|
if t.createEmpty && startT >= int64(t.bounds.Stop) {
|
|
|
|
return nil, nil, false
|
|
|
|
}
|
|
|
|
start = arrow.NewInt([]int64{startT}, t.alloc)
|
|
|
|
stop = arrow.NewInt([]int64{stopT}, t.alloc)
|
|
|
|
return start, stop, true
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextAt will retrieve the next value that can be used with
|
|
|
|
// the given stop timestamp. If no values can be used with the timestamp,
|
|
|
|
// it will return the default value and false.
|
|
|
|
func (t *unsignedWindowTable) nextAt(ts int64) (v uint64, ok bool) {
|
|
|
|
if !t.nextBuffer() {
|
|
|
|
return
|
|
|
|
} else if !t.isInWindow(ts, t.arr.Timestamps[t.idxInArr]) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
v, ok = t.arr.Values[t.idxInArr], true
|
|
|
|
t.idxInArr++
|
|
|
|
return v, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// isInWindow will check if the given time at stop can be used within
|
|
|
|
// the window stop time for ts. The ts may be a truncated stop time
|
|
|
|
// because of a restricted boundary while stop will be the true
|
|
|
|
// stop time returned by storage.
|
|
|
|
func (t *unsignedWindowTable) isInWindow(ts int64, stop int64) bool {
|
|
|
|
// This method checks if the stop time is a valid stop time for
|
|
|
|
// that interval. This calculation is different from the calculation
|
|
|
|
// of the window itself. For example, for a 10 second window that
|
|
|
|
// starts at 20 seconds, we would include points between [20, 30).
|
|
|
|
// The stop time for this interval would be 30, but because the stop
|
|
|
|
// time can be truncated, valid stop times range from anywhere between
|
|
|
|
// (20, 30]. The storage engine will always produce 30 as the end time
|
|
|
|
// but we may have truncated the stop time because of the boundary
|
|
|
|
// and this is why we are checking for this range instead of checking
|
|
|
|
// if the two values are equal.
|
|
|
|
start := stop - t.windowEvery
|
|
|
|
return start < ts && ts <= stop
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextBuffer will ensure the array cursor is filled
|
|
|
|
// and will return true if there is at least one value
|
|
|
|
// that can be read from it.
|
|
|
|
func (t *unsignedWindowTable) nextBuffer() bool {
|
|
|
|
// Discard the current array cursor if we have
|
|
|
|
// exceeded it.
|
|
|
|
if t.arr != nil && t.idxInArr >= t.arr.Len() {
|
|
|
|
t.arr = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the next array cursor if needed.
|
2020-05-28 18:42:38 +00:00
|
|
|
if t.arr == nil {
|
2020-06-01 22:57:50 +00:00
|
|
|
arr := t.cur.Next()
|
|
|
|
if arr.Len() == 0 {
|
2020-05-28 18:42:38 +00:00
|
|
|
return false
|
|
|
|
}
|
2020-06-01 22:57:50 +00:00
|
|
|
t.arr, t.idxInArr = arr, 0
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// appendValues will scan the timestamps and append values
|
|
|
|
// that match those timestamps from the buffer.
|
|
|
|
func (t *unsignedWindowTable) appendValues(intervals []int64, appendValue func(v uint64), appendNull func()) {
|
|
|
|
for i := 0; i < len(intervals); i++ {
|
|
|
|
if v, ok := t.nextAt(intervals[i]); ok {
|
|
|
|
appendValue(v)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
appendNull()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *unsignedWindowTable) advance() bool {
|
|
|
|
// Create the timestamps for the next window.
|
|
|
|
start, stop, ok := t.createNextWindow()
|
|
|
|
if !ok {
|
|
|
|
return false
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
2020-06-01 22:57:50 +00:00
|
|
|
values := t.mergeValues(stop.Int64Values())
|
2020-05-28 18:42:38 +00:00
|
|
|
|
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2020-06-01 22:57:50 +00:00
|
|
|
cr := t.allocateBuffer(stop.Len())
|
|
|
|
cr.cols[startColIdx] = start
|
|
|
|
cr.cols[stopColIdx] = stop
|
|
|
|
cr.cols[windowedValueColIdx] = values
|
|
|
|
t.appendTags(cr)
|
2020-05-28 18:42:38 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
// group table
|
|
|
|
|
|
|
|
type unsignedGroupTable struct {
|
|
|
|
table
|
2019-05-16 01:40:29 +00:00
|
|
|
mu sync.Mutex
|
2020-03-10 05:00:52 +00:00
|
|
|
gc storage.GroupCursor
|
2019-05-16 01:40:29 +00:00
|
|
|
cur cursors.UnsignedArrayCursor
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newUnsignedGroupTable(
|
2018-10-31 23:21:54 +00:00
|
|
|
done chan struct{},
|
2020-03-10 05:00:52 +00:00
|
|
|
gc storage.GroupCursor,
|
2018-10-05 22:02:31 +00:00
|
|
|
cur cursors.UnsignedArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
2019-11-27 14:31:53 +00:00
|
|
|
cache *tagsCache,
|
2019-03-06 21:29:45 +00:00
|
|
|
alloc *memory.Allocator,
|
2018-10-05 22:02:31 +00:00
|
|
|
) *unsignedGroupTable {
|
|
|
|
t := &unsignedGroupTable{
|
2019-11-27 14:31:53 +00:00
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
2018-10-05 22:02:31 +00:00
|
|
|
gc: gc,
|
|
|
|
cur: cur,
|
|
|
|
}
|
|
|
|
t.readTags(tags)
|
2019-07-03 14:26:08 +00:00
|
|
|
t.advance()
|
2018-10-05 22:02:31 +00:00
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *unsignedGroupTable) Close() {
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Lock()
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.cur != nil {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
}
|
|
|
|
if t.gc != nil {
|
|
|
|
t.gc.Close()
|
|
|
|
t.gc = nil
|
|
|
|
}
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Unlock()
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *unsignedGroupTable) Do(f func(flux.ColReader) error) error {
|
2019-07-03 14:26:08 +00:00
|
|
|
return t.do(f, t.advance)
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
func (t *unsignedGroupTable) advance() bool {
|
2018-10-05 22:02:31 +00:00
|
|
|
RETRY:
|
|
|
|
a := t.cur.Next()
|
2019-05-30 17:31:54 +00:00
|
|
|
l := a.Len()
|
|
|
|
if l == 0 {
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.advanceCursor() {
|
|
|
|
goto RETRY
|
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
return false
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 17:31:54 +00:00
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2019-07-03 14:26:08 +00:00
|
|
|
cr := t.allocateBuffer(l)
|
2019-05-30 17:31:54 +00:00
|
|
|
cr.cols[timeColIdx] = arrow.NewInt(a.Timestamps, t.alloc)
|
|
|
|
cr.cols[valueColIdx] = t.toArrowBuffer(a.Values)
|
|
|
|
t.appendTags(cr)
|
|
|
|
t.appendBounds(cr)
|
2019-07-03 14:26:08 +00:00
|
|
|
return true
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *unsignedGroupTable) advanceCursor() bool {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
for t.gc.Next() {
|
|
|
|
cur := t.gc.Cursor()
|
|
|
|
if cur == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-10-08 22:22:59 +00:00
|
|
|
if typedCur, ok := cur.(cursors.UnsignedArrayCursor); !ok {
|
2018-10-05 22:02:31 +00:00
|
|
|
// TODO(sgc): error or skip?
|
|
|
|
cur.Close()
|
2020-04-09 21:40:41 +00:00
|
|
|
t.err = &influxdb.Error{
|
|
|
|
Code: influxdb.EInvalid,
|
|
|
|
Err: &GroupCursorError{
|
|
|
|
typ: "unsigned",
|
|
|
|
cursor: cur,
|
|
|
|
},
|
|
|
|
}
|
2018-10-05 22:02:31 +00:00
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
t.readTags(t.gc.Tags())
|
2018-10-08 22:22:59 +00:00
|
|
|
t.cur = typedCur
|
2018-10-05 22:02:31 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-25 20:44:18 +00:00
|
|
|
func (t *unsignedGroupTable) Statistics() cursors.CursorStats {
|
2018-11-07 16:31:42 +00:00
|
|
|
if t.cur == nil {
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{}
|
2018-11-07 16:31:42 +00:00
|
|
|
}
|
|
|
|
cs := t.cur.Stats()
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{
|
2018-11-07 16:31:42 +00:00
|
|
|
ScannedValues: cs.ScannedValues,
|
|
|
|
ScannedBytes: cs.ScannedBytes,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
//
|
|
|
|
// *********** String ***********
|
|
|
|
//
|
|
|
|
|
|
|
|
type stringTable struct {
|
|
|
|
table
|
2019-05-16 01:40:29 +00:00
|
|
|
mu sync.Mutex
|
|
|
|
cur cursors.StringArrayCursor
|
|
|
|
alloc *memory.Allocator
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newStringTable(
|
2018-10-31 23:21:54 +00:00
|
|
|
done chan struct{},
|
2018-10-05 22:02:31 +00:00
|
|
|
cur cursors.StringArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
2019-11-27 14:31:53 +00:00
|
|
|
cache *tagsCache,
|
2019-03-06 21:29:45 +00:00
|
|
|
alloc *memory.Allocator,
|
2018-10-05 22:02:31 +00:00
|
|
|
) *stringTable {
|
|
|
|
t := &stringTable{
|
2019-11-27 14:31:53 +00:00
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
2018-10-05 22:02:31 +00:00
|
|
|
cur: cur,
|
|
|
|
}
|
|
|
|
t.readTags(tags)
|
2019-07-03 14:26:08 +00:00
|
|
|
t.advance()
|
2018-10-05 22:02:31 +00:00
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *stringTable) Close() {
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Lock()
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.cur != nil {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
}
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Unlock()
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 20:44:18 +00:00
|
|
|
func (t *stringTable) Statistics() cursors.CursorStats {
|
2018-11-07 16:31:42 +00:00
|
|
|
t.mu.Lock()
|
2018-12-13 18:05:14 +00:00
|
|
|
defer t.mu.Unlock()
|
2018-11-07 16:31:42 +00:00
|
|
|
cur := t.cur
|
|
|
|
if cur == nil {
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{}
|
2018-11-07 16:31:42 +00:00
|
|
|
}
|
|
|
|
cs := cur.Stats()
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{
|
2018-11-07 16:31:42 +00:00
|
|
|
ScannedValues: cs.ScannedValues,
|
|
|
|
ScannedBytes: cs.ScannedBytes,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
func (t *stringTable) Do(f func(flux.ColReader) error) error {
|
2019-07-03 14:26:08 +00:00
|
|
|
return t.do(f, t.advance)
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
func (t *stringTable) advance() bool {
|
2018-10-05 22:02:31 +00:00
|
|
|
a := t.cur.Next()
|
2019-05-30 17:31:54 +00:00
|
|
|
l := a.Len()
|
|
|
|
if l == 0 {
|
2019-07-03 14:26:08 +00:00
|
|
|
return false
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 17:31:54 +00:00
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2019-07-03 14:26:08 +00:00
|
|
|
cr := t.allocateBuffer(l)
|
2019-05-30 17:31:54 +00:00
|
|
|
cr.cols[timeColIdx] = arrow.NewInt(a.Timestamps, t.alloc)
|
|
|
|
cr.cols[valueColIdx] = t.toArrowBuffer(a.Values)
|
|
|
|
t.appendTags(cr)
|
|
|
|
t.appendBounds(cr)
|
2019-07-03 14:26:08 +00:00
|
|
|
return true
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 18:42:38 +00:00
|
|
|
// window table
|
|
|
|
type stringWindowTable struct {
|
|
|
|
stringTable
|
|
|
|
windowEvery int64
|
|
|
|
arr *cursors.StringArray
|
2020-06-01 22:57:50 +00:00
|
|
|
nextTS int64
|
2020-05-28 18:42:38 +00:00
|
|
|
idxInArr int
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty bool
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newStringWindowTable(
|
|
|
|
done chan struct{},
|
|
|
|
cur cursors.StringArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
every int64,
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty bool,
|
2020-05-28 18:42:38 +00:00
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
|
|
|
cache *tagsCache,
|
|
|
|
alloc *memory.Allocator,
|
|
|
|
) *stringWindowTable {
|
|
|
|
t := &stringWindowTable{
|
|
|
|
stringTable: stringTable{
|
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
|
|
|
cur: cur,
|
|
|
|
},
|
|
|
|
windowEvery: every,
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty: createEmpty,
|
|
|
|
}
|
|
|
|
if t.createEmpty {
|
|
|
|
start := int64(bounds.Start)
|
|
|
|
t.nextTS = start + (every - start%every)
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
|
|
|
t.readTags(tags)
|
|
|
|
t.advance()
|
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2020-06-01 22:57:50 +00:00
|
|
|
func (t *stringWindowTable) Do(f func(flux.ColReader) error) error {
|
|
|
|
return t.do(f, t.advance)
|
|
|
|
}
|
|
|
|
|
|
|
|
// createNextWindow will read the timestamps from the array
|
|
|
|
// cursor and construct the values for the next window.
|
|
|
|
func (t *stringWindowTable) createNextWindow() (start, stop *array.Int64, ok bool) {
|
|
|
|
var stopT int64
|
|
|
|
if t.createEmpty {
|
|
|
|
stopT = t.nextTS
|
|
|
|
t.nextTS += t.windowEvery
|
|
|
|
} else {
|
|
|
|
if !t.nextBuffer() {
|
|
|
|
return nil, nil, false
|
|
|
|
}
|
|
|
|
stopT = t.arr.Timestamps[t.idxInArr]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Regain the window start time from the window end time.
|
|
|
|
startT := stopT - t.windowEvery
|
|
|
|
if startT < int64(t.bounds.Start) {
|
|
|
|
startT = int64(t.bounds.Start)
|
|
|
|
}
|
|
|
|
if stopT > int64(t.bounds.Stop) {
|
|
|
|
stopT = int64(t.bounds.Stop)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the start time is after our stop boundary,
|
|
|
|
// we exit here when create empty is true.
|
|
|
|
if t.createEmpty && startT >= int64(t.bounds.Stop) {
|
|
|
|
return nil, nil, false
|
|
|
|
}
|
|
|
|
start = arrow.NewInt([]int64{startT}, t.alloc)
|
|
|
|
stop = arrow.NewInt([]int64{stopT}, t.alloc)
|
|
|
|
return start, stop, true
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextAt will retrieve the next value that can be used with
|
|
|
|
// the given stop timestamp. If no values can be used with the timestamp,
|
|
|
|
// it will return the default value and false.
|
|
|
|
func (t *stringWindowTable) nextAt(ts int64) (v string, ok bool) {
|
|
|
|
if !t.nextBuffer() {
|
|
|
|
return
|
|
|
|
} else if !t.isInWindow(ts, t.arr.Timestamps[t.idxInArr]) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
v, ok = t.arr.Values[t.idxInArr], true
|
|
|
|
t.idxInArr++
|
|
|
|
return v, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// isInWindow will check if the given time at stop can be used within
|
|
|
|
// the window stop time for ts. The ts may be a truncated stop time
|
|
|
|
// because of a restricted boundary while stop will be the true
|
|
|
|
// stop time returned by storage.
|
|
|
|
func (t *stringWindowTable) isInWindow(ts int64, stop int64) bool {
|
|
|
|
// This method checks if the stop time is a valid stop time for
|
|
|
|
// that interval. This calculation is different from the calculation
|
|
|
|
// of the window itself. For example, for a 10 second window that
|
|
|
|
// starts at 20 seconds, we would include points between [20, 30).
|
|
|
|
// The stop time for this interval would be 30, but because the stop
|
|
|
|
// time can be truncated, valid stop times range from anywhere between
|
|
|
|
// (20, 30]. The storage engine will always produce 30 as the end time
|
|
|
|
// but we may have truncated the stop time because of the boundary
|
|
|
|
// and this is why we are checking for this range instead of checking
|
|
|
|
// if the two values are equal.
|
|
|
|
start := stop - t.windowEvery
|
|
|
|
return start < ts && ts <= stop
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextBuffer will ensure the array cursor is filled
|
|
|
|
// and will return true if there is at least one value
|
|
|
|
// that can be read from it.
|
|
|
|
func (t *stringWindowTable) nextBuffer() bool {
|
|
|
|
// Discard the current array cursor if we have
|
|
|
|
// exceeded it.
|
|
|
|
if t.arr != nil && t.idxInArr >= t.arr.Len() {
|
|
|
|
t.arr = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the next array cursor if needed.
|
2020-05-28 18:42:38 +00:00
|
|
|
if t.arr == nil {
|
2020-06-01 22:57:50 +00:00
|
|
|
arr := t.cur.Next()
|
|
|
|
if arr.Len() == 0 {
|
2020-05-28 18:42:38 +00:00
|
|
|
return false
|
|
|
|
}
|
2020-06-01 22:57:50 +00:00
|
|
|
t.arr, t.idxInArr = arr, 0
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// appendValues will scan the timestamps and append values
|
|
|
|
// that match those timestamps from the buffer.
|
|
|
|
func (t *stringWindowTable) appendValues(intervals []int64, appendValue func(v string), appendNull func()) {
|
|
|
|
for i := 0; i < len(intervals); i++ {
|
|
|
|
if v, ok := t.nextAt(intervals[i]); ok {
|
|
|
|
appendValue(v)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
appendNull()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *stringWindowTable) advance() bool {
|
|
|
|
// Create the timestamps for the next window.
|
|
|
|
start, stop, ok := t.createNextWindow()
|
|
|
|
if !ok {
|
|
|
|
return false
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
2020-06-01 22:57:50 +00:00
|
|
|
values := t.mergeValues(stop.Int64Values())
|
2020-05-28 18:42:38 +00:00
|
|
|
|
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2020-06-01 22:57:50 +00:00
|
|
|
cr := t.allocateBuffer(stop.Len())
|
|
|
|
cr.cols[startColIdx] = start
|
|
|
|
cr.cols[stopColIdx] = stop
|
|
|
|
cr.cols[windowedValueColIdx] = values
|
|
|
|
t.appendTags(cr)
|
2020-05-28 18:42:38 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
// group table
|
|
|
|
|
|
|
|
type stringGroupTable struct {
|
|
|
|
table
|
2019-05-16 01:40:29 +00:00
|
|
|
mu sync.Mutex
|
2020-03-10 05:00:52 +00:00
|
|
|
gc storage.GroupCursor
|
2019-05-16 01:40:29 +00:00
|
|
|
cur cursors.StringArrayCursor
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newStringGroupTable(
|
2018-10-31 23:21:54 +00:00
|
|
|
done chan struct{},
|
2020-03-10 05:00:52 +00:00
|
|
|
gc storage.GroupCursor,
|
2018-10-05 22:02:31 +00:00
|
|
|
cur cursors.StringArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
2019-11-27 14:31:53 +00:00
|
|
|
cache *tagsCache,
|
2019-03-06 21:29:45 +00:00
|
|
|
alloc *memory.Allocator,
|
2018-10-05 22:02:31 +00:00
|
|
|
) *stringGroupTable {
|
|
|
|
t := &stringGroupTable{
|
2019-11-27 14:31:53 +00:00
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
2018-10-05 22:02:31 +00:00
|
|
|
gc: gc,
|
|
|
|
cur: cur,
|
|
|
|
}
|
|
|
|
t.readTags(tags)
|
2019-07-03 14:26:08 +00:00
|
|
|
t.advance()
|
2018-10-05 22:02:31 +00:00
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *stringGroupTable) Close() {
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Lock()
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.cur != nil {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
}
|
|
|
|
if t.gc != nil {
|
|
|
|
t.gc.Close()
|
|
|
|
t.gc = nil
|
|
|
|
}
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Unlock()
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *stringGroupTable) Do(f func(flux.ColReader) error) error {
|
2019-07-03 14:26:08 +00:00
|
|
|
return t.do(f, t.advance)
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
func (t *stringGroupTable) advance() bool {
|
2018-10-05 22:02:31 +00:00
|
|
|
RETRY:
|
|
|
|
a := t.cur.Next()
|
2019-05-30 17:31:54 +00:00
|
|
|
l := a.Len()
|
|
|
|
if l == 0 {
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.advanceCursor() {
|
|
|
|
goto RETRY
|
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
return false
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 17:31:54 +00:00
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2019-07-03 14:26:08 +00:00
|
|
|
cr := t.allocateBuffer(l)
|
2019-05-30 17:31:54 +00:00
|
|
|
cr.cols[timeColIdx] = arrow.NewInt(a.Timestamps, t.alloc)
|
|
|
|
cr.cols[valueColIdx] = t.toArrowBuffer(a.Values)
|
|
|
|
t.appendTags(cr)
|
|
|
|
t.appendBounds(cr)
|
2019-07-03 14:26:08 +00:00
|
|
|
return true
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *stringGroupTable) advanceCursor() bool {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
for t.gc.Next() {
|
|
|
|
cur := t.gc.Cursor()
|
|
|
|
if cur == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-10-08 22:22:59 +00:00
|
|
|
if typedCur, ok := cur.(cursors.StringArrayCursor); !ok {
|
2018-10-05 22:02:31 +00:00
|
|
|
// TODO(sgc): error or skip?
|
|
|
|
cur.Close()
|
2020-04-09 21:40:41 +00:00
|
|
|
t.err = &influxdb.Error{
|
|
|
|
Code: influxdb.EInvalid,
|
|
|
|
Err: &GroupCursorError{
|
|
|
|
typ: "string",
|
|
|
|
cursor: cur,
|
|
|
|
},
|
|
|
|
}
|
2018-10-05 22:02:31 +00:00
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
t.readTags(t.gc.Tags())
|
2018-10-08 22:22:59 +00:00
|
|
|
t.cur = typedCur
|
2018-10-05 22:02:31 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-25 20:44:18 +00:00
|
|
|
func (t *stringGroupTable) Statistics() cursors.CursorStats {
|
2018-11-07 16:31:42 +00:00
|
|
|
if t.cur == nil {
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{}
|
2018-11-07 16:31:42 +00:00
|
|
|
}
|
|
|
|
cs := t.cur.Stats()
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{
|
2018-11-07 16:31:42 +00:00
|
|
|
ScannedValues: cs.ScannedValues,
|
|
|
|
ScannedBytes: cs.ScannedBytes,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
//
|
|
|
|
// *********** Boolean ***********
|
|
|
|
//
|
|
|
|
|
|
|
|
type booleanTable struct {
|
|
|
|
table
|
2019-05-16 01:40:29 +00:00
|
|
|
mu sync.Mutex
|
|
|
|
cur cursors.BooleanArrayCursor
|
|
|
|
alloc *memory.Allocator
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newBooleanTable(
|
2018-10-31 23:21:54 +00:00
|
|
|
done chan struct{},
|
2018-10-05 22:02:31 +00:00
|
|
|
cur cursors.BooleanArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
2019-11-27 14:31:53 +00:00
|
|
|
cache *tagsCache,
|
2019-03-06 21:29:45 +00:00
|
|
|
alloc *memory.Allocator,
|
2018-10-05 22:02:31 +00:00
|
|
|
) *booleanTable {
|
|
|
|
t := &booleanTable{
|
2019-11-27 14:31:53 +00:00
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
2018-10-05 22:02:31 +00:00
|
|
|
cur: cur,
|
|
|
|
}
|
|
|
|
t.readTags(tags)
|
2019-07-03 14:26:08 +00:00
|
|
|
t.advance()
|
2018-10-05 22:02:31 +00:00
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *booleanTable) Close() {
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Lock()
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.cur != nil {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
}
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Unlock()
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 20:44:18 +00:00
|
|
|
func (t *booleanTable) Statistics() cursors.CursorStats {
|
2018-11-07 16:31:42 +00:00
|
|
|
t.mu.Lock()
|
2018-12-13 18:05:14 +00:00
|
|
|
defer t.mu.Unlock()
|
2018-11-07 16:31:42 +00:00
|
|
|
cur := t.cur
|
|
|
|
if cur == nil {
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{}
|
2018-11-07 16:31:42 +00:00
|
|
|
}
|
|
|
|
cs := cur.Stats()
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{
|
2018-11-07 16:31:42 +00:00
|
|
|
ScannedValues: cs.ScannedValues,
|
|
|
|
ScannedBytes: cs.ScannedBytes,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
func (t *booleanTable) Do(f func(flux.ColReader) error) error {
|
2019-07-03 14:26:08 +00:00
|
|
|
return t.do(f, t.advance)
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
func (t *booleanTable) advance() bool {
|
2018-10-05 22:02:31 +00:00
|
|
|
a := t.cur.Next()
|
2019-05-30 17:31:54 +00:00
|
|
|
l := a.Len()
|
|
|
|
if l == 0 {
|
2019-07-03 14:26:08 +00:00
|
|
|
return false
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 17:31:54 +00:00
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2019-07-03 14:26:08 +00:00
|
|
|
cr := t.allocateBuffer(l)
|
2019-05-30 17:31:54 +00:00
|
|
|
cr.cols[timeColIdx] = arrow.NewInt(a.Timestamps, t.alloc)
|
|
|
|
cr.cols[valueColIdx] = t.toArrowBuffer(a.Values)
|
|
|
|
t.appendTags(cr)
|
|
|
|
t.appendBounds(cr)
|
2019-07-03 14:26:08 +00:00
|
|
|
return true
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 18:42:38 +00:00
|
|
|
// window table
|
|
|
|
type booleanWindowTable struct {
|
|
|
|
booleanTable
|
|
|
|
windowEvery int64
|
|
|
|
arr *cursors.BooleanArray
|
2020-06-01 22:57:50 +00:00
|
|
|
nextTS int64
|
2020-05-28 18:42:38 +00:00
|
|
|
idxInArr int
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty bool
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newBooleanWindowTable(
|
|
|
|
done chan struct{},
|
|
|
|
cur cursors.BooleanArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
every int64,
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty bool,
|
2020-05-28 18:42:38 +00:00
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
|
|
|
cache *tagsCache,
|
|
|
|
alloc *memory.Allocator,
|
|
|
|
) *booleanWindowTable {
|
|
|
|
t := &booleanWindowTable{
|
|
|
|
booleanTable: booleanTable{
|
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
|
|
|
cur: cur,
|
|
|
|
},
|
|
|
|
windowEvery: every,
|
2020-06-01 22:57:50 +00:00
|
|
|
createEmpty: createEmpty,
|
|
|
|
}
|
|
|
|
if t.createEmpty {
|
|
|
|
start := int64(bounds.Start)
|
|
|
|
t.nextTS = start + (every - start%every)
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
|
|
|
t.readTags(tags)
|
|
|
|
t.advance()
|
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2020-06-01 22:57:50 +00:00
|
|
|
func (t *booleanWindowTable) Do(f func(flux.ColReader) error) error {
|
|
|
|
return t.do(f, t.advance)
|
|
|
|
}
|
|
|
|
|
|
|
|
// createNextWindow will read the timestamps from the array
|
|
|
|
// cursor and construct the values for the next window.
|
|
|
|
func (t *booleanWindowTable) createNextWindow() (start, stop *array.Int64, ok bool) {
|
|
|
|
var stopT int64
|
|
|
|
if t.createEmpty {
|
|
|
|
stopT = t.nextTS
|
|
|
|
t.nextTS += t.windowEvery
|
|
|
|
} else {
|
|
|
|
if !t.nextBuffer() {
|
|
|
|
return nil, nil, false
|
|
|
|
}
|
|
|
|
stopT = t.arr.Timestamps[t.idxInArr]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Regain the window start time from the window end time.
|
|
|
|
startT := stopT - t.windowEvery
|
|
|
|
if startT < int64(t.bounds.Start) {
|
|
|
|
startT = int64(t.bounds.Start)
|
|
|
|
}
|
|
|
|
if stopT > int64(t.bounds.Stop) {
|
|
|
|
stopT = int64(t.bounds.Stop)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the start time is after our stop boundary,
|
|
|
|
// we exit here when create empty is true.
|
|
|
|
if t.createEmpty && startT >= int64(t.bounds.Stop) {
|
|
|
|
return nil, nil, false
|
|
|
|
}
|
|
|
|
start = arrow.NewInt([]int64{startT}, t.alloc)
|
|
|
|
stop = arrow.NewInt([]int64{stopT}, t.alloc)
|
|
|
|
return start, stop, true
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextAt will retrieve the next value that can be used with
|
|
|
|
// the given stop timestamp. If no values can be used with the timestamp,
|
|
|
|
// it will return the default value and false.
|
|
|
|
func (t *booleanWindowTable) nextAt(ts int64) (v bool, ok bool) {
|
|
|
|
if !t.nextBuffer() {
|
|
|
|
return
|
|
|
|
} else if !t.isInWindow(ts, t.arr.Timestamps[t.idxInArr]) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
v, ok = t.arr.Values[t.idxInArr], true
|
|
|
|
t.idxInArr++
|
|
|
|
return v, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// isInWindow will check if the given time at stop can be used within
|
|
|
|
// the window stop time for ts. The ts may be a truncated stop time
|
|
|
|
// because of a restricted boundary while stop will be the true
|
|
|
|
// stop time returned by storage.
|
|
|
|
func (t *booleanWindowTable) isInWindow(ts int64, stop int64) bool {
|
|
|
|
// This method checks if the stop time is a valid stop time for
|
|
|
|
// that interval. This calculation is different from the calculation
|
|
|
|
// of the window itself. For example, for a 10 second window that
|
|
|
|
// starts at 20 seconds, we would include points between [20, 30).
|
|
|
|
// The stop time for this interval would be 30, but because the stop
|
|
|
|
// time can be truncated, valid stop times range from anywhere between
|
|
|
|
// (20, 30]. The storage engine will always produce 30 as the end time
|
|
|
|
// but we may have truncated the stop time because of the boundary
|
|
|
|
// and this is why we are checking for this range instead of checking
|
|
|
|
// if the two values are equal.
|
|
|
|
start := stop - t.windowEvery
|
|
|
|
return start < ts && ts <= stop
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextBuffer will ensure the array cursor is filled
|
|
|
|
// and will return true if there is at least one value
|
|
|
|
// that can be read from it.
|
|
|
|
func (t *booleanWindowTable) nextBuffer() bool {
|
|
|
|
// Discard the current array cursor if we have
|
|
|
|
// exceeded it.
|
|
|
|
if t.arr != nil && t.idxInArr >= t.arr.Len() {
|
|
|
|
t.arr = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the next array cursor if needed.
|
2020-05-28 18:42:38 +00:00
|
|
|
if t.arr == nil {
|
2020-06-01 22:57:50 +00:00
|
|
|
arr := t.cur.Next()
|
|
|
|
if arr.Len() == 0 {
|
2020-05-28 18:42:38 +00:00
|
|
|
return false
|
|
|
|
}
|
2020-06-01 22:57:50 +00:00
|
|
|
t.arr, t.idxInArr = arr, 0
|
2020-05-28 18:42:38 +00:00
|
|
|
}
|
2020-06-01 22:57:50 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// appendValues will scan the timestamps and append values
|
|
|
|
// that match those timestamps from the buffer.
|
|
|
|
func (t *booleanWindowTable) appendValues(intervals []int64, appendValue func(v bool), appendNull func()) {
|
|
|
|
for i := 0; i < len(intervals); i++ {
|
|
|
|
if v, ok := t.nextAt(intervals[i]); ok {
|
|
|
|
appendValue(v)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
appendNull()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *booleanWindowTable) advance() bool {
|
|
|
|
// Create the timestamps for the next window.
|
|
|
|
start, stop, ok := t.createNextWindow()
|
|
|
|
if !ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
values := t.mergeValues(stop.Int64Values())
|
2020-05-28 18:42:38 +00:00
|
|
|
|
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2020-06-01 22:57:50 +00:00
|
|
|
cr := t.allocateBuffer(stop.Len())
|
|
|
|
cr.cols[startColIdx] = start
|
|
|
|
cr.cols[stopColIdx] = stop
|
|
|
|
cr.cols[windowedValueColIdx] = values
|
|
|
|
t.appendTags(cr)
|
2020-05-28 18:42:38 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-10-05 22:02:31 +00:00
|
|
|
// group table
|
|
|
|
|
|
|
|
type booleanGroupTable struct {
|
|
|
|
table
|
2019-05-16 01:40:29 +00:00
|
|
|
mu sync.Mutex
|
2020-03-10 05:00:52 +00:00
|
|
|
gc storage.GroupCursor
|
2019-05-16 01:40:29 +00:00
|
|
|
cur cursors.BooleanArrayCursor
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newBooleanGroupTable(
|
2018-10-31 23:21:54 +00:00
|
|
|
done chan struct{},
|
2020-03-10 05:00:52 +00:00
|
|
|
gc storage.GroupCursor,
|
2018-10-05 22:02:31 +00:00
|
|
|
cur cursors.BooleanArrayCursor,
|
|
|
|
bounds execute.Bounds,
|
|
|
|
key flux.GroupKey,
|
|
|
|
cols []flux.ColMeta,
|
|
|
|
tags models.Tags,
|
|
|
|
defs [][]byte,
|
2019-11-27 14:31:53 +00:00
|
|
|
cache *tagsCache,
|
2019-03-06 21:29:45 +00:00
|
|
|
alloc *memory.Allocator,
|
2018-10-05 22:02:31 +00:00
|
|
|
) *booleanGroupTable {
|
|
|
|
t := &booleanGroupTable{
|
2019-11-27 14:31:53 +00:00
|
|
|
table: newTable(done, bounds, key, cols, defs, cache, alloc),
|
2018-10-05 22:02:31 +00:00
|
|
|
gc: gc,
|
|
|
|
cur: cur,
|
|
|
|
}
|
|
|
|
t.readTags(tags)
|
2019-07-03 14:26:08 +00:00
|
|
|
t.advance()
|
2018-10-05 22:02:31 +00:00
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *booleanGroupTable) Close() {
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Lock()
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.cur != nil {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
}
|
|
|
|
if t.gc != nil {
|
|
|
|
t.gc.Close()
|
|
|
|
t.gc = nil
|
|
|
|
}
|
2018-10-31 23:21:54 +00:00
|
|
|
t.mu.Unlock()
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *booleanGroupTable) Do(f func(flux.ColReader) error) error {
|
2019-07-03 14:26:08 +00:00
|
|
|
return t.do(f, t.advance)
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
func (t *booleanGroupTable) advance() bool {
|
2018-10-05 22:02:31 +00:00
|
|
|
RETRY:
|
|
|
|
a := t.cur.Next()
|
2019-05-30 17:31:54 +00:00
|
|
|
l := a.Len()
|
|
|
|
if l == 0 {
|
2018-10-05 22:02:31 +00:00
|
|
|
if t.advanceCursor() {
|
|
|
|
goto RETRY
|
|
|
|
}
|
|
|
|
|
2019-07-03 14:26:08 +00:00
|
|
|
return false
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 17:31:54 +00:00
|
|
|
// Retrieve the buffer for the data to avoid allocating
|
|
|
|
// additional slices. If the buffer is still being used
|
|
|
|
// because the references were retained, then we will
|
|
|
|
// allocate a new buffer.
|
2019-07-03 14:26:08 +00:00
|
|
|
cr := t.allocateBuffer(l)
|
2019-05-30 17:31:54 +00:00
|
|
|
cr.cols[timeColIdx] = arrow.NewInt(a.Timestamps, t.alloc)
|
|
|
|
cr.cols[valueColIdx] = t.toArrowBuffer(a.Values)
|
|
|
|
t.appendTags(cr)
|
|
|
|
t.appendBounds(cr)
|
2019-07-03 14:26:08 +00:00
|
|
|
return true
|
2018-10-05 22:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *booleanGroupTable) advanceCursor() bool {
|
|
|
|
t.cur.Close()
|
|
|
|
t.cur = nil
|
|
|
|
for t.gc.Next() {
|
|
|
|
cur := t.gc.Cursor()
|
|
|
|
if cur == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-10-08 22:22:59 +00:00
|
|
|
if typedCur, ok := cur.(cursors.BooleanArrayCursor); !ok {
|
2018-10-05 22:02:31 +00:00
|
|
|
// TODO(sgc): error or skip?
|
|
|
|
cur.Close()
|
2020-04-09 21:40:41 +00:00
|
|
|
t.err = &influxdb.Error{
|
|
|
|
Code: influxdb.EInvalid,
|
|
|
|
Err: &GroupCursorError{
|
|
|
|
typ: "boolean",
|
|
|
|
cursor: cur,
|
|
|
|
},
|
|
|
|
}
|
2018-10-05 22:02:31 +00:00
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
t.readTags(t.gc.Tags())
|
2018-10-08 22:22:59 +00:00
|
|
|
t.cur = typedCur
|
2018-10-05 22:02:31 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2018-11-07 16:31:42 +00:00
|
|
|
|
2019-02-25 20:44:18 +00:00
|
|
|
func (t *booleanGroupTable) Statistics() cursors.CursorStats {
|
2018-11-07 16:31:42 +00:00
|
|
|
if t.cur == nil {
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{}
|
2018-11-07 16:31:42 +00:00
|
|
|
}
|
|
|
|
cs := t.cur.Stats()
|
2019-02-25 20:44:18 +00:00
|
|
|
return cursors.CursorStats{
|
2018-11-07 16:31:42 +00:00
|
|
|
ScannedValues: cs.ScannedValues,
|
|
|
|
ScannedBytes: cs.ScannedBytes,
|
|
|
|
}
|
|
|
|
}
|