shape

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaterializeThreshold = 100 // TODO: tune

Functions

func BuildIterator

func BuildIterator(qs graph.QuadStore, s Shape) graph.Iterator

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) *graph.IterateChain

func One

func One(s Shape) (graph.Value, 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) graph.Iterator

func (AllNodes) Optimize

func (s AllNodes) Optimize(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 graph.Iterator) graph.Iterator

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) graph.Iterator

func (Count) Optimize

func (s Count) Optimize(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) graph.Iterator

func (Except) Optimize

func (s Except) Optimize(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) graph.Iterator

func (Filter) Optimize

func (s Filter) Optimize(r Optimizer) (Shape, bool)

type Fixed

type Fixed []graph.Value

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

func (*Fixed) Add

func (s *Fixed) Add(v ...graph.Value)

func (Fixed) BuildIterator

func (s Fixed) BuildIterator(qs graph.QuadStore) graph.Iterator

func (Fixed) Optimize

func (s Fixed) Optimize(r Optimizer) (Shape, bool)

type FixedTags

type FixedTags struct {
	Tags map[string]graph.Value
	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) graph.Iterator

func (FixedTags) Optimize

func (s FixedTags) Optimize(r Optimizer) (Shape, bool)

type InternalQuad

type InternalQuad struct {
	Subject   graph.Value
	Predicate graph.Value
	Object    graph.Value
	Label     graph.Value
}

InternalQuad is an internal representation of quad index in QuadStore.

func (InternalQuad) Get

Get returns a specified direction of the quad.

func (InternalQuad) Set

func (q InternalQuad) Set(d quad.Direction, v graph.Value)

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) graph.Iterator

func (Intersect) Optimize

func (s Intersect) Optimize(r Optimizer) (sout 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) graph.Iterator

func (Lookup) Optimize

func (s Lookup) Optimize(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) graph.Iterator

func (Materialize) Optimize

func (s Materialize) Optimize(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) graph.Iterator

func (NodesFrom) Optimize

func (s NodesFrom) Optimize(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) graph.Iterator

func (Null) Optimize

func (s Null) Optimize(r Optimizer) (Shape, bool)

type Optimizer

type Optimizer interface {
	OptimizeShape(s Shape) (Shape, bool)
}

type Optional

type Optional struct {
	From Shape
}

Optional makes a query execution optional. The query can only produce tagged results, since it's value is not used to compute intersection.

func (Optional) BuildIterator

func (s Optional) BuildIterator(qs graph.QuadStore) graph.Iterator

func (Optional) Optimize

func (s Optional) Optimize(r Optimizer) (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) graph.Iterator

func (Page) Optimize

func (s Page) Optimize(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]graph.Value) (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]graph.Value) (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) graph.Iterator

func (*Quads) Intersect

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

func (Quads) Optimize

func (s Quads) Optimize(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]graph.Value
}

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) graph.Iterator

func (QuadsAction) Clone

func (s QuadsAction) Clone() QuadsAction

func (QuadsAction) Optimize

func (s QuadsAction) Optimize(r Optimizer) (Shape, bool)

func (*QuadsAction) SetFilter

func (s *QuadsAction) SetFilter(d quad.Direction, v graph.Value)

func (QuadsAction) Simplify

func (s QuadsAction) Simplify() 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 graph.Iterator) graph.Iterator

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) graph.Iterator

func (Save) Optimize

func (s Save) Optimize(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) graph.Iterator
	// 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(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 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 IntersectShapes

func IntersectShapes(s1, s2 Shape) Shape

func Labels

func Labels(from Shape) Shape

func Optimize

func Optimize(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 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) graph.Iterator

func (Union) Optimize

func (s Union) Optimize(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) graph.Iterator

func (Unique) Optimize

func (s Unique) Optimize(r Optimizer) (Shape, bool)

type ValueFilter

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

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 added in v0.7.1

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 added in v0.7.1

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

func (Wildcard) Regexp added in v0.7.1

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