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-22 21:54:09 +00:00
|
|
|
"github.com/influxdata/flux/plan"
|
2021-09-13 19:12:35 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform"
|
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 {
|
2022-03-22 17:33:52 +00:00
|
|
|
ReadFilter(ctx context.Context, spec ReadFilterSpec, alloc memory.Allocator) (TableIterator, error)
|
|
|
|
ReadGroup(ctx context.Context, spec ReadGroupSpec, alloc memory.Allocator) (TableIterator, error)
|
|
|
|
ReadWindowAggregate(ctx context.Context, spec ReadWindowAggregateSpec, alloc memory.Allocator) (TableIterator, error)
|
2020-03-07 01:59:16 +00:00
|
|
|
|
2022-03-22 17:33:52 +00:00
|
|
|
ReadTagKeys(ctx context.Context, spec ReadTagKeysSpec, alloc memory.Allocator) (TableIterator, error)
|
|
|
|
ReadTagValues(ctx context.Context, spec ReadTagValuesSpec, alloc memory.Allocator) (TableIterator, error)
|
2020-03-07 01:59:16 +00:00
|
|
|
|
2022-03-22 17:33:52 +00:00
|
|
|
ReadSeriesCardinality(ctx context.Context, spec ReadSeriesCardinalitySpec, alloc memory.Allocator) (TableIterator, error)
|
2021-09-09 18:37:11 +00:00
|
|
|
SupportReadSeriesCardinality(ctx context.Context) bool
|
|
|
|
|
2020-03-07 01:59:16 +00:00
|
|
|
Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReadFilterSpec struct {
|
2021-03-30 18:10:02 +00:00
|
|
|
OrganizationID platform.ID
|
|
|
|
BucketID platform.ID
|
2020-03-07 01:59:16 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-06-04 21:36:15 +00:00
|
|
|
func (spec *ReadGroupSpec) Name() string {
|
|
|
|
return fmt.Sprintf("readGroup(%s)", spec.AggregateMethod)
|
|
|
|
}
|
|
|
|
|
2020-03-07 01:59:16 +00:00
|
|
|
type ReadTagKeysSpec struct {
|
|
|
|
ReadFilterSpec
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReadTagValuesSpec struct {
|
|
|
|
ReadFilterSpec
|
|
|
|
TagKey string
|
|
|
|
}
|
|
|
|
|
2021-09-09 18:37:11 +00:00
|
|
|
type ReadSeriesCardinalitySpec struct {
|
|
|
|
ReadFilterSpec
|
|
|
|
}
|
|
|
|
|
2021-05-20 01:22:56 +00:00
|
|
|
// ReadWindowAggregateSpec defines the options for WindowAggregate.
|
|
|
|
//
|
2020-11-17 11:22:12 +00:00
|
|
|
// Window and the WindowEvery/Offset should be mutually exclusive. If you set either the WindowEvery or Offset with
|
2021-05-20 01:22:56 +00:00
|
|
|
// nanosecond values, then the Window will be ignored.
|
2020-04-22 21:54:09 +00:00
|
|
|
type ReadWindowAggregateSpec struct {
|
|
|
|
ReadFilterSpec
|
|
|
|
WindowEvery int64
|
2020-07-14 16:44:05 +00:00
|
|
|
Offset int64
|
2020-04-22 21:54:09 +00:00
|
|
|
Aggregates []plan.ProcedureKind
|
2020-06-01 22:57:50 +00:00
|
|
|
CreateEmpty bool
|
2020-06-10 18:21:41 +00:00
|
|
|
TimeColumn string
|
2020-10-22 21:34:22 +00:00
|
|
|
Window execute.Window
|
2021-05-20 01:22:56 +00:00
|
|
|
|
|
|
|
// ForceAggregate forces all aggregates to be treated as aggregates.
|
|
|
|
// This forces selectors, which normally don't return values for empty
|
|
|
|
// windows, to return a null value.
|
|
|
|
ForceAggregate bool
|
2020-04-22 21:54:09 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 19:21:37 +00:00
|
|
|
func (spec *ReadWindowAggregateSpec) Name() string {
|
|
|
|
var agg string
|
|
|
|
if len(spec.Aggregates) > 0 {
|
|
|
|
agg = string(spec.Aggregates[0])
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("readWindow(%s)", agg)
|
|
|
|
}
|
|
|
|
|
2020-03-07 01:59:16 +00:00
|
|
|
// 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))
|
|
|
|
}
|
|
|
|
}
|