knowledge

package
v0.0.85 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MatchScope = Scope{Context: MatchContext, ID: 0}

MatchScope default match scope. All patterns in the MATCH clause should have this scope.

Functions

func MeasureDuration

func MeasureDuration(Func func()) time.Duration

Types

type AndOrExpression added in v0.0.6

type AndOrExpression struct {
	And        bool // true for And and false for Or
	Children   []AndOrExpression
	Expression string
}

AndOrExpression represent a AND or OR expression

func CrossProductExpressions added in v0.0.6

func CrossProductExpressions(and1 []AndOrExpression, and2 []AndOrExpression) []AndOrExpression

CrossProductExpressions computes the cross product of 2 sets of expressions. This is used to transform OR expressions into a union of AND expressions.

func FlattenAndOrExpressions added in v0.0.54

func FlattenAndOrExpressions(tree AndOrExpression) (AndOrExpression, error)

func UnwindOrExpressions added in v0.0.6

func UnwindOrExpressions(tree AndOrExpression) ([]AndOrExpression, error)

UnwindOrExpressions in order to transform query with or relations into a union query which is more performant, an AndOrExpression is transformed into a list of AndExpressions

func (AndOrExpression) String added in v0.0.30

func (aoe AndOrExpression) String() string

type Asset

type Asset AssetKey

Asset represent the asset with details

func NewAsset

func NewAsset(assetType schema.AssetType, assetKey string) Asset

NewAsset create a new asset from type and key

type AssetKey

type AssetKey struct {
	Type schema.AssetType `json:"type"`
	Key  string           `json:"key"`
}

AssetKey represent the key of the asset

type AssetWithID

type AssetWithID struct {
	ID    string `json:"_id"`
	Asset `json:",inline"`
}

AssetWithID represent an asset with an ID from the database

func (AssetWithID) String

func (a AssetWithID) String() string

type Cursor

type Cursor interface {
	HasMore() bool
	Read(ctx context.Context, doc interface{}) error
	Close() error
}

Cursor is a cursor over the results

type ExpressionBuilder

type ExpressionBuilder struct {
	QueryGraph *QueryGraph
	// contains filtered or unexported fields
}

ExpressionBuilder build a SQL part based on a Cypher expression

func NewExpressionBuilder

func NewExpressionBuilder(queryGraph *QueryGraph) *ExpressionBuilder

NewExpressionBuilder create a new instance of expression builder

func (*ExpressionBuilder) Build added in v0.0.6

Build the SQL expression from the Cypher expression

type ExpressionParser added in v0.0.6

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

ExpressionParser is a parser of expression

func NewExpressionParser added in v0.0.6

func NewExpressionParser(visitor ExpressionVisitor, queryGraph *QueryGraph) *ExpressionParser

NewExpressionParser create a new instance of expression parser.

func (*ExpressionParser) ParseAddOrSubtractExpression added in v0.0.6

func (ep *ExpressionParser) ParseAddOrSubtractExpression(q *query.QueryAddOrSubtractExpression) error

ParseAddOrSubtractExpression parse add or subtract expression

func (*ExpressionParser) ParseComparisonExpression added in v0.0.6

func (ep *ExpressionParser) ParseComparisonExpression(q *query.QueryComparisonExpression) error

ParseComparisonExpression parse comparison expression

func (*ExpressionParser) ParseExpression added in v0.0.6

func (ep *ExpressionParser) ParseExpression(q *query.QueryExpression) error

ParseExpression parse expression

func (*ExpressionParser) ParseMultipleDivideModuloExpression added in v0.0.6

func (ep *ExpressionParser) ParseMultipleDivideModuloExpression(q *query.QueryMultipleDivideModuloExpression) error

ParseMultipleDivideModuloExpression parse multiple divide modulo expression

func (*ExpressionParser) ParseNotExpression added in v0.0.6

func (ep *ExpressionParser) ParseNotExpression(q *query.QueryNotExpression) error

ParseNotExpression parse not expression

func (*ExpressionParser) ParseOrExpression added in v0.0.6

func (ep *ExpressionParser) ParseOrExpression(q *query.QueryOrExpression) error

ParseOrExpression parse or expression

func (*ExpressionParser) ParsePowerOfExpression added in v0.0.6

func (ep *ExpressionParser) ParsePowerOfExpression(q *query.QueryPowerOfExpression) error

ParsePowerOfExpression parse power of expression

func (*ExpressionParser) ParsePropertyOrLabelsExpression added in v0.0.6

func (ep *ExpressionParser) ParsePropertyOrLabelsExpression(q *query.QueryPropertyOrLabelsExpression) error

ParsePropertyOrLabelsExpression parse property or labels expression

func (*ExpressionParser) ParseRelationshipsPattern added in v0.0.32

func (ep *ExpressionParser) ParseRelationshipsPattern(q *query.QueryRelationshipsPattern) error

ParseRelationshipsPattern parse a query relationships pattern

func (*ExpressionParser) ParseStringListNullOperatorExpression added in v0.0.6

func (ep *ExpressionParser) ParseStringListNullOperatorExpression(q *query.QueryStringListNullOperatorExpression) error

ParseStringListNullOperatorExpression parse string list null operator expression

func (*ExpressionParser) ParseUnaryAddOrSubtractExpression added in v0.0.6

func (ep *ExpressionParser) ParseUnaryAddOrSubtractExpression(q *query.QueryUnaryAddOrSubtractExpression) error

ParseUnaryAddOrSubtractExpression parse unary add or subtract expression

func (*ExpressionParser) ParseXorExpression added in v0.0.6

func (ep *ExpressionParser) ParseXorExpression(q *query.QueryXorExpression) error

ParseXorExpression parse xor expression

type ExpressionType

type ExpressionType int

ExpressionType expression type

const (
	// NodeExprType node expression type
	NodeExprType ExpressionType = iota
	// EdgeExprType edge expression type
	EdgeExprType ExpressionType = iota
	// PropertyExprType property expression type
	PropertyExprType ExpressionType = iota
)

type ExpressionVisitor added in v0.0.6

type ExpressionVisitor interface {
	OnEnterPropertyOrLabelsExpression(e query.QueryPropertyOrLabelsExpression) error
	OnExitPropertyOrLabelsExpression(e query.QueryPropertyOrLabelsExpression) error

	OnEnterStringListNullOperatorExpression(e query.QueryStringListNullOperatorExpression) error
	OnExitStringListNullOperatorExpression(e query.QueryStringListNullOperatorExpression) error

	OnVariable(name string) error
	OnVariablePropertiesPath(propertiesPath []string) error

	OnStringLiteral(value string) error
	OnDoubleLiteral(value float64) error
	OnIntegerLiteral(value int64) error
	OnBooleanLiteral(value bool) error

	OnEnterFunctionInvocation(name string, distinct bool) error
	OnExitFunctionInvocation(name string, distinct bool) error

	OnEnterRelationshipsPattern(q query.QueryRelationshipsPattern, id int) error
	OnExitRelationshipsPattern(q query.QueryRelationshipsPattern, id int) error

	OnNodePattern(q query.QueryNodePattern) error
	OnRelationshipPattern(q query.QueryRelationshipPattern) error

	OnEnterParenthesizedExpression() error
	OnExitParenthesizedExpression() error

	OnStringOperator(operator query.StringOperator) error

	OnEnterUnaryExpression() error
	OnExitUnaryExpression() error

	OnEnterPowerOfExpression() error
	OnExitPowerOfExpression() error

	OnEnterMultipleDivideModuloExpression() error
	OnExitMultipleDivideModuloExpression() error
	OnMultiplyDivideModuloOperator(operator query.MultiplyDivideModuloOperator) error

	OnEnterAddOrSubtractExpression() error
	OnExitAddOrSubtractExpression() error
	OnAddOrSubtractOperator(operator query.AddOrSubtractOperator) error

	OnEnterComparisonExpression() error
	OnExitComparisonExpression() error
	OnComparisonOperator(operator query.ComparisonOperator) error

	OnEnterNotExpression(not bool) error
	OnExitNotExpression(not bool) error

	OnEnterAndExpression() error
	OnExitAndExpression() error

	OnEnterXorExpression() error
	OnExitXorExpression() error

	OnEnterOrExpression() error
	OnExitOrExpression() error

	OnEnterExpression() error
	OnExitExpression() error
}

ExpressionVisitor a visitor of expression

type ExpressionVisitorBase added in v0.0.6

type ExpressionVisitorBase struct{}

ExpressionVisitorBase expression visitor base interface

func (*ExpressionVisitorBase) OnAddOrSubtractOperator added in v0.0.6

func (evb *ExpressionVisitorBase) OnAddOrSubtractOperator(operator query.AddOrSubtractOperator) error

func (*ExpressionVisitorBase) OnBooleanLiteral added in v0.0.6

func (evb *ExpressionVisitorBase) OnBooleanLiteral(value bool) error

func (*ExpressionVisitorBase) OnComparisonOperator added in v0.0.6

func (evb *ExpressionVisitorBase) OnComparisonOperator(operator query.ComparisonOperator) error

func (*ExpressionVisitorBase) OnDoubleLiteral added in v0.0.6

func (evb *ExpressionVisitorBase) OnDoubleLiteral(value float64) error

func (*ExpressionVisitorBase) OnEnterAddOrSubtractExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterAddOrSubtractExpression() error

func (*ExpressionVisitorBase) OnEnterAndExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterAndExpression() error

func (*ExpressionVisitorBase) OnEnterComparisonExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterComparisonExpression() error

func (*ExpressionVisitorBase) OnEnterExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterExpression() error

func (*ExpressionVisitorBase) OnEnterFunctionInvocation added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterFunctionInvocation(name string, distinct bool) error

func (*ExpressionVisitorBase) OnEnterMultipleDivideModuloExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterMultipleDivideModuloExpression() error

func (*ExpressionVisitorBase) OnEnterNotExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterNotExpression(not bool) error

func (*ExpressionVisitorBase) OnEnterOrExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterOrExpression() error

func (*ExpressionVisitorBase) OnEnterParenthesizedExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterParenthesizedExpression() error

func (*ExpressionVisitorBase) OnEnterPowerOfExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterPowerOfExpression() error

func (*ExpressionVisitorBase) OnEnterPropertyOrLabelsExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterPropertyOrLabelsExpression(e query.QueryPropertyOrLabelsExpression) error

func (*ExpressionVisitorBase) OnEnterRelationshipsPattern added in v0.0.30

func (evb *ExpressionVisitorBase) OnEnterRelationshipsPattern(q query.QueryRelationshipsPattern, id int) error

func (*ExpressionVisitorBase) OnEnterStringListNullOperatorExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterStringListNullOperatorExpression(e query.QueryStringListNullOperatorExpression) error

func (*ExpressionVisitorBase) OnEnterUnaryExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterUnaryExpression() error

func (*ExpressionVisitorBase) OnEnterXorExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnEnterXorExpression() error

func (*ExpressionVisitorBase) OnExitAddOrSubtractExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitAddOrSubtractExpression() error

func (*ExpressionVisitorBase) OnExitAndExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitAndExpression() error

func (*ExpressionVisitorBase) OnExitComparisonExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitComparisonExpression() error

func (*ExpressionVisitorBase) OnExitExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitExpression() error

func (*ExpressionVisitorBase) OnExitFunctionInvocation added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitFunctionInvocation(name string, distinct bool) error

func (*ExpressionVisitorBase) OnExitMultipleDivideModuloExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitMultipleDivideModuloExpression() error

func (*ExpressionVisitorBase) OnExitNotExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitNotExpression(not bool) error

func (*ExpressionVisitorBase) OnExitOrExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitOrExpression() error

func (*ExpressionVisitorBase) OnExitParenthesizedExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitParenthesizedExpression() error

func (*ExpressionVisitorBase) OnExitPowerOfExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitPowerOfExpression() error

func (*ExpressionVisitorBase) OnExitPropertyOrLabelsExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitPropertyOrLabelsExpression(e query.QueryPropertyOrLabelsExpression) error

func (*ExpressionVisitorBase) OnExitRelationshipsPattern added in v0.0.30

func (evb *ExpressionVisitorBase) OnExitRelationshipsPattern(q query.QueryRelationshipsPattern, id int) error

func (*ExpressionVisitorBase) OnExitStringListNullOperatorExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitStringListNullOperatorExpression(e query.QueryStringListNullOperatorExpression) error

func (*ExpressionVisitorBase) OnExitUnaryExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitUnaryExpression() error

func (*ExpressionVisitorBase) OnExitXorExpression added in v0.0.6

func (evb *ExpressionVisitorBase) OnExitXorExpression() error

func (*ExpressionVisitorBase) OnIntegerLiteral added in v0.0.6

func (evb *ExpressionVisitorBase) OnIntegerLiteral(value int64) error

func (*ExpressionVisitorBase) OnMultiplyDivideModuloOperator added in v0.0.6

func (evb *ExpressionVisitorBase) OnMultiplyDivideModuloOperator(operator query.MultiplyDivideModuloOperator) error

func (*ExpressionVisitorBase) OnNodePattern added in v0.0.32

func (evb *ExpressionVisitorBase) OnNodePattern(q query.QueryNodePattern) error

func (*ExpressionVisitorBase) OnRelationshipPattern added in v0.0.32

func (evb *ExpressionVisitorBase) OnRelationshipPattern(q query.QueryRelationshipPattern) error

func (*ExpressionVisitorBase) OnStringLiteral added in v0.0.6

func (evb *ExpressionVisitorBase) OnStringLiteral(value string) error

func (*ExpressionVisitorBase) OnStringOperator added in v0.0.6

func (evb *ExpressionVisitorBase) OnStringOperator(operator query.StringOperator) error

func (*ExpressionVisitorBase) OnVariable added in v0.0.6

func (evb *ExpressionVisitorBase) OnVariable(name string) error

func (*ExpressionVisitorBase) OnVariablePropertiesPath added in v0.0.6

func (evb *ExpressionVisitorBase) OnVariablePropertiesPath(propertiesPath []string) error

type FunctionInvocationContext added in v0.0.54

type FunctionInvocationContext struct {
	Distinct       bool
	FunctionName   string
	Expression     string
	VariableName   string
	VariableType   ExpressionType
	PropertiesPath []string
}

type Graph

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

Graph represent a Graph

func NewGraph

func NewGraph() *Graph

NewGraph create a graph

func (*Graph) AddAsset

func (g *Graph) AddAsset(assetType schema.AssetType, assetKey string) (AssetKey, error)

AddAsset add an asset to the graph

func (*Graph) AddRelation

func (g *Graph) AddRelation(from AssetKey, relationType schema.RelationKeyType, to AssetKey) Relation

AddRelation add a relation to the graph

func (*Graph) Assets

func (g *Graph) Assets() map[Asset]GraphEntryAction

Assets return the assets in the graph

func (*Graph) Clean added in v0.0.68

func (g *Graph) Clean()

func (*Graph) Copy

func (g *Graph) Copy() *Graph

Copy perform a deep copy of the graph

func (*Graph) Equal

func (g *Graph) Equal(other *Graph) bool

Equal return true if graphs are equal, otherwise return false

func (*Graph) ExtractSchema

func (g *Graph) ExtractSchema() schema.SchemaGraph

ExtractSchema extract the schema from the graph

func (*Graph) HasAsset

func (g *Graph) HasAsset(asset Asset) bool

HasAsset return true if the asset is in the graph, false otherwise.

func (*Graph) HasRelation

func (g *Graph) HasRelation(relation Relation) bool

HasRelation return true if the relation is in the graph, false otherwise.

func (*Graph) MarshalJSON

func (g *Graph) MarshalJSON() ([]byte, error)

MarshalJSON marshall the graph in JSON

func (*Graph) Relations

func (g *Graph) Relations() map[Relation]GraphEntryAction

Relations return the relations in the graph

func (*Graph) UnmarshalJSON

func (g *Graph) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshal a graph from JSON

type GraphBinder

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

GraphBinder represent a graph builder which bind assets and relations to graph schema provided by the source

func NewGraphBinder

func NewGraphBinder(graph *Graph) *GraphBinder

NewGraphBinder create an instance of graph binder

func (*GraphBinder) Bind

func (gb *GraphBinder) Bind(asset string, assetType schema.AssetType) error

Bind bind one asset to a type

func (*GraphBinder) Relate

func (gb *GraphBinder) Relate(from string, relationType schema.RelationType, to string) error

Relate relate one asset to another

type GraphDB

type GraphDB interface {
	Close() error

	InitializeSchema() error

	ReadGraph(ctx context.Context, sourceName string, encoder *GraphEncoder) error

	// Atomic operations on the graph
	InsertAssets(ctx context.Context, sourceName string, assets []Asset) error
	InsertRelations(ctx context.Context, sourceName string, relations []Relation) error
	RemoveAssets(ctx context.Context, sourceName string, assets []Asset) error
	RemoveRelations(ctx context.Context, sourceName string, relations []Relation) error

	GetAssetSources(ctx context.Context, ids []string) (map[string][]string, error)
	GetRelationSources(ctx context.Context, ids []string) (map[string][]string, error)

	FlushAll(ctx context.Context) error

	CountAssets(ctx context.Context) (int64, error)
	CountAssetsBySource(ctx context.Context) (map[string]int64, error)
	CountRelations(ctx context.Context) (int64, error)
	CountRelationsBySource(ctx context.Context) (map[string]int64, error)

	Query(ctx context.Context, query SQLTranslation) (*GraphQueryResult, error)

	// Collect some metrics about the database
	CollectMetrics(ctx context.Context) (map[string]int, error)
}

GraphDB an interface to a graph DB such as Arango or neo4j

type GraphDecoder added in v0.0.50

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

GraphDecoder represent a graph decoder

func NewGraphDecoder added in v0.0.50

func NewGraphDecoder(r io.Reader) *GraphDecoder

NewGraphDecoder create an instance of a graph encoder

func (*GraphDecoder) Decode added in v0.0.50

func (ge *GraphDecoder) Decode(graph *Graph) error

Decode decode a graph

type GraphEncoder added in v0.0.50

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

GraphEncoder represent a graph encoder

func NewGraphEncoder added in v0.0.50

func NewGraphEncoder(w io.Writer) *GraphEncoder

NewGraphEncoder create an instance of a graph encoder

func (*GraphEncoder) EncodeAsset added in v0.0.50

func (ge *GraphEncoder) EncodeAsset(asset Asset) error

EncodeAsset encode an asset

func (*GraphEncoder) EncodeRelation added in v0.0.50

func (ge *GraphEncoder) EncodeRelation(relation Relation) error

EncodeRelation encode a relation

type GraphEntryAction added in v0.0.68

type GraphEntryAction uint8
const (
	GraphEntryRemove GraphEntryAction = iota
	GraphEntryAdd
	GraphEntryNone
)

type GraphJSON

type GraphJSON struct {
	Assets    []Asset    `json:"assets"`
	Relations []Relation `json:"relations"`
}

GraphJSON is the json representation of a graph

type GraphQueryResult

type GraphQueryResult struct {
	Cursor      Cursor
	Projections []Projection
}

GraphQueryResult represent a result from the database with the projection model

type GraphUpdater

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

GraphUpdater represents the updater of graph

func NewGraphUpdater

func NewGraphUpdater(graphDB GraphDB, schemaPersistor schema.Persistor) *GraphUpdater

NewGraphUpdater create a new instance of graph updater

func (*GraphUpdater) InsertAssets added in v0.0.25

func (sl *GraphUpdater) InsertAssets(ctx context.Context, source string, assets []Asset) error

InsertAssets insert multiple assets in the graph of the data source

func (*GraphUpdater) InsertRelations added in v0.0.25

func (sl *GraphUpdater) InsertRelations(ctx context.Context, source string, relations []Relation) error

InsertRelations insert multiple relations in the graph of the data source

func (*GraphUpdater) RemoveAssets added in v0.0.25

func (sl *GraphUpdater) RemoveAssets(ctx context.Context, source string, assets []Asset) error

RemoveAssets remove multiple assets from the graph of the data source

func (*GraphUpdater) RemoveRelations added in v0.0.25

func (sl *GraphUpdater) RemoveRelations(ctx context.Context, source string, relations []Relation) error

RemoveRelations remove multiple relations from the graph of the data source

func (*GraphUpdater) UpdateSchema added in v0.0.17

func (sl *GraphUpdater) UpdateSchema(ctx context.Context, source string, sg schema.SchemaGraph) error

UpdateSchema update the schema for the source with the one provided in the request

type GraphUpdatesQueue added in v0.0.17

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

GraphUpdatesQueue represent a graph updates queue with

func NewGraphUpdatesQueue added in v0.0.17

func NewGraphUpdatesQueue(length int) *GraphUpdatesQueue

NewGraphUpdatesQueue create a new instance of updates queue

func (*GraphUpdatesQueue) Dequeue added in v0.0.17

func (guq *GraphUpdatesQueue) Dequeue() (*SourceSubGraphUpdates, error)

Dequeue an item from the queue

func (*GraphUpdatesQueue) Dispose added in v0.0.17

func (guq *GraphUpdatesQueue) Dispose()

Dispose will dispose of this queue. Any subsequent calls to Get or Put will return an error.

func (*GraphUpdatesQueue) Enqueue added in v0.0.17

func (guq *GraphUpdatesQueue) Enqueue(update SourceSubGraphUpdates) error

Enqueue an item into the queue

func (*GraphUpdatesQueue) IsFull added in v0.0.17

func (guq *GraphUpdatesQueue) IsFull() bool

IsFull check if the queue is full

type PatternContext added in v0.0.31

type PatternContext int

PatternContext the context of the pattern pushed

const (
	// MatchContext the node or relation is coming from a MATCH clause
	MatchContext PatternContext = iota
	// WhereContext the node or relation is coming from a WHERE clause
	WhereContext PatternContext = iota
)

type PatternParser added in v0.0.30

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

PatternParser is a parser of patterns

func NewPatternParser added in v0.0.30

func NewPatternParser(queryGraph *QueryGraph) *PatternParser

NewPatternParser create an instance of pattern parser

func (*PatternParser) ParsePatternElement added in v0.0.30

func (ep *PatternParser) ParsePatternElement(q *query.QueryPatternElement, scope Scope) error

ParsePatternElement parse a pattern element

func (*PatternParser) ParseRelationshipsPattern added in v0.0.30

func (ep *PatternParser) ParseRelationshipsPattern(q *query.QueryRelationshipsPattern, scope Scope) error

ParseRelationshipsPattern parse a relationships pattern

type ProcessedRelationTuple added in v0.0.71

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

ProcessedRelationTuple tuple for existing relationships

type Projection

type Projection struct {
	Alias          string
	ExpressionType ExpressionType
}

Projection represent the type and alias of one item in the RETURN statement (called a projection).

type ProjectionItem added in v0.0.54

type ProjectionItem struct {
	Variable string
	Function string
	Distinct bool
}

type ProjectionVisitor added in v0.0.6

type ProjectionVisitor struct {
	ExpressionVisitorBase

	Aggregation    bool
	TypeAndIndex   TypeAndIndex
	ExpressionType ExpressionType
	Projections    []ProjectionItem
	// contains filtered or unexported fields
}

func NewProjectionVisitor added in v0.0.30

func NewProjectionVisitor(queryGraph *QueryGraph) *ProjectionVisitor

func (*ProjectionVisitor) OnEnterFunctionInvocation added in v0.0.6

func (pv *ProjectionVisitor) OnEnterFunctionInvocation(name string, distinct bool) error

OnExitFunctionInvocation called when the ExitFunctionInvocation is parsed. Name is the name of the function.

func (*ProjectionVisitor) OnExitFunctionInvocation added in v0.0.54

func (pv *ProjectionVisitor) OnExitFunctionInvocation(name string, distinct bool) error

OnExitFunctionInvocation called when the ExitFunctionInvocation is parsed. Name is the name of the function.

func (*ProjectionVisitor) OnExitPropertyOrLabelsExpression added in v0.0.6

func (pv *ProjectionVisitor) OnExitPropertyOrLabelsExpression(e query.QueryPropertyOrLabelsExpression) error

func (*ProjectionVisitor) OnVariable added in v0.0.6

func (pv *ProjectionVisitor) OnVariable(name string) error

func (*ProjectionVisitor) OnVariablePropertiesPath added in v0.0.6

func (pv *ProjectionVisitor) OnVariablePropertiesPath(properties []string) error

func (*ProjectionVisitor) ParseExpression added in v0.0.6

func (pv *ProjectionVisitor) ParseExpression(q *query.QueryExpression) error

ParseExpression return whether the expression require aggregation

type Property added in v0.0.79

type Property struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

type Querier

type Querier struct {
	GraphDB GraphDB
	// contains filtered or unexported fields
}

func NewQuerier

func NewQuerier(db GraphDB, historizer history.Historizer) *Querier

NewQuerier create an instance of a querier

func (*Querier) Query

func (q *Querier) Query(ctx context.Context, queryString string) (*QuerierResult, error)

Query run a query against the graph DB.

type QuerierResult

type QuerierResult struct {
	Cursor      Cursor
	Projections []Projection
	Statistics  Statistics
}

type QueryGraph added in v0.0.6

type QueryGraph struct {
	Nodes     []QueryNode
	Relations []QueryRelation

	VariablesIndex map[string]TypeAndIndex
}

QueryGraph the representation of a query graph. This structure helps create the relations between nodes to facilitate SQL translation and projections

func NewQueryGraph added in v0.0.6

func NewQueryGraph() QueryGraph

NewQueryGraph create an instance of a query graph

func (*QueryGraph) Clone added in v0.0.71

func (qg *QueryGraph) Clone() *QueryGraph

func (*QueryGraph) FindVariable added in v0.0.6

func (qg *QueryGraph) FindVariable(name string) (TypeAndIndex, error)

FindVariable find a variable by its name

func (*QueryGraph) GetNodeByID added in v0.0.31

func (qg *QueryGraph) GetNodeByID(idx int) (*QueryNode, error)

GetNodeByID get a node by its id

func (*QueryGraph) GetNodesByRelation added in v0.0.71

func (qg *QueryGraph) GetNodesByRelation(relation *QueryRelation) (*QueryNode, *QueryNode, error)

GetNodesByRelation get nodes attached to a relation

func (*QueryGraph) GetRelationsByNodeId added in v0.0.71

func (qg *QueryGraph) GetRelationsByNodeId(nodeId int) []*QueryRelation

GetRelationsByNode get a node's relations.

func (*QueryGraph) PushNode added in v0.0.6

func (qg *QueryGraph) PushNode(q query.QueryNodePattern, scope Scope) (*QueryNode, int, error)

PushNode push a node into the registry

func (*QueryGraph) PushProperty added in v0.0.79

func (qg *QueryGraph) PushProperty(property string) error

func (*QueryGraph) PushRelation added in v0.0.6

func (qg *QueryGraph) PushRelation(q query.QueryRelationshipPattern, leftIdx, rightIdx int, scope Scope) (*QueryRelation, int, error)

PushRelation push a relation into the registry

type QueryLimitVisitor added in v0.0.6

type QueryLimitVisitor struct {
	ExpressionVisitorBase

	Limit int64
	// contains filtered or unexported fields
}

QueryLimitVisitor a visitor for the limit clause

func NewQueryLimitVisitor added in v0.0.30

func NewQueryLimitVisitor(queryGraph *QueryGraph) *QueryLimitVisitor

NewQueryLimitVisitor create an instance of query limit visitor

func (*QueryLimitVisitor) OnIntegerLiteral added in v0.0.6

func (qlv *QueryLimitVisitor) OnIntegerLiteral(value int64) error

OnIntegerLiteral handler called when an integer literal is visited

func (*QueryLimitVisitor) ParseExpression added in v0.0.6

func (qlv *QueryLimitVisitor) ParseExpression(q *query.QueryExpression) error

ParseExpression return whether the expression require aggregation

type QueryNode

type QueryNode struct {
	Labels []string
	// Constraint expressions
	Constraints AndOrExpression

	// The scopes this node belongs to (MATCH or WHERE)
	Scopes map[Scope]struct{}

	AssignedVariable string
	// contains filtered or unexported fields
}

QueryNode represent a node and its constraints

type QueryRelation

type QueryRelation struct {
	Labels []string
	// Constraint expressions
	Constraints AndOrExpression

	LeftIdx   int
	RightIdx  int
	Direction RelationDirection

	// The scopes this relations belongs to (MATCH or WHERE)
	Scopes map[Scope]struct{}

	AssignedVariable string
	// contains filtered or unexported fields
}

QueryRelation represent a relation and its constraints

type QuerySkipVisitor added in v0.0.6

type QuerySkipVisitor struct {
	ExpressionVisitorBase

	Skip int64
	// contains filtered or unexported fields
}

QuerySkipVisitor a visitor for the skip clause

func NewQuerySkipVisitor added in v0.0.30

func NewQuerySkipVisitor(queryGraph *QueryGraph) *QuerySkipVisitor

NewQuerySkipVisitor create an instance of the skip visitor

func (*QuerySkipVisitor) OnIntegerLiteral added in v0.0.6

func (qsv *QuerySkipVisitor) OnIntegerLiteral(value int64) error

OnIntegerLiteral handler called when an integer literal is visited

func (*QuerySkipVisitor) ParseExpression added in v0.0.6

func (qsv *QuerySkipVisitor) ParseExpression(q *query.QueryExpression) error

ParseExpression return whether the expression require aggregation

type QueryWhereVisitor added in v0.0.6

type QueryWhereVisitor struct {
	ExpressionVisitorBase

	Variables []string
	// contains filtered or unexported fields
}

QueryWhereVisitor a visitor for the where clauses

func NewQueryWhereVisitor added in v0.0.30

func NewQueryWhereVisitor(queryGraph *QueryGraph) *QueryWhereVisitor

NewQueryWhereVisitor create an instance of query where visitor.

func (*QueryWhereVisitor) OnVariable added in v0.0.6

func (qwv *QueryWhereVisitor) OnVariable(name string) error

OnVariable handler called when a variable is visited in the where clause

func (*QueryWhereVisitor) ParseExpression added in v0.0.6

func (qwv *QueryWhereVisitor) ParseExpression(q *query.QueryExpression) (string, error)

ParseExpression return whether the expression require aggregation

type Relation

type Relation RelationKey

Relation represent the relation with details

type RelationDirection added in v0.0.6

type RelationDirection int

RelationDirection the direction of a relation

const (
	// Left relation
	Left RelationDirection = iota
	// Right relation
	Right RelationDirection = iota
	// Either there is a relation but we don't know in which direction
	Either RelationDirection = iota
	// Both there is a relation in both directions
	Both RelationDirection = iota
)

type RelationKey

type RelationKey struct {
	Type schema.RelationKeyType `json:"type"`
	From AssetKey               `json:"from"`
	To   AssetKey               `json:"to"`
}

RelationKey a relation key of the KB

type RelationWithID

type RelationWithID struct {
	ID   string                 `json:"_id"`
	From string                 `json:"from_id"`
	To   string                 `json:"to_id"`
	Type schema.RelationKeyType `json:"type"`
}

RelationWithID represent a relation with an ID from the database

func (RelationWithID) String

func (r RelationWithID) String() string

type SQLExpressionVisitor added in v0.0.6

type SQLExpressionVisitor struct {
	ExpressionVisitorBase
	// contains filtered or unexported fields
}

SQLExpressionVisitor visitor used to build the SQL part from the Cypher expression.

func (*SQLExpressionVisitor) OnBooleanLiteral added in v0.0.6

func (sev *SQLExpressionVisitor) OnBooleanLiteral(value bool) error

func (*SQLExpressionVisitor) OnComparisonOperator added in v0.0.6

func (sev *SQLExpressionVisitor) OnComparisonOperator(operator query.ComparisonOperator) error

func (*SQLExpressionVisitor) OnDoubleLiteral added in v0.0.6

func (sev *SQLExpressionVisitor) OnDoubleLiteral(value float64) error

func (*SQLExpressionVisitor) OnExitAndExpression added in v0.0.6

func (sev *SQLExpressionVisitor) OnExitAndExpression() error

func (*SQLExpressionVisitor) OnExitComparisonExpression added in v0.0.6

func (sev *SQLExpressionVisitor) OnExitComparisonExpression() error

func (*SQLExpressionVisitor) OnExitExpression added in v0.0.6

func (sev *SQLExpressionVisitor) OnExitExpression() error

func (*SQLExpressionVisitor) OnExitFunctionInvocation added in v0.0.6

func (sev *SQLExpressionVisitor) OnExitFunctionInvocation(name string, distinct bool) error

OnExitFunctionInvocation build the SQL snippet calling the function

func (*SQLExpressionVisitor) OnExitNotExpression added in v0.0.6

func (sev *SQLExpressionVisitor) OnExitNotExpression(not bool) error

func (*SQLExpressionVisitor) OnExitOrExpression added in v0.0.6

func (sev *SQLExpressionVisitor) OnExitOrExpression() error

func (*SQLExpressionVisitor) OnExitParenthesizedExpression added in v0.0.6

func (sev *SQLExpressionVisitor) OnExitParenthesizedExpression() error

func (*SQLExpressionVisitor) OnExitPropertyOrLabelsExpression added in v0.0.6

func (sev *SQLExpressionVisitor) OnExitPropertyOrLabelsExpression(e query.QueryPropertyOrLabelsExpression) error

func (*SQLExpressionVisitor) OnExitRelationshipsPattern added in v0.0.32

func (sev *SQLExpressionVisitor) OnExitRelationshipsPattern(q query.QueryRelationshipsPattern, id int) error

OnExitRelationshipsPattern build the SQL query that will be put in the EXIST clause

func (*SQLExpressionVisitor) OnExitStringListNullOperatorExpression added in v0.0.6

func (sev *SQLExpressionVisitor) OnExitStringListNullOperatorExpression(e query.QueryStringListNullOperatorExpression) error

func (*SQLExpressionVisitor) OnIntegerLiteral added in v0.0.6

func (sev *SQLExpressionVisitor) OnIntegerLiteral(value int64) error

func (*SQLExpressionVisitor) OnStringLiteral added in v0.0.6

func (sev *SQLExpressionVisitor) OnStringLiteral(value string) error

func (*SQLExpressionVisitor) OnStringOperator added in v0.0.6

func (sev *SQLExpressionVisitor) OnStringOperator(operator query.StringOperator) error

func (*SQLExpressionVisitor) OnVariable added in v0.0.6

func (sev *SQLExpressionVisitor) OnVariable(name string) error

func (*SQLExpressionVisitor) OnVariablePropertiesPath added in v0.0.6

func (sev *SQLExpressionVisitor) OnVariablePropertiesPath(propertiesPath []string) error

type SQLFrom added in v0.0.54

type SQLFrom struct {
	// Alias can be empty.
	Alias string
	Value string
}

SQLFrom represent a from item with an optional alias name

type SQLFunction added in v0.0.54

type SQLFunction struct {
	Name     string
	Distinct bool
}

type SQLInnerStructure added in v0.0.54

type SQLInnerStructure struct {
	// If alias is empty there won't be any aliasing with AS keyword.
	Alias     string
	Structure SQLStructure
}

SQLInnerStructure represent a SQL inner structure with an optional alias name

type SQLJoin added in v0.0.71

type SQLJoin struct {
	Table string
	Alias string
	On    string
	Index string
}

type SQLProjection added in v0.0.54

type SQLProjection struct {
	// If alias is empty there won't be any aliasing with AS keyword.
	Alias    string
	Variable string
	// If function is not empty, variable should be provided and then the SQL expression should be <Function>(<Variable>) AS <Alias>
	Function *SQLFunction
}

SQLProjection represent a projection item with an optional alias name

type SQLQueryTranslator

type SQLQueryTranslator struct {
	QueryGraph QueryGraph
}

SQLQueryTranslator represent an SQL translator object converting cypher queries into SQL

func NewSQLQueryTranslator

func NewSQLQueryTranslator() *SQLQueryTranslator

NewSQLQueryTranslator create an instance of SQL query translator

func (*SQLQueryTranslator) Translate

func (sqt *SQLQueryTranslator) Translate(query *query.QueryCypher) (*SQLTranslation, error)

Translate a Cypher query into a SQL model

type SQLStructure added in v0.0.54

type SQLStructure struct {
	Distinct          bool
	Projections       []SQLProjection
	FromEntries       []SQLFrom
	FromStructures    []SQLInnerStructure
	WhereExpression   AndOrExpression
	HavingExpression  AndOrExpression
	FunctionedAliases map[string]struct{}
	JoinEntries       [][]SQLJoin
	GroupByIndices    []int
	Limit             int
	Offset            int
}

SQLStructure represent a SQL structure for building the query string

type SQLTranslation

type SQLTranslation struct {
	// Query is the SQL query built from the Cypher query
	Query string
	// ProjectionTypes helps the clients know how to serialize the results
	ProjectionTypes []Projection
}

SQLTranslation the resulting object of the translation

type Scope added in v0.0.31

type Scope struct {
	Context PatternContext
	ID      int
}

Scope represent the context of the pattern and the ID. This is useful to know wether the pattern comes from the MATCH clause or a WHERE clause.

type SourceSubGraphUpdates

type SourceSubGraphUpdates struct {
	Schema schema.SchemaGraph
	Source string
}

SourceSubGraphUpdates represents the updates to perform on a source subgraph

type Statistics

type Statistics struct {
	Parsing   time.Duration
	Execution time.Duration
}

type TypeAndIndex added in v0.0.6

type TypeAndIndex struct {
	Type  VariableType
	Index int
}

TypeAndIndex type and index of a variable from the cypher query

type VariableType added in v0.0.6

type VariableType int

VariableType represent the type of a variable in the cypher query.

const (
	// NodeType variable of type node
	NodeType VariableType = iota
	// RelationType variable of type relation
	RelationType VariableType = iota
	// PropertyType variable of type property (neither a node or a relation)
	PropertyType VariableType = iota
)

Jump to

Keyboard shortcuts

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