2020-03-07 01:59:16 +00:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/influxdata/flux"
|
|
|
|
"github.com/influxdata/flux/execute"
|
|
|
|
"github.com/influxdata/flux/memory"
|
2020-04-06 17:17:47 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
2020-04-07 15:45:08 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/storage/reads/datatypes"
|
2020-04-06 17:17:47 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/tsdb/cursors"
|
2020-03-07 01:59:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// StorageReader is an interface for reading tables from the storage subsystem.
|
|
|
|
type StorageReader interface {
|
|
|
|
ReadFilter(ctx context.Context, spec ReadFilterSpec, alloc *memory.Allocator) (TableIterator, error)
|
|
|
|
ReadGroup(ctx context.Context, spec ReadGroupSpec, alloc *memory.Allocator) (TableIterator, error)
|
|
|
|
|
|
|
|
ReadTagKeys(ctx context.Context, spec ReadTagKeysSpec, alloc *memory.Allocator) (TableIterator, error)
|
|
|
|
ReadTagValues(ctx context.Context, spec ReadTagValuesSpec, alloc *memory.Allocator) (TableIterator, error)
|
|
|
|
|
|
|
|
Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReadFilterSpec struct {
|
|
|
|
OrganizationID influxdb.ID
|
|
|
|
BucketID influxdb.ID
|
|
|
|
|
2020-04-07 15:45:08 +00:00
|
|
|
Bounds execute.Bounds
|
|
|
|
Predicate *datatypes.Predicate
|
2020-03-07 01:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ReadGroupSpec struct {
|
|
|
|
ReadFilterSpec
|
|
|
|
|
|
|
|
GroupMode GroupMode
|
|
|
|
GroupKeys []string
|
|
|
|
|
|
|
|
AggregateMethod string
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReadTagKeysSpec struct {
|
|
|
|
ReadFilterSpec
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReadTagValuesSpec struct {
|
|
|
|
ReadFilterSpec
|
|
|
|
TagKey string
|
|
|
|
}
|
|
|
|
|
|
|
|
// TableIterator is a table iterator that also keeps track of cursor statistics from the storage engine.
|
|
|
|
type TableIterator interface {
|
|
|
|
flux.TableIterator
|
|
|
|
Statistics() cursors.CursorStats
|
|
|
|
}
|
|
|
|
|
|
|
|
type GroupMode int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// GroupModeNone merges all series into a single group.
|
|
|
|
GroupModeNone GroupMode = iota
|
|
|
|
// GroupModeBy produces a table for each unique value of the specified GroupKeys.
|
|
|
|
GroupModeBy
|
|
|
|
)
|
|
|
|
|
|
|
|
// ToGroupMode accepts the group mode from Flux and produces the appropriate storage group mode.
|
|
|
|
func ToGroupMode(fluxMode flux.GroupMode) GroupMode {
|
|
|
|
switch fluxMode {
|
|
|
|
case flux.GroupModeNone:
|
|
|
|
return GroupModeNone
|
|
|
|
case flux.GroupModeBy:
|
|
|
|
return GroupModeBy
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprint("unknown group mode: ", fluxMode))
|
|
|
|
}
|
|
|
|
}
|