Documentation
¶
Overview ¶
Package semantic contains the semantic analysis required to have a semantically valid parser. It includes the data conversion required to turn tokens into valid BadWolf structures. It also provides the hooks implementations required for building an actionable execution plan.
Index ¶
- func ToLiteral(ce ConsumedElement) (*literal.Literal, error)
- func ToNode(ce ConsumedElement) (*node.Node, error)
- func ToPredicate(ce ConsumedElement) (*predicate.Predicate, error)
- type AlwaysReturn
- type ClauseHook
- func GroupByBindingsChecker() ClauseHook
- func HavingExpressionBuilder() ClauseHook
- func InitWorkingConstructClause() ClauseHook
- func InitWorkingConstructClauseHook() ClauseHook
- func NextWorkingConstructClause() ClauseHook
- func NextWorkingConstructClauseHook() ClauseHook
- func NextWorkingConstructPredicateObjectPair() ClauseHook
- func NextWorkingConstructPredicateObjectPairClauseHook() ClauseHook
- func OrderByBindingsChecker() ClauseHook
- func TypeBindingClauseHook(t StatementType) ClauseHook
- func VarBindingsGraphChecker() ClauseHook
- func WhereInitWorkingClauseHook() ClauseHook
- func WhereNextWorkingClauseHook() ClauseHook
- type ConstructClause
- func (c *ConstructClause) AddWorkingPredicateObjectPair()
- func (c *ConstructClause) IsEmpty() bool
- func (c *ConstructClause) PredicateObjectPairs() []*ConstructPredicateObjectPair
- func (c *ConstructClause) ResetWorkingPredicateObjectPair()
- func (c *ConstructClause) String() string
- func (c *ConstructClause) WorkingPredicateObjectPair() *ConstructPredicateObjectPair
- type ConstructPredicateObjectPair
- type ConsumedElement
- type ElementHook
- func CollectGlobalBounds() ElementHook
- func ConstructObjectHook() ElementHook
- func ConstructPredicateHook() ElementHook
- func ConstructSubjectHook() ElementHook
- func DataAccumulatorHook() ElementHook
- func GraphAccumulatorHook() ElementHook
- func GroupByBindings() ElementHook
- func HavingExpression() ElementHook
- func InputGraphAccumulatorHook() ElementHook
- func LimitCollection() ElementHook
- func OrderByBindings() ElementHook
- func OutputGraphAccumulatorHook() ElementHook
- func VarAccumulatorHook() ElementHook
- func WhereObjectClauseHook() ElementHook
- func WherePredicateClauseHook() ElementHook
- func WhereSubjectClauseHook() ElementHook
- type Evaluator
- type GraphClause
- type OP
- type Projection
- type Statement
- func (s *Statement) AddData(d *triple.Triple)
- func (s *Statement) AddGraph(g string)
- func (s *Statement) AddInputGraph(g string)
- func (s *Statement) AddOutputGraph(g string)
- func (s *Statement) AddWorkingConstructClause()
- func (s *Statement) AddWorkingGraphClause()
- func (s *Statement) AddWorkingProjection()
- func (s *Statement) BindType(st StatementType)
- func (s *Statement) Bindings() []string
- func (s *Statement) BindingsMap() map[string]int
- func (s *Statement) ConstructClauses() []*ConstructClause
- func (s *Statement) Data() []*triple.Triple
- func (s *Statement) GlobalLookupOptions() *storage.LookupOptions
- func (s *Statement) GraphNames() []string
- func (s *Statement) GraphPatternClauses() []*GraphClause
- func (s *Statement) Graphs() []storage.Graph
- func (s *Statement) GroupBy() []string
- func (s *Statement) GroupByBindings() []string
- func (s *Statement) HasHavingClause() bool
- func (s *Statement) HasLimit() bool
- func (s *Statement) HavingEvaluator() Evaluator
- func (s *Statement) HavingExpression() []ConsumedElement
- func (s *Statement) Init(ctx context.Context, st storage.Store) error
- func (s *Statement) InputBindings() []string
- func (s *Statement) InputGraphNames() []string
- func (s *Statement) InputGraphs() []storage.Graph
- func (s *Statement) IsLimitSet() bool
- func (s *Statement) Limit() int64
- func (s *Statement) OrderBy() table.SortConfig
- func (s *Statement) OrderByConfig() table.SortConfig
- func (s *Statement) OutputBindings() []string
- func (s *Statement) OutputGraphNames() []string
- func (s *Statement) OutputGraphs() []storage.Graph
- func (s *Statement) Projection() []*Projection
- func (s *Statement) Projections() []*Projection
- func (s *Statement) ResetProjection()
- func (s *Statement) ResetWorkingConstructClause()
- func (s *Statement) ResetWorkingGraphClause()
- func (s *Statement) SortedGraphPatternClauses() []*GraphClause
- func (s *Statement) Type() StatementType
- func (s *Statement) WorkingClause() *GraphClause
- func (s *Statement) WorkingConstructClause() *ConstructClause
- func (s *Statement) WorkingProjection() *Projection
- type StatementType
- type Symbol
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToLiteral ¶
func ToLiteral(ce ConsumedElement) (*literal.Literal, error)
ToLiteral converts the node found by the lexer and converts it into a BadWolf literal.
func ToNode ¶
func ToNode(ce ConsumedElement) (*node.Node, error)
ToNode converts the node found by the lexer and converts it into a BadWolf node.
func ToPredicate ¶
func ToPredicate(ce ConsumedElement) (*predicate.Predicate, error)
ToPredicate converts the node found by the lexer and converts it into a BadWolf predicate.
Types ¶
type AlwaysReturn ¶
type AlwaysReturn struct {
V bool
}
AlwaysReturn evaluator always return the provided boolean value.
type ClauseHook ¶
type ClauseHook func(*Statement, Symbol) (ClauseHook, error)
ClauseHook is a function hook for the parser that gets called on clause wide events.
func GroupByBindingsChecker ¶
func GroupByBindingsChecker() ClauseHook
GroupByBindingsChecker returns the singleton to check that the group by bindings are valid.
func HavingExpressionBuilder ¶
func HavingExpressionBuilder() ClauseHook
HavingExpressionBuilder returns the singleton to collect the tokens that form the having clause.
func InitWorkingConstructClause ¶ added in v0.8.0
func InitWorkingConstructClause() ClauseHook
InitWorkingConstructClause returns a clause hook to initialize a new working construct clause.
func InitWorkingConstructClauseHook ¶ added in v0.8.0
func InitWorkingConstructClauseHook() ClauseHook
InitWorkingConstructClauseHook returns the singleton for clause accumulation within the construct statement.
func NextWorkingConstructClause ¶ added in v0.8.0
func NextWorkingConstructClause() ClauseHook
NextWorkingConstructClause returns a clause hook to close the current working construct clause and start a new working construct clause.
func NextWorkingConstructClauseHook ¶ added in v0.8.0
func NextWorkingConstructClauseHook() ClauseHook
NextWorkingConstructClauseHook returns the singleton for clause accumulation within the construct statement.
func NextWorkingConstructPredicateObjectPair ¶ added in v0.8.0
func NextWorkingConstructPredicateObjectPair() ClauseHook
NextWorkingConstructPredicateObjectPair returns a clause hook to close the current predicate-object pair and start a new predicate-object pair within the working construct clause.
func NextWorkingConstructPredicateObjectPairClauseHook ¶ added in v0.8.0
func NextWorkingConstructPredicateObjectPairClauseHook() ClauseHook
NextWorkingConstructPredicateObjectPairClauseHook returns the singleton for adding the current predicate-object pair to the set of predicate-objects pairs within the working construct statement and initializing a new working predicate-object pair.
func OrderByBindingsChecker ¶
func OrderByBindingsChecker() ClauseHook
OrderByBindingsChecker returns the singleton to check that the group by bindings are valid.
func TypeBindingClauseHook ¶
func TypeBindingClauseHook(t StatementType) ClauseHook
TypeBindingClauseHook returns a ClauseHook that sets the binding type.
func VarBindingsGraphChecker ¶
func VarBindingsGraphChecker() ClauseHook
VarBindingsGraphChecker returns the singleton for checking a query statement for valid bindings in the select variables.
func WhereInitWorkingClauseHook ¶
func WhereInitWorkingClauseHook() ClauseHook
WhereInitWorkingClauseHook returns the singleton for graph accumulation.
func WhereNextWorkingClauseHook ¶
func WhereNextWorkingClauseHook() ClauseHook
WhereNextWorkingClauseHook returns the singleton for graph accumulation.
type ConstructClause ¶ added in v0.8.0
type ConstructClause struct {
S *node.Node
SBinding string
// contains filtered or unexported fields
}
ConstructClause represents a singular clause within a construct statement.
func (*ConstructClause) AddWorkingPredicateObjectPair ¶ added in v0.8.0
func (c *ConstructClause) AddWorkingPredicateObjectPair()
AddWorkingPredicateObjectPair adds the working predicate-object pair to the set of predicate-object pairs belonging to the construct clause.
func (*ConstructClause) IsEmpty ¶ added in v0.8.0
func (c *ConstructClause) IsEmpty() bool
IsEmpty will return true if there are no set values in the construct clause.
func (*ConstructClause) PredicateObjectPairs ¶ added in v0.8.0
func (c *ConstructClause) PredicateObjectPairs() []*ConstructPredicateObjectPair
PredicateObjectPairs returns the list of predicate-object pairs within the construct clause.
func (*ConstructClause) ResetWorkingPredicateObjectPair ¶ added in v0.8.0
func (c *ConstructClause) ResetWorkingPredicateObjectPair()
ResetWorkingPredicateObjectPair resets the working predicate-object pair in the construct clause.
func (*ConstructClause) String ¶ added in v0.8.0
func (c *ConstructClause) String() string
String returns a readable representation of a construct clause.
func (*ConstructClause) WorkingPredicateObjectPair ¶ added in v0.8.0
func (c *ConstructClause) WorkingPredicateObjectPair() *ConstructPredicateObjectPair
WorkingPredicateObjectPair returns the working predicate-object pair in the construct clause.
type ConstructPredicateObjectPair ¶ added in v0.8.0
type ConstructPredicateObjectPair struct {
P *predicate.Predicate
PBinding string
PID string
PAnchorBinding string
PTemporal bool
O *triple.Object
OBinding string
OID string
OAnchorBinding string
OTemporal bool
}
ConstructPredicateObjectPair represents a predicate-object pair within a CONSTRUCT clause.
func (*ConstructPredicateObjectPair) IsEmpty ¶ added in v0.8.0
func (c *ConstructPredicateObjectPair) IsEmpty() bool
IsEmpty will return true if there are no set values in the predicate-object pair.
func (*ConstructPredicateObjectPair) String ¶ added in v0.8.0
func (c *ConstructPredicateObjectPair) String() string
String returns a readable representation of a ConstructPredicateObjectPair.
type ConsumedElement ¶
type ConsumedElement struct {
// contains filtered or unexported fields
}
ConsumedElement groups the current element being processed by the parser.
func NewConsumedSymbol ¶
func NewConsumedSymbol(s Symbol) ConsumedElement
NewConsumedSymbol create a new consumed element that boxes a symbol.
func NewConsumedToken ¶
func NewConsumedToken(tkn *lexer.Token) ConsumedElement
NewConsumedToken create a new consumed element that boxes a token.
func (ConsumedElement) IsSymbol ¶
func (c ConsumedElement) IsSymbol() bool
IsSymbol returns true if the boxed element is a symbol; false otherwise.
func (ConsumedElement) Symbol ¶
func (c ConsumedElement) Symbol() Symbol
Symbol returns the boxed symbol.
func (ConsumedElement) Token ¶
func (c ConsumedElement) Token() *lexer.Token
Token returns the boxed token.
type ElementHook ¶
type ElementHook func(*Statement, ConsumedElement) (ElementHook, error)
ElementHook is a function hook for the parser that gets called after an Element is confused.
func CollectGlobalBounds ¶
func CollectGlobalBounds() ElementHook
CollectGlobalBounds returns the global temporary bounds hook.
func ConstructObjectHook ¶ added in v0.8.0
func ConstructObjectHook() ElementHook
ConstructObjectHook returns the singleton for populating the object in the current predicate-object pair in the working construct clause.
func ConstructPredicateHook ¶ added in v0.8.0
func ConstructPredicateHook() ElementHook
ConstructPredicateHook returns the singleton for populating the predicate in the current predicate-object pair in the working construct clause.
func ConstructSubjectHook ¶ added in v0.8.0
func ConstructSubjectHook() ElementHook
ConstructSubjectHook returns the singleton for populating the subject in the working construct clause.
func DataAccumulatorHook ¶
func DataAccumulatorHook() ElementHook
DataAccumulatorHook returns the singleton for data accumulation.
func GraphAccumulatorHook ¶
func GraphAccumulatorHook() ElementHook
GraphAccumulatorHook returns the singleton for graph accumulation.
func GroupByBindings ¶
func GroupByBindings() ElementHook
GroupByBindings returns the singleton for collecting all the group by bindings.
func HavingExpression ¶
func HavingExpression() ElementHook
HavingExpression returns the singleton to collect the tokens that form the having clause.
func InputGraphAccumulatorHook ¶ added in v0.8.0
func InputGraphAccumulatorHook() ElementHook
InputGraphAccumulatorHook returns the singleton for input graph accumulation.
func LimitCollection ¶
func LimitCollection() ElementHook
LimitCollection returns the limit collection hook.
func OrderByBindings ¶
func OrderByBindings() ElementHook
OrderByBindings returns the singleton for collecting all the group by bindings.
func OutputGraphAccumulatorHook ¶ added in v0.8.0
func OutputGraphAccumulatorHook() ElementHook
OutputGraphAccumulatorHook returns the singleton for output graph accumulation.
func VarAccumulatorHook ¶
func VarAccumulatorHook() ElementHook
VarAccumulatorHook returns the singleton for accumulating variable projections.
func WhereObjectClauseHook ¶
func WhereObjectClauseHook() ElementHook
WhereObjectClauseHook returns the singleton for working clause hooks that populates the object.
func WherePredicateClauseHook ¶
func WherePredicateClauseHook() ElementHook
WherePredicateClauseHook returns the singleton for working clause hooks that populates the predicate.
func WhereSubjectClauseHook ¶
func WhereSubjectClauseHook() ElementHook
WhereSubjectClauseHook returns the singleton for working clause hooks that populates the subject.
type Evaluator ¶
type Evaluator interface {
// Evaluate computes the boolean value of the expression given a certain
// results table row. It will return an
// error if it could not be evaluated for the provided table row.
Evaluate(r table.Row) (bool, error)
}
Evaluator interface computes the evaluation of a boolean expression.
func NewBinaryBooleanExpression ¶
NewBinaryBooleanExpression creates a new binary boolean evaluator.
func NewEvaluationExpression ¶
NewEvaluationExpression creates a new evaluator for two bindings in a row.
func NewEvaluator ¶
func NewEvaluator(ce []ConsumedElement) (Evaluator, error)
NewEvaluator construct an evaluator given a sequence of tokens. It will return a descriptive error if it could build it properly.
type GraphClause ¶
type GraphClause struct {
S *node.Node
SBinding string
SAlias string
STypeAlias string
SIDAlias string
P *predicate.Predicate
PID string
PBinding string
PAlias string
PIDAlias string
PAnchorBinding string
PAnchorAlias string
PLowerBound *time.Time
PUpperBound *time.Time
PLowerBoundAlias string
PUpperBoundAlias string
PTemporal bool
O *triple.Object
OBinding string
OAlias string
OID string
OTypeAlias string
OIDAlias string
OAnchorBinding string
OAnchorAlias string
OLowerBound *time.Time
OUpperBound *time.Time
OLowerBoundAlias string
OUpperBoundAlias string
OTemporal bool
}
GraphClause represents a clause of a graph pattern in a where clause.
func (*GraphClause) Bindings ¶
func (c *GraphClause) Bindings() []string
Bindings returns the list of unique bindings listed in the graph clause.
func (*GraphClause) BindingsMap ¶
func (c *GraphClause) BindingsMap() map[string]int
BindingsMap returns the binding map for the graph clause.
func (*GraphClause) IsEmpty ¶
func (c *GraphClause) IsEmpty() bool
IsEmpty will return true if the are no set values in the clause.
func (*GraphClause) String ¶ added in v0.7.0
func (c *GraphClause) String() string
String returns a readable representation of a graph clause.
type Projection ¶
type Projection struct {
Binding string
Alias string
OP lexer.TokenType // The information about what function to use.
Modifier lexer.TokenType // The modifier for the selected op.
}
Projection contains the information required to project the outcome of querying with GraphClauses. It also contains the information of what aggregation function should be used.
func (*Projection) IsEmpty ¶
func (p *Projection) IsEmpty() bool
IsEmpty checks if the given projection is empty.
func (*Projection) String ¶
func (p *Projection) String() string
String returns a readable form of the projection.
type Statement ¶
type Statement struct {
// contains filtered or unexported fields
}
Statement contains all the semantic information extract from the parsing
func (*Statement) AddInputGraph ¶ added in v0.8.0
AddInputGraph adds an input graph to a given statement.
func (*Statement) AddOutputGraph ¶ added in v0.8.0
AddOutputGraph adds an output graph to a given statement.
func (*Statement) AddWorkingConstructClause ¶ added in v0.8.0
func (s *Statement) AddWorkingConstructClause()
AddWorkingConstructClause adds the current working construct clause to the set of construct clauses that form the construct statement.
func (*Statement) AddWorkingGraphClause ¶ added in v0.5.0
func (s *Statement) AddWorkingGraphClause()
AddWorkingGraphClause adds the current working graph clause to the set of clauses that form the graph pattern.
func (*Statement) AddWorkingProjection ¶
func (s *Statement) AddWorkingProjection()
AddWorkingProjection adds the current projection variable to the set of projects that this statement.
func (*Statement) BindType ¶
func (s *Statement) BindType(st StatementType)
BindType sets the type of a statement.
func (*Statement) Bindings ¶
Bindings returns the list of bindings available on the graph clauses for he statement.
func (*Statement) BindingsMap ¶
BindingsMap returns the set of bindings available on the graph clauses for the statement.
func (*Statement) ConstructClauses ¶ added in v0.8.0
func (s *Statement) ConstructClauses() []*ConstructClause
ConstructClauses returns the list of construct clauses in the statement.
func (*Statement) GlobalLookupOptions ¶
func (s *Statement) GlobalLookupOptions() *storage.LookupOptions
GlobalLookupOptions returns the global lookup options available in the statement.
func (*Statement) GraphNames ¶ added in v0.7.0
GraphNames returns the list of graphs listed on the statement.
func (*Statement) GraphPatternClauses ¶
func (s *Statement) GraphPatternClauses() []*GraphClause
GraphPatternClauses returns the list of graph pattern clauses
func (*Statement) GroupBy ¶ added in v0.7.0
GroupBy returns the available group by binding in the statement.
func (*Statement) GroupByBindings ¶
GroupByBindings returns the bindings used on the group by statement.
func (*Statement) HasHavingClause ¶
HasHavingClause returns true if there is a having clause.
func (*Statement) HavingEvaluator ¶
HavingEvaluator returns the evaluator constructed for the provided having clause.
func (*Statement) HavingExpression ¶ added in v0.7.0
func (s *Statement) HavingExpression() []ConsumedElement
HavingExpression returns the avaible tokens in the haaving expression.
func (*Statement) InputBindings ¶
InputBindings returns the list of incoming bindings feed from a where clause.
func (*Statement) InputGraphNames ¶ added in v0.8.0
InputGraphNames returns the list of input graphs listed on the statement.
func (*Statement) InputGraphs ¶ added in v0.8.0
InputGraphs returns the list of input graphs listed on the statement.
func (*Statement) IsLimitSet ¶
IsLimitSet returns true if the limit is set.
func (*Statement) OrderBy ¶ added in v0.7.0
func (s *Statement) OrderBy() table.SortConfig
OrderBy returns the available order by binding in the statement.
func (*Statement) OrderByConfig ¶
func (s *Statement) OrderByConfig() table.SortConfig
OrderByConfig returns the sort configuration specified by the order by statement.
func (*Statement) OutputBindings ¶
OutputBindings returns the list of binding that a query will return.
func (*Statement) OutputGraphNames ¶ added in v0.8.0
OutputGraphNames returns the list of output graphs listed on the statement.
func (*Statement) OutputGraphs ¶ added in v0.8.0
OutputGraphs returns the list of output graphs listed on the statement.
func (*Statement) Projection ¶ added in v0.7.0
func (s *Statement) Projection() []*Projection
Projection returns the available projections in the statement.
func (*Statement) Projections ¶
func (s *Statement) Projections() []*Projection
Projections returns all the available projections.
func (*Statement) ResetProjection ¶
func (s *Statement) ResetProjection()
ResetProjection resets the current working variable projection.
func (*Statement) ResetWorkingConstructClause ¶ added in v0.8.0
func (s *Statement) ResetWorkingConstructClause()
ResetWorkingConstructClause resets the current working construct clause.
func (*Statement) ResetWorkingGraphClause ¶
func (s *Statement) ResetWorkingGraphClause()
ResetWorkingGraphClause resets the current working graph clause.
func (*Statement) SortedGraphPatternClauses ¶
func (s *Statement) SortedGraphPatternClauses() []*GraphClause
SortedGraphPatternClauses return the list of graph pattern clauses
func (*Statement) Type ¶
func (s *Statement) Type() StatementType
Type returns the type of the statement.
func (*Statement) WorkingClause ¶
func (s *Statement) WorkingClause() *GraphClause
WorkingClause returns the current working clause.
func (*Statement) WorkingConstructClause ¶ added in v0.8.0
func (s *Statement) WorkingConstructClause() *ConstructClause
WorkingConstructClause returns the current working construct clause.
func (*Statement) WorkingProjection ¶
func (s *Statement) WorkingProjection() *Projection
WorkingProjection returns the current working variable projection.
type StatementType ¶
type StatementType int8
StatementType describes the type of statement being represented.
const ( // Query statement. Query StatementType = iota // Insert statement. Insert // Delete statement. Delete // Create statement. Create // Drop statement. Drop // Construct statement. Construct )
func (StatementType) String ¶
func (t StatementType) String() string
String provides a readable version of the StatementType.