graph

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDatabaseExists = errors.New("quadstore: cannot init; database already exists")
	ErrNotInitialized = errors.New("quadstore: not initialized")
)
View Source
var (
	ErrQuadExists    = errors.New("quad exists")
	ErrQuadNotExist  = errors.New("quad does not exist")
	ErrInvalidAction = errors.New("invalid action")
	ErrNodeNotExists = errors.New("node does not exist")
)
View Source
var (
	// IgnoreDuplicates specifies whether duplicate quads
	// cause an error during loading or are ignored.
	IgnoreDuplicates = true

	// IgnoreMissing specifies whether missing quads
	// cause an error during deletion or are ignored.
	IgnoreMissing = false
)
View Source
var (
	ErrQuadStoreNotRegistred  = fmt.Errorf("this QuadStore is not registered")
	ErrQuadStoreNotPersistent = fmt.Errorf("cannot specify address for non-persistent backend")
	ErrOperationNotSupported  = fmt.Errorf("this Operation is not supported")
)

Functions

func InitQuadStore added in v0.4.1

func InitQuadStore(name string, dbpath string, opts Options) error

func IsInvalidAction added in v0.6.0

func IsInvalidAction(err error) bool

IsInvalidAction returns whether an error is a DeltaError with the Err field equal to ErrInvalidAction.

func IsPersistent added in v0.4.0

func IsPersistent(name string) bool

func IsQuadExist added in v0.6.0

func IsQuadExist(err error) bool

IsQuadExist returns whether an error is a DeltaError with the Err field equal to ErrQuadExists.

func IsQuadNotExist added in v0.6.0

func IsQuadNotExist(err error) bool

IsQuadNotExist returns whether an error is a DeltaError with the Err field equal to ErrQuadNotExist.

func IsRegistered added in v0.7.0

func IsRegistered(name string) bool

func NewQuadStoreReader added in v0.6.1

func NewQuadStoreReader(qs QuadStore) quad.ReadSkipCloser

NewQuadStoreReader creates a quad reader for a given QuadStore.

func NewResultReader added in v0.6.1

func NewResultReader(qs QuadStore, it iterator.Scanner) quad.ReadSkipCloser

NewResultReader creates a quad reader for a given QuadStore and iterator. If iterator is nil QuadsAllIterator will be used.

Only quads returned by iterator's Result will be used.

Iterator will be closed with the reader.

func NewTxWriter added in v0.7.0

func NewTxWriter(tx *Transaction, p Procedure) quad.Writer

NewTxWriter creates a writer that applies a given procedures for all quads in stream. If procedure is zero, Add operation will be used.

func QuadStores added in v0.4.1

func QuadStores() []string

func RegisterQuadStore added in v0.4.1

func RegisterQuadStore(name string, register QuadStoreRegistration)

func RegisterWriter added in v0.4.0

func RegisterWriter(name string, newFunc NewQuadWriterFunc)

func UpgradeQuadStore added in v0.5.0

func UpgradeQuadStore(name string, dbpath string, opts Options) error

func ValuesOf added in v0.7.0

func ValuesOf(ctx context.Context, qs refs.Namer, vals []Ref) ([]quad.Value, error)

func WriterMethods added in v0.4.0

func WriterMethods() []string

Types

type BatchWriter added in v0.6.1

type BatchWriter interface {
	quad.WriteCloser
	Flush() error
}

func NewRemover added in v0.6.1

func NewRemover(qs QuadWriter) BatchWriter

NewRemover creates a quad writer for a given QuadStore which removes quads instead of adding them.

func NewWriter added in v0.6.1

func NewWriter(qs QuadWriter) BatchWriter

NewWriter creates a quad writer for a given QuadStore.

Caller must call Flush or Close to flush an internal buffer.

type Delta added in v0.4.0

type Delta struct {
	Quad   quad.Quad
	Action Procedure
}

type DeltaError added in v0.6.0

type DeltaError struct {
	Delta Delta
	Err   error
}

DeltaError records an error and the delta that caused it.

func (*DeltaError) Error added in v0.6.0

func (e *DeltaError) Error() string

type Handle added in v0.4.0

type Handle struct {
	QuadStore
	QuadWriter
}

func (*Handle) Close added in v0.4.0

func (h *Handle) Close() error

type HasA added in v0.3.1

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

A HasA consists of a reference back to the graph.QuadStore that it references, a primary subiterator, a direction in which the quads for that subiterator point, and a temporary holder for the iterator generated on Contains().

func NewHasA added in v0.7.8

func NewHasA(qs QuadIndexer, subIt iterator.Shape, d quad.Direction) *HasA

NewHasA construct a new HasA iterator, given the quad subiterator, and the quad direction for which it stands.

func (*HasA) Direction added in v0.7.8

func (it *HasA) Direction() quad.Direction

Direction accessor.

func (*HasA) Iterate added in v0.7.8

func (it *HasA) Iterate() iterator.Scanner

func (*HasA) Lookup added in v0.7.8

func (it *HasA) Lookup() iterator.Index

func (*HasA) Optimize added in v0.7.8

func (it *HasA) Optimize(ctx context.Context) (iterator.Shape, bool)

Optimize pass the Optimize() call along to the subiterator. If it becomes Null, then the HasA becomes Null (there are no quads that have any directions).

func (*HasA) Stats added in v0.7.8

func (it *HasA) Stats(ctx context.Context) (iterator.Costs, error)

Stats returns the statistics on the HasA iterator. This is curious. Next cost is easy, it's an extra call or so on top of the subiterator Next cost. ContainsCost involves going to the graph.QuadStore, iterating out values, and hoping one sticks -- potentially expensive, depending on fanout. Size, however, is potentially smaller. we know at worst it's the size of the subiterator, but if there are many repeated values, it could be much smaller in totality.

func (*HasA) String added in v0.7.8

func (it *HasA) String() string

func (*HasA) SubIterators added in v0.7.8

func (it *HasA) SubIterators() []iterator.Shape

SubIterators returns our sole subiterator.

type IgnoreOpts added in v0.4.1

type IgnoreOpts struct {
	IgnoreDup, IgnoreMissing bool
}

type InitStoreFunc added in v0.3.1

type InitStoreFunc func(string, Options) error

type LinksTo added in v0.3.1

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

A LinksTo has a reference back to the graph.QuadStore (to create the iterators for each node) the subiterator, and the direction the iterator comes from. `next_it` is the tempoarary iterator held per result in `primary_it`.

func NewLinksTo added in v0.7.8

func NewLinksTo(qs QuadIndexer, it iterator.Shape, d quad.Direction) *LinksTo

NewLinksTo construct a new LinksTo iterator around a direction and a subiterator of nodes.

func (*LinksTo) Direction added in v0.7.8

func (it *LinksTo) Direction() quad.Direction

Direction returns the direction under consideration.

func (*LinksTo) Iterate added in v0.7.8

func (it *LinksTo) Iterate() iterator.Scanner

func (*LinksTo) Lookup added in v0.7.8

func (it *LinksTo) Lookup() iterator.Index

func (*LinksTo) Optimize added in v0.7.8

func (it *LinksTo) Optimize(ctx context.Context) (iterator.Shape, bool)

Optimize the LinksTo, by replacing it if it can be.

func (*LinksTo) Stats added in v0.7.8

func (it *LinksTo) Stats(ctx context.Context) (iterator.Costs, error)

Stats returns a guess as to how big or costly it is to next the iterator.

func (*LinksTo) String added in v0.7.8

func (it *LinksTo) String() string

func (*LinksTo) SubIterators added in v0.7.8

func (it *LinksTo) SubIterators() []iterator.Shape

SubIterators returns a list containing only our subiterator.

type NewQuadWriterFunc added in v0.4.0

type NewQuadWriterFunc func(QuadStore, Options) (QuadWriter, error)

type NewStoreFunc added in v0.3.1

type NewStoreFunc func(string, Options) (QuadStore, error)

type Options added in v0.3.1

type Options map[string]interface{}

func (Options) BoolKey added in v0.4.0

func (d Options) BoolKey(key string, def bool) (bool, error)

func (Options) IntKey added in v0.3.1

func (d Options) IntKey(key string, def int) (int, error)

func (Options) StringKey added in v0.3.1

func (d Options) StringKey(key string, def string) (string, error)

type Procedure added in v0.4.0

type Procedure int8
const (
	Add    Procedure = +1
	Delete Procedure = -1
)

The different types of actions a transaction can do.

func (Procedure) String added in v0.6.0

func (p Procedure) String() string

type QuadIndexer added in v0.7.8

type QuadIndexer interface {
	// Given an opaque token, returns the quad for that token from the store.
	Quad(Ref) quad.Quad

	// Given a direction and a token, creates an iterator of links which have
	// that node token in that directional field.
	QuadIterator(quad.Direction, Ref) iterator.Shape

	// QuadIteratorSize returns an estimated size of an iterator.
	QuadIteratorSize(ctx context.Context, d quad.Direction, v Ref) (refs.Size, error)

	// Convenience function for speed. Given a quad token and a direction
	// return the node token for that direction. Sometimes, a QuadStore
	// can do this without going all the way to the backing store, and
	// gives the QuadStore the opportunity to make this optimization.
	//
	// Iterators will call this. At worst, a valid implementation is
	//
	//  qs.ValueOf(qs.Quad(id).Get(dir))
	//
	QuadDirection(id Ref, d quad.Direction) Ref

	// Stats returns the number of nodes and quads currently stored.
	// Exact flag controls the correctness of the value. It can be an estimation, or a precise calculation.
	// The quadstore may have a fast way of retrieving the precise stats, in this case it may ignore 'exact'
	// flag and always return correct stats (with an appropriate flags set in the output).
	Stats(ctx context.Context, exact bool) (Stats, error)
}

type QuadStore added in v0.4.1

type QuadStore interface {
	refs.Namer
	QuadIndexer

	// The only way in is through building a transaction, which
	// is done by a replication strategy.
	ApplyDeltas(in []Delta, opts IgnoreOpts) error

	// NewQuadWriter starts a batch quad import process.
	// The order of changes is not guaranteed, neither is the order and result of concurrent ApplyDeltas.
	NewQuadWriter() (quad.WriteCloser, error)

	// Returns an iterator enumerating all nodes in the graph.
	NodesAllIterator() iterator.Shape

	// Returns an iterator enumerating all links in the graph.
	QuadsAllIterator() iterator.Shape

	// Close the quad store and clean up. (Flush to disk, cleanly
	// sever connections, etc)
	Close() error
}

func NewQuadStore added in v0.4.1

func NewQuadStore(name string, dbpath string, opts Options) (QuadStore, error)

func Unwrap added in v0.7.1

func Unwrap(qs QuadStore) QuadStore

Unwrap returns an original QuadStore value if it was wrapped by Handle. This prevents shadowing of optional interface implementations.

type QuadStoreRegistration added in v0.5.0

type QuadStoreRegistration struct {
	NewFunc      NewStoreFunc
	UpgradeFunc  UpgradeStoreFunc
	InitFunc     InitStoreFunc
	IsPersistent bool
}

type QuadWriter added in v0.4.0

type QuadWriter interface {
	// AddQuad adds a quad to the store.
	AddQuad(quad.Quad) error

	// TODO(barakmich): Deprecate in favor of transaction.
	// AddQuadSet adds a set of quads to the store, atomically if possible.
	AddQuadSet([]quad.Quad) error

	// RemoveQuad removes a quad matching the given one  from the database,
	// if it exists. Does nothing otherwise.
	RemoveQuad(quad.Quad) error

	// ApplyTransaction applies a set of quad changes.
	ApplyTransaction(*Transaction) error

	// RemoveNode removes all quads which have the given node as subject, predicate, object, or label.
	//
	// It returns ErrNodeNotExists if node is missing.
	RemoveNode(quad.Value) error

	// Close cleans up replication and closes the writing aspect of the database.
	Close() error
}

func NewQuadWriter added in v0.4.0

func NewQuadWriter(name string, qs QuadStore, opts Options) (QuadWriter, error)

type Ref added in v0.7.8

type Ref = refs.Ref

Ref defines an opaque "quad store reference" type. However the backend wishes to implement it, a Ref is merely a token to a quad or a node that the backing store itself understands, and the base iterators pass around.

For example, in a very traditional, graphd-style graph, these are int64s (guids of the primitives). In a very direct sort of graph, these could be pointers to structs, or merely quads, or whatever works best for the backing store.

These must be comparable, or return a comparable version on Key.

func RefsOf added in v0.7.5

func RefsOf(ctx context.Context, qs refs.Namer, nodes []quad.Value) ([]Ref, error)

type Stats added in v0.7.8

type Stats struct {
	Nodes refs.Size // number of nodes
	Quads refs.Size // number of quads
}

Stats of a graph.

type Transaction added in v0.5.0

type Transaction struct {
	// Deltas stores the deltas in the right order
	Deltas []Delta
	// contains filtered or unexported fields
}

Transaction stores a bunch of Deltas to apply together in an atomic step on the database.

func NewTransaction added in v0.5.0

func NewTransaction() *Transaction

NewTransaction initialize a new transaction.

func NewTransactionN added in v0.7.4

func NewTransactionN(n int) *Transaction

NewTransactionN initialize a new transaction with a predefined capacity.

func (*Transaction) AddQuad added in v0.5.0

func (t *Transaction) AddQuad(q quad.Quad)

AddQuad adds a new quad to the transaction if it is not already present in it. If there is a 'remove' delta for that quad, it will remove that delta from the transaction instead of actually adding the quad.

func (*Transaction) RemoveQuad added in v0.5.0

func (t *Transaction) RemoveQuad(q quad.Quad)

RemoveQuad adds a quad to remove to the transaction. The quad will be removed from the database if it is not present in the transaction, otherwise it simply remove it from the transaction.

type UpgradeStoreFunc added in v0.5.0

type UpgradeStoreFunc func(string, Options) error

Directories

Path Synopsis
kv
all
Package b implements a B+tree.
Package b implements a B+tree.
all
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.
sql

Jump to

Keyboard shortcuts

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