shape

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaterializeThreshold = 100 // TODO: tune

Functions

func BuildIterator

func BuildIterator(ctx context.Context, qs graph.QuadStore, s Shape) iterator.Shape

BuildIterator optimizes the shape and builds a corresponding iterator tree.

func IsNull

func IsNull(s Shape) bool

IsNull safely checks if shape represents an empty set. It accounts for both Null and nil.

func Iterate

func Iterate(ctx context.Context, qs graph.QuadStore, s Shape) *iterator.Chain

func One

func One(s Shape) (refs.Ref, bool)

One checks if Shape represents a single fixed value and returns it.

func Walk

func Walk(s Shape, fnc WalkFunc)

Walk calls provided function for each shape in the tree.

Types

type AllNodes

type AllNodes struct{}

AllNodes represents all nodes in QuadStore.

func (AllNodes) BuildIterator

func (s AllNodes) BuildIterator(qs graph.QuadStore) iterator.Shape

func (AllNodes) Optimize

func (s AllNodes) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type Comparison

type Comparison struct {
	Op  iterator.Operator
	Val quad.Value
}

Comparison is a value filter that evaluates binary operation in reference to a fixed value.

func (Comparison) BuildIterator

func (f Comparison) BuildIterator(qs graph.QuadStore, it iterator.Shape) iterator.Shape

type Composite

type Composite interface {
	Simplify() Shape
}

Composite shape can be simplified to a tree of more basic shapes.

type Count

type Count struct {
	Values Shape
}

Count returns a count of objects in source as a single value. It always returns exactly one value.

func (Count) BuildIterator

func (s Count) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Count) Optimize

func (s Count) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type Except

type Except struct {
	Exclude Shape // nodes to exclude
	From    Shape // a set of all nodes to exclude from; nil means AllNodes
}

Except excludes a set on nodes from a source. If source is nil, AllNodes is assumed.

func (Except) BuildIterator

func (s Except) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Except) Optimize

func (s Except) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type Filter

type Filter struct {
	From    Shape         // source that will be filtered
	Filters []ValueFilter // filters to apply
}

Filter filters all values from the source using a list of operations.

func (Filter) BuildIterator

func (s Filter) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Filter) Optimize

func (s Filter) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type Fixed

type Fixed []refs.Ref

Fixed is a static set of nodes. Defined only for a particular QuadStore.

func (*Fixed) Add

func (s *Fixed) Add(v ...refs.Ref)

func (Fixed) BuildIterator

func (s Fixed) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Fixed) Optimize

func (s Fixed) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type FixedTags

type FixedTags struct {
	Tags map[string]refs.Ref
	On   Shape
}

FixedTags adds a set of fixed tag values to query results. It does not affect query execution in any other way.

Shape implementations should try to push these objects up the tree during optimization process.

func (FixedTags) BuildIterator

func (s FixedTags) BuildIterator(qs graph.QuadStore) iterator.Shape

func (FixedTags) Optimize

func (s FixedTags) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type InternalQuad

type InternalQuad struct {
	Subject   refs.Ref
	Predicate refs.Ref
	Object    refs.Ref
	Label     refs.Ref
}

InternalQuad is an internal representation of quad index in QuadStore.

func (InternalQuad) Get

func (q InternalQuad) Get(d quad.Direction) refs.Ref

Get returns a specified direction of the quad.

func (InternalQuad) Set

func (q InternalQuad) Set(d quad.Direction, v refs.Ref)

Set assigns a specified direction of the quad to a given value.

type Intersect

type Intersect []Shape

Intersect computes an intersection of nodes between multiple queries. Similar to And iterator.

func (Intersect) BuildIterator

func (s Intersect) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Intersect) Optimize

func (s Intersect) Optimize(ctx context.Context, r Optimizer) (sout Shape, opt bool)

type IntersectOpt

type IntersectOpt struct {
	Sub Intersect
	Opt []Shape
}

IntersectOpt is like Intersect but it also joins optional query shapes to the main query.

func (*IntersectOpt) Add

func (s *IntersectOpt) Add(arr ...Shape)

func (*IntersectOpt) AddOptional

func (s *IntersectOpt) AddOptional(arr ...Shape)

func (IntersectOpt) BuildIterator

func (s IntersectOpt) BuildIterator(qs graph.QuadStore) iterator.Shape

func (IntersectOpt) Optimize

func (s IntersectOpt) Optimize(ctx context.Context, r Optimizer) (_ Shape, opt bool)

type Lookup

type Lookup []quad.Value

Lookup is a static set of values that must be resolved to nodes by QuadStore.

func (*Lookup) Add

func (s *Lookup) Add(v ...quad.Value)

func (Lookup) BuildIterator

func (s Lookup) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Lookup) Optimize

func (s Lookup) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type Materialize

type Materialize struct {
	Size   int // approximate size; zero means undefined
	Values Shape
}

Materialize loads results of sub-query into memory during execution to speedup iteration.

func (Materialize) BuildIterator

func (s Materialize) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Materialize) Optimize

func (s Materialize) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type NodesFrom

type NodesFrom struct {
	Dir   quad.Direction
	Quads Shape
}

NodesFrom extracts nodes on a given direction from source quads. Similar to HasA iterator.

func (NodesFrom) BuildIterator

func (s NodesFrom) BuildIterator(qs graph.QuadStore) iterator.Shape

func (NodesFrom) Optimize

func (s NodesFrom) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type Null

type Null struct{}

Null represent an empty set. Mostly used as a safe alias for nil shape.

func (Null) BuildIterator

func (Null) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Null) Optimize

func (s Null) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type Optimizer

type Optimizer interface {
	OptimizeShape(ctx context.Context, s Shape) (Shape, bool)
}

type Page

type Page struct {
	From  Shape
	Skip  int64
	Limit int64 // zero means unlimited
}

Page provides a simple form of pagination. Can be used to skip or limit results.

func (Page) ApplyPage

func (s Page) ApplyPage(p Page) *Page

func (Page) BuildIterator

func (s Page) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Page) Optimize

func (s Page) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type QuadFilter

type QuadFilter struct {
	Dir    quad.Direction
	Values Shape
}

QuadFilter is a constraint used to filter quads that have a certain set of values on a given direction. Analog of LinksTo iterator.

type QuadIndexer

type QuadIndexer interface {
	// SizeOfIndex returns a size of a quad index with given constraints.
	SizeOfIndex(c map[quad.Direction]refs.Ref) (int64, bool)
	// LookupQuadIndex finds a quad that matches a given constraint.
	// It returns false if quad was not found, or there are multiple quads matching constraint.
	LookupQuadIndex(c map[quad.Direction]refs.Ref) (InternalQuad, bool)
}

QuadIndexer is an optional interface for quad stores that keep an index of quad directions.

It is used to optimize shapes based on stats from these indexes.

type Quads

type Quads []QuadFilter

Quads is a selector of quads with a given set of node constraints. Empty or nil Quads is equivalent to AllQuads. Equivalent to And(AllQuads,LinksTo*) iterator tree.

func (Quads) BuildIterator

func (s Quads) BuildIterator(qs graph.QuadStore) iterator.Shape

func (*Quads) Intersect

func (s *Quads) Intersect(q ...QuadFilter)

func (Quads) Optimize

func (s Quads) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type QuadsAction

type QuadsAction struct {
	Size   int64 // approximate size; zero means undefined
	Result quad.Direction
	Save   map[quad.Direction][]string
	Filter map[quad.Direction]refs.Ref
}

QuadsAction represents a set of actions that can be done to a set of quads in a single scan pass. It filters quads according to Filter constraints (equivalent of LinksTo), tags directions using tags in Save field and returns a specified quad direction as result of the iterator (equivalent of HasA). Optionally, Size field may be set to indicate an approximate number of quads that will be returned by this query.

func (QuadsAction) BuildIterator

func (s QuadsAction) BuildIterator(qs graph.QuadStore) iterator.Shape

func (QuadsAction) Clone

func (s QuadsAction) Clone() QuadsAction

func (QuadsAction) Optimize

func (s QuadsAction) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

func (*QuadsAction) SetFilter

func (s *QuadsAction) SetFilter(d quad.Direction, v refs.Ref)

func (QuadsAction) Simplify

func (s QuadsAction) Simplify() Shape

func (QuadsAction) SimplifyFrom

func (s QuadsAction) SimplifyFrom(quads Shape) Shape

type Regexp

type Regexp struct {
	Re   *regexp.Regexp
	Refs bool // allow to match IRIs
}

Regexp filters values using regular expression.

Since regexp patterns can not be optimized in most cases, Wildcard should be used if possible.

func (Regexp) BuildIterator

func (f Regexp) BuildIterator(qs graph.QuadStore, it iterator.Shape) iterator.Shape

type Save

type Save struct {
	Tags []string
	From Shape
}

Save tags a results of query with provided tags.

func (Save) BuildIterator

func (s Save) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Save) Optimize

func (s Save) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type Shape

type Shape interface {
	// BuildIterator constructs an iterator tree from a given shapes and binds it to QuadStore.
	BuildIterator(qs graph.QuadStore) iterator.Shape
	// Optimize runs an optimization pass over a query shape.
	//
	// It returns a bool that indicates if shape was replaced and should always return a copy of shape in this case.
	// In case no optimizations were made, it returns the same unmodified shape.
	//
	// If Optimizer is specified, it will be used instead of default optimizations.
	Optimize(ctx context.Context, r Optimizer) (Shape, bool)
}

Shape represent a query tree shape.

func AddFilters

func AddFilters(nodes Shape, filters ...ValueFilter) Shape

func Compare

func Compare(nodes Shape, op iterator.Operator, v quad.Value) Shape

func FilterQuads

func FilterQuads(subject, predicate, object, label []quad.Value) Shape

func Has

func Has(from, via, nodes Shape, rev bool) Shape

func HasLabels

func HasLabels(from, via, nodes, labels Shape, rev bool) Shape

func In

func In(from, via, labels Shape, tags ...string) Shape

func IntersectOptional

func IntersectOptional(s, opt Shape) Shape

func IntersectShapes

func IntersectShapes(s1, s2 Shape) Shape

func Labels

func Labels(from Shape) Shape

func Optimize

func Optimize(ctx context.Context, s Shape, qs graph.QuadStore) (Shape, bool)

Optimize applies generic optimizations for the tree. If quad store is specified it will also resolve Lookups and apply any specific optimizations. Should not be used with Simplify - it will fold query to a compact form again.

func Out

func Out(from, via, labels Shape, tags ...string) Shape

func Predicates

func Predicates(from Shape, in bool) Shape

func SavePredicates

func SavePredicates(from Shape, in bool, tag string) Shape

func SaveVia

func SaveVia(from, via Shape, tag string, rev, opt bool) Shape

func SaveViaLabels

func SaveViaLabels(from, via, labels Shape, tag string, rev, opt bool) Shape

type Sort

type Sort struct {
	From Shape
}

func (Sort) BuildIterator

func (s Sort) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Sort) Optimize

func (s Sort) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type Union

type Union []Shape

Union joins results of multiple queries together. It does not make results unique.

func UnionShapes

func UnionShapes(s1, s2 Shape) Union

func (Union) BuildIterator

func (s Union) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Union) Optimize

func (s Union) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type Unique

type Unique struct {
	From Shape
}

Unique makes query results unique.

func (Unique) BuildIterator

func (s Unique) BuildIterator(qs graph.QuadStore) iterator.Shape

func (Unique) Optimize

func (s Unique) Optimize(ctx context.Context, r Optimizer) (Shape, bool)

type ValueFilter

type ValueFilter interface {
	BuildIterator(qs graph.QuadStore, it iterator.Shape) iterator.Shape
}

ValueFilter is an interface for iterator wrappers that can filter node values.

type WalkFunc

type WalkFunc func(Shape) bool

WalkFunc is used to visit all shapes in the tree. If false is returned, branch will not be traversed further.

type Wildcard

type Wildcard struct {
	Pattern string // allowed wildcards are: % and ?
}

Wildcard is a filter for string patterns.

% - zero or more characters
? - exactly one character

func (Wildcard) BuildIterator

func (f Wildcard) BuildIterator(qs graph.QuadStore, it iterator.Shape) iterator.Shape

func (Wildcard) Regexp

func (f Wildcard) Regexp() string

Regexp returns an analog regexp pattern in format accepted by Go stdlib (RE2).

Jump to

Keyboard shortcuts

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