query

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AndPredicate

type AndPredicate struct {
	Left  Predicate
	Right Predicate
}

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

type AttributePathAST struct {
	Element string `@( "node" | "edge" )`
	Attr    string `Dot @Ident`
}

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

func (*BindExpr) Apply

func (e *BindExpr) Apply(ctx *QueryContext, input Value) (Value, error)

Apply executes the subpipeline, stores result, returns input unchanged

type BindingAST

type BindingAST struct {
	Pipeline *QueryAST `LParen @@ RParen`
	Name     string    `"as" @Ident`
}

BindingAST: "(" pipeline ")" "as" NAME

type Boolean

type Boolean bool

Boolean captures true/false literals

func (*Boolean) Capture

func (b *Boolean) Capture(values []string) error

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 FromAST

type FromAST struct {
	Wildcard bool   `"from" ( @Star`
	Name     string `| @Ident )`
}

FromAST: "from" ("*" | NAME)

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

func (*FromExpr) Apply

func (e *FromExpr) Apply(ctx *QueryContext, input Value) (Value, error)

Apply returns the selected graph

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 GraphValue

type GraphValue struct {
	Graph *gsl.Graph
}

GraphValue wraps a Graph as a Value

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

func (*MakeExpr) Apply

func (e *MakeExpr) Apply(ctx *QueryContext, input Value) (Value, error)

Apply assigns attributes to matching nodes or edges

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

func ParsePredicate(input string) (Predicate, error)

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

func (*Query) Execute

func (q *Query) Execute(ctx *QueryContext) (Value, error)

Execute runs the query pipeline, starting with InputGraph from ctx

type QueryAST

type QueryAST struct {
	Expressions []*ExpressionAST `( @@ ( Pipe @@ )* )?`
}

QueryAST is the top-level grammar rule

type QueryContext

type QueryContext struct {
	InputGraph  *gsl.Graph
	NamedGraphs map[string]*gsl.Graph
}

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

type SetMembershipPredicate struct {
	Target string // "node" or "edge"
	SetID  string // set name
}

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

type Value

type Value interface{}

Value represents a value flowing through the query pipeline. In v1, this is always a graph. Future versions may support NodeSet, EdgeSet, Scalar.

type ValueAST

type ValueAST struct {
	String *string  `  @String`
	Bool   *Boolean `| @( "true" | "false" )`
	Number *string  `| @Number`
	Ident  *string  `| @Ident`
}

ValueAST: string | bool | number | bare ident

Jump to

Keyboard shortcuts

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