Documentation
¶
Index ¶
- type AndPredicate
- type AttrPredicateAST
- type AttributeEqualsPredicate
- type AttributeExistsPredicate
- type AttributeNotEqualsPredicate
- type AttributeNotExistsPredicate
- type AttributePathAST
- type BindExpr
- type BindingAST
- type Boolean
- type CollapseAST
- type CollapseExpr
- type EdgeExistsPredicate
- type ExistsPredicate
- type Expression
- type ExpressionAST
- type FromAST
- type FromExpr
- type GraphAlgebraAST
- type GraphAlgebraExpr
- type GraphValue
- type IdentityExpr
- type MakeAST
- type MakeExpr
- type NodeExistsPredicate
- type NotPredicate
- type Predicate
- type PredicateAST
- type PredicateTermAST
- type Query
- type QueryAST
- type QueryContext
- type QueryParser
- type RemoveAST
- type RemoveAttributeExpr
- type RemoveEdgeExpr
- type RemoveOrphansExpr
- type SetMembershipPredicate
- type SetNotMembershipPredicate
- type SetPredicateAST
- type SubgraphAST
- type SubgraphExpr
- type TraversalConfig
- type TraverseAST
- type Value
- type ValueAST
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AndPredicate ¶
AndPredicate combines predicates with AND (both must be true)
func (*AndPredicate) EvaluateEdge ¶
func (p *AndPredicate) EvaluateEdge(edge *gsl.Edge) bool
func (*AndPredicate) EvaluateNode ¶
func (p *AndPredicate) EvaluateNode(node *gsl.Node) bool
func (*AndPredicate) TargetType ¶
func (p *AndPredicate) TargetType() string
type AttrPredicateAST ¶
type AttrPredicateAST struct {
Path *AttributePathAST `@@`
Operator string `( @( Operator | Assign )`
Value *ValueAST ` @@`
Exists bool `| @"exists"`
NotExists bool `| "not" @"exists" )`
}
AttrPredicateAST: path (op value | "exists" | "not" "exists")
type AttributeEqualsPredicate ¶
type AttributeEqualsPredicate struct {
Target string // "node" or "edge"
Name string // attribute name
Value interface{} // expected value
}
AttributeEqualsPredicate matches nodes/edges with attribute = value
func (*AttributeEqualsPredicate) EvaluateEdge ¶
func (p *AttributeEqualsPredicate) EvaluateEdge(edge *gsl.Edge) bool
func (*AttributeEqualsPredicate) EvaluateNode ¶
func (p *AttributeEqualsPredicate) EvaluateNode(node *gsl.Node) bool
func (*AttributeEqualsPredicate) TargetType ¶
func (p *AttributeEqualsPredicate) TargetType() string
type AttributeExistsPredicate ¶
type AttributeExistsPredicate struct {
Target string // "node" or "edge"
Name string // attribute name
}
AttributeExistsPredicate matches nodes/edges that have a specific attribute
func (*AttributeExistsPredicate) EvaluateEdge ¶
func (p *AttributeExistsPredicate) EvaluateEdge(edge *gsl.Edge) bool
func (*AttributeExistsPredicate) EvaluateNode ¶
func (p *AttributeExistsPredicate) EvaluateNode(node *gsl.Node) bool
func (*AttributeExistsPredicate) TargetType ¶
func (p *AttributeExistsPredicate) TargetType() string
type AttributeNotEqualsPredicate ¶
type AttributeNotEqualsPredicate struct {
Target string // "node" or "edge"
Name string // attribute name
Value interface{} // value to compare against
}
AttributeNotEqualsPredicate matches nodes/edges with attribute != value
func (*AttributeNotEqualsPredicate) EvaluateEdge ¶
func (p *AttributeNotEqualsPredicate) EvaluateEdge(edge *gsl.Edge) bool
func (*AttributeNotEqualsPredicate) EvaluateNode ¶
func (p *AttributeNotEqualsPredicate) EvaluateNode(node *gsl.Node) bool
func (*AttributeNotEqualsPredicate) TargetType ¶
func (p *AttributeNotEqualsPredicate) TargetType() string
type AttributeNotExistsPredicate ¶
type AttributeNotExistsPredicate struct {
Target string // "node" or "edge"
Name string // attribute name
}
AttributeNotExistsPredicate matches nodes/edges that do NOT have a specific attribute
func (*AttributeNotExistsPredicate) EvaluateEdge ¶
func (p *AttributeNotExistsPredicate) EvaluateEdge(edge *gsl.Edge) bool
func (*AttributeNotExistsPredicate) EvaluateNode ¶
func (p *AttributeNotExistsPredicate) EvaluateNode(node *gsl.Node) bool
func (*AttributeNotExistsPredicate) TargetType ¶
func (p *AttributeNotExistsPredicate) TargetType() string
type AttributePathAST ¶
AttributePathAST: ("node"|"edge") "." ident
type BindExpr ¶
type BindExpr struct {
Pipeline *Query // Subpipeline to evaluate
Name string // Name to bind result to
}
BindExpr binds a subpipeline result to a named graph Execution: evaluate subpipeline, store result, return input unchanged
type BindingAST ¶
BindingAST: "(" pipeline ")" "as" NAME
type CollapseAST ¶
type CollapseAST struct {
NodeID string `"collapse" "into" @Ident`
Predicate *PredicateAST `"where" @@`
}
CollapseAST: "collapse" "into" id "where" predicate
type CollapseExpr ¶
type CollapseExpr struct {
NodeID string // target node ID for collapsed nodes
Pred Predicate // predicate to select nodes to collapse
}
CollapseExpr merges multiple nodes matching a predicate into a single node Edge rewriting and attribute merging follows the spec
func (*CollapseExpr) Apply ¶
func (e *CollapseExpr) Apply(ctx *QueryContext, input Value) (Value, error)
Apply merges nodes matching the predicate into a single node
type EdgeExistsPredicate ¶
type EdgeExistsPredicate struct{}
EdgeExistsPredicate matches all edges
func (*EdgeExistsPredicate) EvaluateEdge ¶
func (p *EdgeExistsPredicate) EvaluateEdge(edge *gsl.Edge) bool
func (*EdgeExistsPredicate) EvaluateNode ¶
func (p *EdgeExistsPredicate) EvaluateNode(node *gsl.Node) bool
func (*EdgeExistsPredicate) TargetType ¶
func (p *EdgeExistsPredicate) TargetType() string
type ExistsPredicate ¶
type ExistsPredicate struct{}
ExistsPredicate matches nodes/edges that exist (always true)
func (*ExistsPredicate) EvaluateEdge ¶
func (p *ExistsPredicate) EvaluateEdge(edge *gsl.Edge) bool
func (*ExistsPredicate) EvaluateNode ¶
func (p *ExistsPredicate) EvaluateNode(node *gsl.Node) bool
func (*ExistsPredicate) TargetType ¶
func (p *ExistsPredicate) TargetType() string
type Expression ¶
type Expression interface {
Apply(ctx *QueryContext, input Value) (Value, error)
}
Expression is implemented by all query expressions. Each expression transforms an input value into an output value.
type ExpressionAST ¶
type ExpressionAST struct {
Binding *BindingAST ` @@`
Subgraph *SubgraphAST `| @@`
Make *MakeAST `| @@`
Remove *RemoveAST `| @@`
Collapse *CollapseAST `| @@`
From *FromAST `| @@`
GraphAlgebra *GraphAlgebraAST `| @@`
}
ExpressionAST is a union of all expression types Order matters: keywords must be tried before graph algebra
type FromExpr ¶
type FromExpr struct {
IsWildcard bool // true if "*", false if named graph
Name string // graph name (empty if wildcard)
}
FromExpr selects a graph from context
type GraphAlgebraAST ¶
type GraphAlgebraAST struct {
Left string `@( Star | Ident )`
Operator string `@AlgebraOp`
Right string `@( Star | Ident )`
}
GraphAlgebraAST: REF OP REF
type GraphAlgebraExpr ¶
type GraphAlgebraExpr struct {
LeftRef string // graph name (or "*" for input)
RightRef string // graph name (or "*" for input)
Operator string // "+", "&", "-", "^"
}
GraphAlgebraExpr combines two named graphs using an operator Operators: +, &, -, ^
func (*GraphAlgebraExpr) Apply ¶
func (e *GraphAlgebraExpr) Apply(ctx *QueryContext, input Value) (Value, error)
Apply combines two graphs according to the operator
type IdentityExpr ¶
type IdentityExpr struct{}
IdentityExpr returns the input unchanged
func (*IdentityExpr) Apply ¶
func (e *IdentityExpr) Apply(ctx *QueryContext, input Value) (Value, error)
type MakeAST ¶
type MakeAST struct {
Path *AttributePathAST `"make" @@`
Value *ValueAST `Assign @@`
Predicate *PredicateAST `"where" @@`
}
MakeAST: "make" attr_path "=" value "where" predicate
type MakeExpr ¶
type MakeExpr struct {
Target string // "node" or "edge"
Attr string // attribute name
Value interface{} // value to assign
Pred Predicate // predicate to select targets
}
MakeExpr assigns or overwrites an attribute on nodes or edges matching a predicate
type NodeExistsPredicate ¶
type NodeExistsPredicate struct{}
NodeExistsPredicate matches all nodes (syntactic sugar for exists)
func (*NodeExistsPredicate) EvaluateEdge ¶
func (p *NodeExistsPredicate) EvaluateEdge(edge *gsl.Edge) bool
func (*NodeExistsPredicate) EvaluateNode ¶
func (p *NodeExistsPredicate) EvaluateNode(node *gsl.Node) bool
func (*NodeExistsPredicate) TargetType ¶
func (p *NodeExistsPredicate) TargetType() string
type NotPredicate ¶
type NotPredicate struct {
Inner Predicate
}
NotPredicate inverts a predicate
func (*NotPredicate) EvaluateEdge ¶
func (p *NotPredicate) EvaluateEdge(edge *gsl.Edge) bool
func (*NotPredicate) EvaluateNode ¶
func (p *NotPredicate) EvaluateNode(node *gsl.Node) bool
func (*NotPredicate) TargetType ¶
func (p *NotPredicate) TargetType() string
type Predicate ¶
type Predicate interface {
// EvaluateNode returns true if node matches predicate
EvaluateNode(node *gsl.Node) bool
// EvaluateEdge returns true if edge matches predicate
EvaluateEdge(edge *gsl.Edge) bool
// TargetType returns "node", "edge", or "" (error if both)
TargetType() string
}
Predicate evaluates conditions on nodes and edges An expression can target either nodes or edges, not both (mixed error in SPEC)
func ParsePredicate ¶
ParsePredicate parses a predicate string This is kept for backward compatibility with tests
type PredicateAST ¶
type PredicateAST struct {
Terms []*PredicateTermAST `@@ ( "AND" @@ )*`
}
PredicateAST: term { "AND" term }
type PredicateTermAST ¶
type PredicateTermAST struct {
Exists bool ` @"exists"`
BareSetName string `| "in" @Ident`
BareNotSetName string `| "not" "in" @Ident`
BareNot *PredicateAST `| "not" @@`
SetPredicate *SetPredicateAST `| @@`
AttrPredicate *AttrPredicateAST `| @@`
}
PredicateTermAST: union of predicate forms
type Query ¶
type Query struct {
Expressions []Expression
}
Query represents a pipeline of expressions
type QueryAST ¶
type QueryAST struct {
Expressions []*ExpressionAST `( @@ ( Pipe @@ )* )?`
}
QueryAST is the top-level grammar rule
type QueryContext ¶
QueryContext holds the state for query execution
type QueryParser ¶
type QueryParser struct {
// contains filtered or unexported fields
}
QueryParser parses a query string into a Query AST
func NewQueryParser ¶
func NewQueryParser(input string) *QueryParser
NewQueryParser creates a new parser for the input string
func (*QueryParser) Parse ¶
func (p *QueryParser) Parse() (*Query, error)
Parse parses the input string and returns a Query
type RemoveAST ¶
type RemoveAST struct {
Orphans bool ` "remove" ( @"orphans"`
EdgePredicate *PredicateAST `| "edge" "where" @@`
AttrPath *AttributePathAST `| @@`
AttrPredicate *PredicateAST ` "where" @@ )`
}
RemoveAST: union of remove forms
type RemoveAttributeExpr ¶
type RemoveAttributeExpr struct {
Target string // "node" or "edge"
Attr string // attribute name to remove
Pred Predicate // predicate to select targets
}
RemoveAttributeExpr removes an attribute from nodes or edges matching a predicate
func (*RemoveAttributeExpr) Apply ¶
func (e *RemoveAttributeExpr) Apply(ctx *QueryContext, input Value) (Value, error)
Apply removes attributes from matching nodes or edges
type RemoveEdgeExpr ¶
type RemoveEdgeExpr struct {
Pred Predicate
}
RemoveEdgeExpr removes edges matching a predicate Nodes remain in the graph
func (*RemoveEdgeExpr) Apply ¶
func (e *RemoveEdgeExpr) Apply(ctx *QueryContext, input Value) (Value, error)
Apply removes edges matching the predicate
type RemoveOrphansExpr ¶
type RemoveOrphansExpr struct{}
RemoveOrphansExpr removes nodes with no incident edges A self-loop counts as an incident edge
func (*RemoveOrphansExpr) Apply ¶
func (e *RemoveOrphansExpr) Apply(ctx *QueryContext, input Value) (Value, error)
Apply removes isolated nodes
type SetMembershipPredicate ¶
SetMembershipPredicate matches nodes/edges in a set
func (*SetMembershipPredicate) EvaluateEdge ¶
func (p *SetMembershipPredicate) EvaluateEdge(edge *gsl.Edge) bool
func (*SetMembershipPredicate) EvaluateNode ¶
func (p *SetMembershipPredicate) EvaluateNode(node *gsl.Node) bool
func (*SetMembershipPredicate) TargetType ¶
func (p *SetMembershipPredicate) TargetType() string
type SetNotMembershipPredicate ¶
type SetNotMembershipPredicate struct {
Target string // "node" or "edge"
SetID string // set name
}
SetNotMembershipPredicate matches nodes/edges NOT in a set
func (*SetNotMembershipPredicate) EvaluateEdge ¶
func (p *SetNotMembershipPredicate) EvaluateEdge(edge *gsl.Edge) bool
func (*SetNotMembershipPredicate) EvaluateNode ¶
func (p *SetNotMembershipPredicate) EvaluateNode(node *gsl.Node) bool
func (*SetNotMembershipPredicate) TargetType ¶
func (p *SetNotMembershipPredicate) TargetType() string
type SetPredicateAST ¶
type SetPredicateAST struct {
Element string `@( "node" | "edge" )`
Not bool `@"not"?`
SetName string `"in" At @Ident`
}
SetPredicateAST: ("node"|"edge") ["not"] "in" "@" ident
type SubgraphAST ¶
type SubgraphAST struct {
Predicate *PredicateAST `"subgraph" @@`
Traverse *TraverseAST `( @@ )?`
}
SubgraphAST: "subgraph" predicate ["traverse" direction depth]
type SubgraphExpr ¶
type SubgraphExpr struct {
Pred Predicate // Predicate to match nodes or edges
Traversal *TraversalConfig // nil if no traversal
}
SubgraphExpr extracts a subgraph matching a predicate, with optional traversal Traversal expands the subgraph structurally (not predicate-based)
func (*SubgraphExpr) Apply ¶
func (e *SubgraphExpr) Apply(ctx *QueryContext, input Value) (Value, error)
Apply filters graph to subgraph matching predicate, then optionally traverses
type TraversalConfig ¶
type TraversalConfig struct {
Direction string // "in", "out", or "both"
Depth int // number of hops; 0 means no traversal
}
TraversalConfig specifies traversal direction and depth
type TraverseAST ¶
type TraverseAST struct {
Direction string `"traverse" @( "in" | "out" | "both" )`
Depth string `@( "all" | Number )`
}
TraverseAST: "traverse" direction depth