Documentation ¶
Index ¶
- Constants
- Variables
- func Height(it Shape, filter func(Shape) bool) int
- func IsNull(it Shape) bool
- func RunFloatOp(a quad.Float, op Operator, b quad.Float) bool
- func RunIntOp(a quad.Int, op Operator, b quad.Int) bool
- func RunStrOp(a string, op Operator, b string) bool
- func RunTimeOp(a time.Time, op Operator, b time.Time) bool
- type And
- func (it *And) AddOptionalIterator(sub Shape) *And
- func (it *And) AddSubIterator(sub Shape)
- func (it *And) Iterate() Scanner
- func (it *And) Lookup() Index
- func (it *And) Optimize(ctx context.Context) (Shape, bool)
- func (it *And) Stats(ctx context.Context) (Costs, error)
- func (it *And) String() string
- func (it *And) SubIterators() []Shape
- type Base
- type Chain
- func (c *Chain) All() ([]refs.Ref, error)
- func (c *Chain) AllValues(qs refs.Namer) ([]quad.Value, error)
- func (c *Chain) Count() (int64, error)
- func (c *Chain) Each(fnc func(refs.Ref) error) error
- func (c *Chain) EachValue(qs refs.Namer, fnc func(quad.Value) error) error
- func (c *Chain) EachValuePair(qs refs.Namer, fnc func(refs.Ref, quad.Value) error) error
- func (c *Chain) First() (refs.Ref, error)
- func (c *Chain) FirstValue(qs refs.Namer) (quad.Value, error)
- func (c *Chain) Limit(n int) *Chain
- func (c *Chain) On(qs refs.Namer) *Chain
- func (c *Chain) Paths(enable bool) *Chain
- func (c *Chain) Send(out chan<- refs.Ref) error
- func (c *Chain) SendValues(qs refs.Namer, out chan<- quad.Value) error
- func (c *Chain) TagEach(fnc func(map[string]refs.Ref) error) error
- func (c *Chain) TagValues(qs refs.Namer, fnc func(map[string]quad.Value) error) error
- func (c *Chain) UnOptimized() *Chain
- type Costs
- type Count
- type Error
- func (it *Error) Close() error
- func (it *Error) Contains(ctx context.Context, v refs.Ref) bool
- func (it *Error) Err() error
- func (it *Error) Iterate() Scanner
- func (it *Error) Lookup() Index
- func (it *Error) Next(ctx context.Context) bool
- func (it *Error) NextPath(ctx context.Context) bool
- func (it *Error) Optimize(ctx context.Context) (Shape, bool)
- func (it *Error) Reset()
- func (it *Error) Result() refs.Ref
- func (it *Error) Stats(ctx context.Context) (Costs, error)
- func (it *Error) String() string
- func (it *Error) SubIterators() []Shape
- func (it *Error) TagResults(dst map[string]refs.Ref)
- type Fixed
- func (it *Fixed) Add(v refs.Ref)
- func (it *Fixed) Iterate() Scanner
- func (it *Fixed) Lookup() Index
- func (it *Fixed) Optimize(ctx context.Context) (Shape, bool)
- func (it *Fixed) Stats(ctx context.Context) (Costs, error)
- func (it *Fixed) String() string
- func (it *Fixed) SubIterators() []Shape
- func (it *Fixed) Values() []refs.Ref
- type Index
- type Int64Node
- type Limit
- type Materialize
- type Morphism
- type Not
- type Null
- func (it *Null) Close() error
- func (it *Null) Contains(ctx context.Context, v refs.Ref) bool
- func (it *Null) Err() error
- func (it *Null) Iterate() Scanner
- func (it *Null) Lookup() Index
- func (it *Null) Next(ctx context.Context) bool
- func (it *Null) NextPath(ctx context.Context) bool
- func (it *Null) Optimize(ctx context.Context) (Shape, bool)
- func (it *Null) Reset()
- func (it *Null) Result() refs.Ref
- func (it *Null) Stats(ctx context.Context) (Costs, error)
- func (it *Null) String() string
- func (it *Null) SubIterators() []Shape
- func (it *Null) TagResults(dst map[string]refs.Ref)
- type Operator
- type Or
- type Recursive
- func (it *Recursive) AddDepthTag(s string)
- func (it *Recursive) Iterate() Scanner
- func (it *Recursive) Lookup() Index
- func (it *Recursive) Optimize(ctx context.Context) (Shape, bool)
- func (it *Recursive) Stats(ctx context.Context) (Costs, error)
- func (it *Recursive) String() string
- func (it *Recursive) SubIterators() []Shape
- type Resolver
- type Save
- func (it *Save) AddFixedTag(tag string, value refs.Ref)
- func (it *Save) AddTags(tag ...string)
- func (it *Save) CopyFromTagger(st TaggerBase)
- func (it *Save) FixedTags() map[string]refs.Ref
- func (it *Save) Iterate() Scanner
- func (it *Save) Lookup() Index
- func (it *Save) Optimize(ctx context.Context) (nit Shape, no bool)
- func (it *Save) Stats(ctx context.Context) (Costs, error)
- func (it *Save) String() string
- func (it *Save) SubIterators() []Shape
- func (it *Save) Tags() []string
- type Scanner
- type Shape
- type Skip
- type Sort
- type TaggerBase
- type TaggerShape
- type Unique
- type ValueFilter
- type ValueFilterFunc
Constants ¶
const MaterializeLimit = 1000
Variables ¶
var DefaultMaxRecursiveSteps = 50
Functions ¶
Types ¶
type And ¶
type And struct {
// contains filtered or unexported fields
}
The And iterator. Consists of a number of subiterators, the primary of which will be Next()ed if next is called.
func NewAnd ¶
NewAnd creates an And iterator. `qs` is only required when needing a handle for QuadStore-specific optimizations, otherwise nil is acceptable.
func (*And) AddOptionalIterator ¶ added in v0.7.6
AddOptionalIterator adds an iterator that will only be Contain'ed and will not affect iteration results. Only tags will be propagated from this iterator.
func (*And) AddSubIterator ¶
Add a subiterator to this And iterator.
The first iterator that is added becomes the primary iterator. This is important. Calling Optimize() is the way to change the order based on subiterator statistics. Without Optimize(), the order added is the order used.
func (*And) Optimize ¶
Optimizes the And, by picking the most efficient way to Next() and Contains() its subiterators. For SQL fans, this is equivalent to JOIN.
func (*And) Stats ¶
Stats lives here in and-iterator-optimize.go because it may in the future return different statistics based on how it is optimized. For now, however, it's pretty static.
Returns the approximate size of the And iterator. Because we're dealing with an intersection, we know that the largest we can be is the size of the smallest iterator. This is the heuristic we shall follow. Better heuristics welcome.
func (*And) SubIterators ¶
Returns a slice of the subiterators, in order (primary iterator first).
type Base ¶
type Base interface { // String returns a short textual representation of an iterator. String() string // Fills a tag-to-result-value map. TagResults(map[string]refs.Ref) // Returns the current result. Result() refs.Ref // These methods are the heart and soul of the iterator, as they constitute // the iteration interface. // // To get the full results of iteration, do the following: // // for it.Next(ctx) { // val := it.Result() // ... do things with val. // for it.NextPath(ctx) { // ... find other paths to iterate // } // } // // All of them should set iterator.result to be the last returned value, to // make results work. // // NextPath() advances iterators that may have more than one valid result, // from the bottom up. NextPath(ctx context.Context) bool // Err returns any error that was encountered by the Iterator. Err() error // Close the iterator and do internal cleanup. Close() error }
Base is a set of common methods for Scanner and Index iterators.
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain is a chain-enabled helper to setup iterator execution.
func Iterate ¶
Iterate is a set of helpers for iteration. Context may be used to cancel execution. Iterator will be optimized and closed after execution.
By default, iteration has no limit and includes sub-paths.
func (*Chain) AllValues ¶
AllValues is an analog of All, but it will additionally call NameOf for each graph.Ref before returning the results slice.
func (*Chain) EachValue ¶
EachValue is an analog of Each, but it will additionally call NameOf for each graph.Ref before passing it to a callback.
func (*Chain) EachValuePair ¶
EachValuePair is an analog of Each, but it will additionally call NameOf for each graph.Ref before passing it to a callback. Original value will be passed as well.
func (*Chain) First ¶
First will return a first result of an iterator. It returns nil if iterator is empty.
func (*Chain) FirstValue ¶
FirstValue is an analog of First, but it does lookup of a value in QuadStore.
func (*Chain) On ¶
On sets a default quad store for iteration. If qs was set, it may be omitted in other functions.
func (*Chain) Send ¶
Send will send each result of the iterator to the provided channel.
Channel will NOT be closed when function returns.
func (*Chain) SendValues ¶
SendValues is an analog of Send, but it will additionally call NameOf for each graph.Ref before sending it to a channel.
func (*Chain) TagEach ¶
TagEach will run a provided tag map callback for each result of the iterator.
func (*Chain) TagValues ¶
TagValues is an analog of TagEach, but it will additionally call NameOf for each graph.Ref before passing the map to a callback.
func (*Chain) UnOptimized ¶
UnOptimized disables iterator optimization.
type Count ¶ added in v0.6.0
type Count struct {
// contains filtered or unexported fields
}
Count iterator returns one element with size of underlying iterator.
func NewCount ¶ added in v0.6.0
NewCount creates a new iterator to count a number of results from a provided subiterator. qs may be nil - it's used to check if count Contains (is) a given value.
func (*Count) SubIterators ¶ added in v0.6.0
SubIterators returns a slice of the sub iterators.
type Error ¶ added in v0.7.0
type Error struct {
// contains filtered or unexported fields
}
Error iterator always returns a single error with no other results.
func (*Error) SubIterators ¶ added in v0.7.0
type Fixed ¶
type Fixed struct {
// contains filtered or unexported fields
}
A Fixed iterator consists of it's values, an index (where it is in the process of Next()ing) and an equality function.
func (*Fixed) Add ¶
Add a value to the iterator. The array now contains this value. TODO(barakmich): This ought to be a set someday, disallowing repeated values.
func (*Fixed) Optimize ¶
Optimize() for a Fixed iterator is simple. Returns a Null iterator if it's empty (so that other iterators upstream can treat this as null) or there is no optimization.
type Index ¶
type Index interface { Base // Contains returns whether the value is within the set held by the iterator. // // It will set Result to the matching subtree. TagResults can be used to collect values from tree branches. Contains(ctx context.Context, v refs.Ref) bool }
Index is an index lookup iterator. It allows to check if an index contains a specific value.
type Limit ¶ added in v0.6.0
type Limit struct {
// contains filtered or unexported fields
}
Limit iterator will stop iterating if certain a number of values were encountered. Zero and negative Limit values means no Limit.
func (*Limit) SubIterators ¶ added in v0.6.0
SubIterators returns a slice of the sub iterators.
type Materialize ¶ added in v0.4.0
type Materialize struct {
// contains filtered or unexported fields
}
func NewMaterialize ¶ added in v0.4.0
func NewMaterialize(sub Shape) *Materialize
func NewMaterializeWithSize ¶ added in v0.7.0
func NewMaterializeWithSize(sub Shape, size int64) *Materialize
func (*Materialize) Iterate ¶
func (it *Materialize) Iterate() Scanner
func (*Materialize) Lookup ¶
func (it *Materialize) Lookup() Index
func (*Materialize) Optimize ¶ added in v0.4.0
func (it *Materialize) Optimize(ctx context.Context) (Shape, bool)
func (*Materialize) Stats ¶ added in v0.4.0
func (it *Materialize) Stats(ctx context.Context) (Costs, error)
The entire point of Materialize is to amortize the cost by putting it all up front.
func (*Materialize) String ¶ added in v0.7.0
func (it *Materialize) String() string
func (*Materialize) SubIterators ¶ added in v0.4.0
func (it *Materialize) SubIterators() []Shape
type Not ¶ added in v0.4.1
type Not struct {
// contains filtered or unexported fields
}
Not iterator acts like a complement for the primary iterator. It will return all the vertices which are not part of the primary iterator.
func (*Not) SubIterators ¶ added in v0.4.1
SubIterators returns a slice of the sub iterators. The first iterator is the primary iterator, for which the complement is generated.
type Null ¶
type Null struct{}
Null is the simplest iterator -- the Null iterator. It contains nothing. It is the empty set. Often times, queries that contain one of these match nothing, so it's important to give it a special iterator.
func NewNull ¶
func NewNull() *Null
NewNull creates a new Null iterator Fairly useless New function.
func (*Null) Optimize ¶
A good iterator will close itself when it returns true. Null has nothing it needs to do.
func (*Null) SubIterators ¶
type Or ¶
type Or struct {
// contains filtered or unexported fields
}
func NewShortCircuitOr ¶
func (*Or) AddSubIterator ¶
Add a subiterator to this Or iterator. Order matters.
func (*Or) Stats ¶
Returns the approximate size of the Or iterator. Because we're dealing with a union, we know that the largest we can be is the sum of all the iterators, or in the case of short-circuiting, the longest.
func (*Or) SubIterators ¶
Returns a list.List of the subiterators, in order. The returned slice must not be modified.
type Recursive ¶ added in v0.6.1
type Recursive struct {
// contains filtered or unexported fields
}
Recursive iterator takes a base iterator and a morphism to be applied recursively, for each result.
func NewRecursive ¶ added in v0.6.1
func (*Recursive) AddDepthTag ¶ added in v0.6.1
func (*Recursive) SubIterators ¶ added in v0.6.1
type Resolver ¶ added in v0.7.5
type Resolver struct {
// contains filtered or unexported fields
}
A Resolver iterator consists of it's order, an index (where it is in the, process of iterating) and a store to resolve values from.
func NewResolver ¶ added in v0.7.5
NewResolver creates a new Resolver iterator.
func (*Resolver) Optimize ¶ added in v0.7.5
Returns a Null iterator if it's empty so that upstream iterators can optimize it away, otherwise there is no optimization.
func (*Resolver) SubIterators ¶ added in v0.7.5
type Save ¶ added in v0.7.6
type Save struct {
// contains filtered or unexported fields
}
func (*Save) CopyFromTagger ¶ added in v0.7.6
func (it *Save) CopyFromTagger(st TaggerBase)
func (*Save) FixedTags ¶ added in v0.7.6
Fixed returns the fixed tags held in the tagger. The returned value must not be mutated.
func (*Save) SubIterators ¶
type Scanner ¶
type Scanner interface { Base // Next advances the iterator to the next value, which will then be available through // the Result method. It returns false if no further advancement is possible, or if an // error was encountered during iteration. Err should be consulted to distinguish // between the two cases. Next(ctx context.Context) bool }
Scanner is an iterator that lists all results sequentially, but not necessarily in a sorted order.
func NewLimitNext ¶
type Shape ¶
type Shape interface { // String returns a short textual representation of an iterator. String() string // Iterate starts this iterator in scanning mode. Resulting iterator will list all // results sequentially, but not necessary in the sorted order. Caller must close // the iterator. Iterate() Scanner // Lookup starts this iterator in an index lookup mode. Depending on the iterator type, // this may still involve database scans. Resulting iterator allows to check an index // contains a specified value. Caller must close the iterator. Lookup() Index // These methods relate to choosing the right iterator, or optimizing an // iterator tree // // Stats() returns the relative costs of calling the iteration methods for // this iterator, as well as the size. Roughly, it will take NextCost * Size // "cost units" to get everything out of the iterator. This is a wibbly-wobbly // thing, and not exact, but a useful heuristic. Stats(ctx context.Context) (Costs, error) // Optimizes an iterator. Can replace the iterator, or merely move things // around internally. if it chooses to replace it with a better iterator, // returns (the new iterator, true), if not, it returns (self, false). Optimize(ctx context.Context) (Shape, bool) // Return a slice of the subiterators for this iterator. SubIterators() []Shape }
Shape is an iterator shape, similar to a query plan. But the plan is not specific in this case - it is used to reorder query branches, and the decide what branches will be scanned and what branches will lookup values (hopefully from the index, but not necessarily).
func NewComparison ¶
func NewRegex ¶ added in v0.6.0
NewRegex returns an unary operator -- a filter across the values in the relevant subiterator. It works similarly to gremlin's filter{it.matches('exp')}, reducing the iterator set to values whose string representation passes a regular expression test.
func NewRegexWithRefs ¶ added in v0.7.6
NewRegexWithRefs is like NewRegex but allows regexp iterator to match IRIs and BNodes.
Consider using it carefully. In most cases it's better to reconsider your graph structure instead of relying on slow unoptimizable regexp.
An example of incorrect usage is to match IRIs:
<http://example.org/page> <http://example.org/page/foo>
Via regexp like:
http://example.org/page.*
The right way is to explicitly link graph nodes and query them by this relation:
<http://example.org/page/foo> <type> <http://example.org/page>
type Skip ¶ added in v0.6.0
type Skip struct {
// contains filtered or unexported fields
}
Skip iterator will skip certain number of values from primary iterator.
func (*Skip) SubIterators ¶ added in v0.6.0
SubIterators returns a slice of the sub iterators.
type Sort ¶ added in v0.7.6
type Sort struct {
// contains filtered or unexported fields
}
Sort iterator orders values from it's subiterator.
func NewSort ¶ added in v0.7.6
NewSort creates a new Sort iterator. TODO(dennwc): This iterator must not be used inside And: it may be moved to a Contains branch and won't do anything.
We should make And/Intersect account for this.
func (*Sort) SubIterators ¶
SubIterators returns a slice of the sub iterators.
type TaggerBase ¶
type TaggerBase interface { Tags() []string FixedTags() map[string]refs.Ref AddTags(tag ...string) AddFixedTag(tag string, value refs.Ref) }
TaggerBase is a base interface for Tagger and TaggerShape.
type TaggerShape ¶
type TaggerShape interface { Shape TaggerBase CopyFromTagger(st TaggerBase) }
TaggerShape is an interface for iterators that can tag values. Tags are returned as a part of TagResults call.
type Unique ¶ added in v0.5.0
type Unique struct {
// contains filtered or unexported fields
}
Unique iterator removes duplicate values from it's subiterator.
func (*Unique) SubIterators ¶ added in v0.5.0
SubIterators returns a slice of the sub iterators. The first iterator is the primary iterator, for which the complement is generated.
type ValueFilter ¶ added in v0.7.6
type ValueFilter struct {
// contains filtered or unexported fields
}
func NewValueFilter ¶ added in v0.7.6
func NewValueFilter(qs refs.Namer, sub Shape, filter ValueFilterFunc) *ValueFilter
func (*ValueFilter) Iterate ¶
func (it *ValueFilter) Iterate() Scanner
func (*ValueFilter) Lookup ¶
func (it *ValueFilter) Lookup() Index
func (*ValueFilter) Optimize ¶
func (it *ValueFilter) Optimize(ctx context.Context) (Shape, bool)
There's nothing to optimize, locally, for a value-comparison iterator. Replace the underlying iterator if need be. potentially replace it.
func (*ValueFilter) Stats ¶
func (it *ValueFilter) Stats(ctx context.Context) (Costs, error)
We're only as expensive as our subiterator. Again, optimized value comparison iterators should do better.
func (*ValueFilter) String ¶
func (it *ValueFilter) String() string
func (*ValueFilter) SubIterators ¶
func (it *ValueFilter) SubIterators() []Shape