logical

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package logical implements the executable operations. It also provides Analyzers to parse logical expressions to operations, and wire them to executable tree or execution plan.

Index

Constants

This section is empty.

Variables

View Source
var DummyFilter = new(dummyTagFilter)

DummyFilter matches any predicate.

Functions

func ApplyRules added in v0.3.0

func ApplyRules(plan Plan, rules ...OptimizeRule) error

ApplyRules apply OptimizeRules to a Plan.

func BuildLocalFilter added in v0.2.0

func BuildLocalFilter(criteria *modelv1.Criteria, schema Schema, entityDict map[string]int,
	entity tsdb.Entity, mandatoryIndexRule bool,
) (index.Filter, []tsdb.Entity, error)

BuildLocalFilter returns a new index.Filter for local indices. It could parse series Path at the same time.

func ExecuteForShard added in v0.2.0

func ExecuteForShard(ctx context.Context, l *logger.Logger, series tsdb.SeriesList, timeRange timestamp.TimeRange,
	builders ...SeekerBuilder,
) ([]tsdb.Iterator, []io.Closer, error)

ExecuteForShard fetches elements from series within a single shard. A list of series must be prepared in advanced with the help of Entity. The result is a list of element set, where the order of inner list is kept as what the users specify in the seekerBuilder. This method is used by the underlying tableScan and localIndexScan plans.

func FormatTagRefs added in v0.2.0

func FormatTagRefs(sep string, exprGroup ...[]*TagRef) string

FormatTagRefs outputs formatted tag refs.

func NewItemIter

func NewItemIter(iters []tsdb.Iterator, s modelv1.Sort) sort.Iterator[tsdb.Item]

NewItemIter returns a ItemIterator which mergers several tsdb.Iterator by input sorting order.

func ProjectItem added in v0.2.0

func ProjectItem(ec executor.ExecutionContext, item tsdb.Item, projectionFieldRefs [][]*TagRef) ([]*modelv1.TagFamily, error)

ProjectItem parses the item within the StreamExecutionContext. projectionFieldRefs must be prepared before calling this method, projectionFieldRefs should be a list of tag list where the inner list must exist in the same tag family. Strict order can be guaranteed in the result.

func StringSlicesEqual added in v0.2.0

func StringSlicesEqual(a, b []string) bool

StringSlicesEqual reports whether a and b are the same length and contain the same strings. A nil argument is equivalent to an empty slice.

func ToTags added in v0.3.0

func ToTags(projection *modelv1.TagProjection) [][]*Tag

ToTags converts a projection spec to Tag sets.

Types

type CommonSchema added in v0.2.0

type CommonSchema struct {
	TagSpecMap
	IndexRules []*databasev1.IndexRule
	EntityList []string
}

CommonSchema represents a sharable fields between independent schemas. It provides common access methods at the same time.

func (*CommonSchema) CreateRef added in v0.2.0

func (cs *CommonSchema) CreateRef(tags ...[]*Tag) ([][]*TagRef, error)

CreateRef create TagRef to the given tags. The family name of the tag is actually not used since the uniqueness of the tag names can be guaranteed across families.

func (*CommonSchema) IndexDefined added in v0.2.0

func (cs *CommonSchema) IndexDefined(tagName string) (bool, *databasev1.IndexRule)

IndexDefined checks whether the field given is indexed.

func (*CommonSchema) IndexRuleDefined added in v0.2.0

func (cs *CommonSchema) IndexRuleDefined(indexRuleName string) (bool, *databasev1.IndexRule)

IndexRuleDefined return the IndexRule by its name.

func (*CommonSchema) ProjTags added in v0.2.0

func (cs *CommonSchema) ProjTags(refs ...[]*TagRef) *CommonSchema

ProjTags inits a dictionary for getting TagSpec by tag's name.

type ComparableExpr

type ComparableExpr interface {
	LiteralExpr
	Compare(LiteralExpr) (int, bool)
	BelongTo(LiteralExpr) bool
	Contains(LiteralExpr) bool
}

ComparableExpr allows comparing Expr and Expr arrays.

type Expr

type Expr interface {
	fmt.Stringer
	DataType() int32
	Equal(Expr) bool
}

Expr represents a predicate in criteria.

type Field

type Field struct {
	Name string
}

Field identity a field in a measure.

func NewField

func NewField(name string) *Field

NewField return a new Field.

type FieldRef

type FieldRef struct {
	// Field defines the name of the Field
	Field *Field
	// spec contains the index of the key in the measureSchema, as well as the underlying FieldSpec
	Spec *FieldSpec
}

FieldRef is the reference to the field also it holds the definition (derived from measureSchema) of the field.

func (*FieldRef) DataType

func (f *FieldRef) DataType() int32

DataType shows the type of the filed's value.

func (*FieldRef) Equal

func (f *FieldRef) Equal(expr Expr) bool

Equal reports whether f and expr have the same name and data type.

func (*FieldRef) String

func (f *FieldRef) String() string

String shows the string representation.

type FieldSpec added in v0.2.0

type FieldSpec struct {
	Spec     *databasev1.FieldSpec
	FieldIdx int
}

FieldSpec is the reference to the field. It also holds the definition of the field.

type GlobalIndexError added in v0.2.0

type GlobalIndexError struct {
	IndexRule *databasev1.IndexRule
	Expr      LiteralExpr
}

GlobalIndexError represents a index rule is "global". The local filter can't handle it.

func (GlobalIndexError) Error added in v0.2.0

func (g GlobalIndexError) Error() string

type IndexChecker added in v0.3.0

type IndexChecker interface {
	IndexDefined(tagName string) (bool, *databasev1.IndexRule)
	IndexRuleDefined(ruleName string) (bool, *databasev1.IndexRule)
}

IndexChecker allows checking the existence of a specific index rule.

type LiteralExpr

type LiteralExpr interface {
	Expr
	Bytes() [][]byte
}

LiteralExpr allows getting raw data represented as bytes.

type OptimizeRule added in v0.3.0

type OptimizeRule interface {
	Optimize(Plan) (Plan, error)
}

OptimizeRule allows optimizing a Plan based on a rule.

type OrderBy

type OrderBy struct {
	Index *databasev1.IndexRule

	Sort modelv1.Sort
	// contains filtered or unexported fields
}

OrderBy is the sorting operator.

func ParseOrderBy added in v0.3.0

func ParseOrderBy(s Schema, indexRuleName string, sort modelv1.Sort) (*OrderBy, error)

ParseOrderBy parses an OrderBy from a Schema.

func (*OrderBy) Equal added in v0.2.0

func (o *OrderBy) Equal(other interface{}) bool

Equal reports whether o and other has the same sorting order and name.

func (*OrderBy) String added in v0.2.0

func (o *OrderBy) String() string

Strings shows the string represent.

type Parent added in v0.2.0

type Parent struct {
	UnresolvedInput UnresolvedPlan
	Input           Plan
}

Parent refers to a parent node in the execution tree(plan).

type Plan

type Plan interface {
	fmt.Stringer
	Children() []Plan
	Schema() Schema
}

Plan is the executable operation. It belongs to a execution tree.

type PushDownMaxSize added in v0.3.0

type PushDownMaxSize struct {
	// contains filtered or unexported fields
}

PushDownMaxSize pushes down the max volume to a Plan.

func NewPushDownMaxSize added in v0.3.0

func NewPushDownMaxSize(max int) PushDownMaxSize

NewPushDownMaxSize returns a new PushDownMaxSize.

func (PushDownMaxSize) Optimize added in v0.3.0

func (pde PushDownMaxSize) Optimize(plan Plan) (Plan, error)

Optimize a Plan by pushing down the max volume.

type PushDownOrder added in v0.3.0

type PushDownOrder struct {
	// contains filtered or unexported fields
}

PushDownOrder pushes down the order to a Plan.

func NewPushDownOrder added in v0.3.0

func NewPushDownOrder(order *modelv1.QueryOrder) PushDownOrder

NewPushDownOrder returns a new PushDownOrder.

func (PushDownOrder) Optimize added in v0.3.0

func (pdo PushDownOrder) Optimize(plan Plan) (Plan, error)

Optimize a Plan by pushing down the query order.

type Schema

type Schema interface {
	TagSpecRegistry
	IndexChecker
	Scope() tsdb.Entry
	EntityList() []string
	CreateTagRef(tags ...[]*Tag) ([][]*TagRef, error)
	CreateFieldRef(fields ...*Field) ([]*FieldRef, error)
	ProjTags(refs ...[]*TagRef) Schema
	ProjFields(refs ...*FieldRef) Schema
	Equal(Schema) bool
}

Schema allows retrieving schemas in a convenient way.

type SeekerBuilder added in v0.2.0

type SeekerBuilder func(builder tsdb.SeekerBuilder)

SeekerBuilder wraps the execution of tsdb.SeekerBuilder. TODO:// we could have a chance to remove this wrapper.

type Sorter added in v0.3.0

type Sorter interface {
	Plan
	Sort(order *OrderBy)
}

Sorter sorts a Plan's output.

type Tag

type Tag struct {
	// contains filtered or unexported fields
}

Tag represents the combination of tag family and tag name. It's a tag's identity.

func NewTag

func NewTag(family, name string) *Tag

NewTag return a new Tag.

func NewTags

func NewTags(family string, tagNames ...string) []*Tag

NewTags create an array of Tag within a TagFamily.

func (*Tag) GetCompoundName

func (t *Tag) GetCompoundName() string

GetCompoundName is only used for error message.

type TagFamilies added in v0.3.0

type TagFamilies []*modelv1.TagFamily

TagFamilies wraps a slice of TagFamily.

func (TagFamilies) GetTagValue added in v0.3.0

func (tfs TagFamilies) GetTagValue(tagFamilyIdx, tagIdx int) *modelv1.TagValue

GetTagValue gets TagValue from the underlying TagFamily slice.

type TagFamiliesForWrite added in v0.3.0

type TagFamiliesForWrite []*modelv1.TagFamilyForWrite

TagFamiliesForWrite wraps a slice of TagFamilyForWrite.

func (TagFamiliesForWrite) GetTagValue added in v0.3.0

func (tffws TagFamiliesForWrite) GetTagValue(tagFamilyIdx, tagIdx int) *modelv1.TagValue

GetTagValue gets TagValue from the underlying TagFamilyForWrite slice.

type TagFilter

type TagFilter interface {
	fmt.Stringer
	Match(accessor TagValueIndexAccessor, registry TagSpecRegistry) (bool, error)
}

TagFilter allows matching a tag based on a predicate.

func BuildSimpleTagFilter added in v0.3.0

func BuildSimpleTagFilter(criteria *modelv1.Criteria) (TagFilter, error)

BuildSimpleTagFilter returns a TagFilter without any local-index, global index, sharding key support.

func BuildTagFilter added in v0.2.0

func BuildTagFilter(criteria *modelv1.Criteria, entityDict map[string]int, indexChecker IndexChecker, hasGlobalIndex bool) (TagFilter, error)

BuildTagFilter returns a TagFilter if predicates doesn't match any indices.

type TagRef

type TagRef struct {
	// Tag defines the family name and name of the Tag
	Tag *Tag
	// spec contains the index of the key in the streamSchema/measureSchema, as well as the underlying tagSpec
	Spec *TagSpec
}

TagRef is the reference to the tag also it holds the definition (derived from the streamSchema, measureSchema) of the tag.

func NewSearchableTagRef

func NewSearchableTagRef(tagName string) *TagRef

NewSearchableTagRef is a short-handed method for creating a TagRef to the tag in the searchable family.

func NewTagRef

func NewTagRef(familyName, tagName string) *TagRef

NewTagRef returns a new TagRef.

func (*TagRef) DataType

func (f *TagRef) DataType() int32

DataType shows the type of the tag's value.

func (*TagRef) Equal

func (f *TagRef) Equal(expr Expr) bool

Equal reports whether f and expr have the same name and data type.

func (*TagRef) String

func (f *TagRef) String() string

String shows the string representation.

type TagSpec added in v0.2.0

type TagSpec struct {
	Spec         *databasev1.TagSpec
	TagFamilyIdx int
	TagIdx       int
}

TagSpec wraps offsets to access a tag in the raw data swiftly.

func (*TagSpec) Equal added in v0.2.0

func (fs *TagSpec) Equal(other *TagSpec) bool

Equal compares fs and other have the same fields.

type TagSpecMap added in v0.3.0

type TagSpecMap map[string]*TagSpec

TagSpecMap is a map of TapSpec implements TagSpecRegistry.

func (TagSpecMap) FindTagSpecByName added in v0.3.0

func (tagSpecMap TagSpecMap) FindTagSpecByName(name string) *TagSpec

FindTagSpecByName finds TagSpec by its name in the registry.

func (TagSpecMap) RegisterTag added in v0.3.0

func (tagSpecMap TagSpecMap) RegisterTag(tagFamilyIdx, tagIdx int, spec *databasev1.TagSpec)

RegisterTag registers the tag spec with given tagFamilyName, tagName and indexes.

func (TagSpecMap) RegisterTagFamilies added in v0.3.0

func (tagSpecMap TagSpecMap) RegisterTagFamilies(tagFamilies []*databasev1.TagFamilySpec)

RegisterTagFamilies registers the tag specs with a given slice of TagFamilySpec.

type TagSpecRegistry added in v0.3.0

type TagSpecRegistry interface {
	FindTagSpecByName(string) *TagSpec
}

TagSpecRegistry enables to find TagSpec by its name.

type TagValueIndexAccessor added in v0.3.0

type TagValueIndexAccessor interface {
	GetTagValue(tagFamilyIdx, tagIdx int) *modelv1.TagValue
}

TagValueIndexAccessor provides accessor to get TagValue by two indexes, i.e. tagFamilyIndex and tagIndex. It works like a matrix.

type UnresolvedPlan

type UnresolvedPlan interface {
	Analyze(Schema) (Plan, error)
}

UnresolvedPlan denotes an logical expression. It could be analyzed to a Plan(executable operation) with the Schema.

type VolumeLimiter added in v0.3.0

type VolumeLimiter interface {
	Plan
	Limit(max int)
}

VolumeLimiter controls the volume of a Plan's output.

Directories

Path Synopsis
Package measure implements execution operations for querying measure data.
Package measure implements execution operations for querying measure data.
Package stream implements execution operations for querying stream data.
Package stream implements execution operations for querying stream data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL