Documentation
¶
Overview ¶
Package procs defines the procedure registry for the Cypher executor.
A Registry stores ProcEntry values keyed by the fully-qualified procedure name ("namespace.name") and is consulted at plan-build time by [exec.ProcedureCallOp]. Built-in procedures (db.*) are registered via RegisterBuiltins; custom procedures may be added via [Register].
Circular-import avoidance ¶
This package must NOT import github.com/FlavioCFOliveira/GoGraph/cypher/exec. exec imports procs.
Concurrency ¶
Registry is safe for concurrent use.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrProcAlreadyExists = errors.New("procs: procedure already exists")
ErrProcAlreadyExists is returned by Registry.Register when a procedure with the same fully-qualified name is already registered.
var ErrProcNotFound = errors.New("procs: procedure not found")
ErrProcNotFound is returned by Registry.Lookup when no procedure matching the given namespace and name is registered.
Functions ¶
func CollectIndexRows ¶ added in v0.9.0
CollectIndexRows enumerates every user-visible index registered on mgr as a [][]expr.Value where each inner slice is [name, type]: the index name and its kind ("hash" or "btree"). Names are returned in deterministic (ascending) order so the row set is stable across calls.
It is the single source of index enumeration shared by db.indexes() and the SHOW INDEXES statement (#1922) — both project from the identical row set, so the two views can never diverge on which indexes exist or on their reported type. The internal numeric-companion btree (a "<label>_<prop>_btree_num" index a btree CREATE INDEX registers alongside the user-named string btree, #1652) is filtered out here, so neither view exposes it. A nil mgr yields nil.
CollectIndexRows is safe for concurrent use (it only issues concurrent-safe reads on mgr).
func RegisterBuiltins ¶
func RegisterBuiltins(reg *Registry, mgr *index.Manager, src BuiltinSources)
RegisterBuiltins registers all built-in db.* procedures into reg.
mgr is the index manager used by db.indexes(); it may be nil (the procedure returns an empty result).
src carries the enumeration closures backing db.constraints(), db.labels(), db.relationshipTypes() and db.propertyKeys(); see BuiltinSources. Each closure may be nil, in which case its procedure returns an empty set.
Types ¶
type BuiltinSources ¶ added in v0.5.0
type BuiltinSources struct {
// ListConstraints is invoked by db.constraints() to obtain the current
// constraint rows (each row is [name, type, label, property]).
ListConstraints func() [][]expr.Value
// Labels is invoked by db.labels() to obtain the distinct node labels
// currently attached to live nodes, one per returned name.
Labels func() []string
// RelationshipTypes is invoked by db.relationshipTypes() to obtain the
// distinct relationship types in use, one per returned name.
RelationshipTypes func() []string
// PropertyKeys is invoked by db.propertyKeys() to obtain the distinct
// property keys in use, one per returned name.
PropertyKeys func() []string
}
BuiltinSources bundles the data-source callbacks the built-in db.* procedures query at invocation time. It decouples the procs package from the concrete graph type: callers (typically the engine) supply pure closures that read live graph state, and procs never imports the graph layer.
Every field is optional. A nil closure makes its corresponding procedure return an empty result set, mirroring the nil-index-manager behaviour of db.indexes().
type NamedType ¶
type NamedType struct {
// Name is the column name exposed via YIELD.
Name string
// Kind is the expected expr.Kind of values in this column.
Kind expr.Kind
}
NamedType pairs an output column name with its expected value kind.
type ProcImpl ¶
ProcImpl is the runtime function for a procedure. It receives the context and the evaluated argument values and returns all result rows. Each row must have exactly len(Signature.Outputs) columns.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a thread-safe store of registered procedures keyed by their fully-qualified name ("ns1.ns2.name").
Registry is safe for concurrent use.
Example ¶
ExampleRegistry shows the full register → list → lookup → invoke cycle on a fresh registry. List returns signatures sorted by fully-qualified name, so the output is stable across runs.
package main
import (
"context"
"fmt"
"github.com/FlavioCFOliveira/GoGraph/cypher/expr"
"github.com/FlavioCFOliveira/GoGraph/cypher/procs"
)
func main() {
reg := procs.NewRegistry()
sig := procs.Signature{
Namespace: []string{"demo"},
Name: "echo",
Inputs: []expr.Kind{expr.KindString},
Outputs: []procs.NamedType{{Name: "value", Kind: expr.KindString}},
}
impl := func(_ context.Context, args []expr.Value) ([][]expr.Value, error) {
return [][]expr.Value{{args[0]}}, nil
}
if err := reg.Register(sig, impl); err != nil {
fmt.Println("register error:", err)
return
}
// List exposes every registered signature, sorted by "namespace.name".
for _, s := range reg.List() {
fmt.Printf("listed: %s.%s\n", s.Namespace[0], s.Name)
}
// Lookup retrieves the entry so the executor can invoke its implementation.
entry, err := reg.Lookup([]string{"demo"}, "echo")
if err != nil {
fmt.Println("lookup error:", err)
return
}
rows, err := entry.Impl(context.Background(), []expr.Value{expr.StringValue("hi")})
if err != nil {
fmt.Println("invoke error:", err)
return
}
fmt.Printf("invoke result: %s\n", string(rows[0][0].(expr.StringValue)))
}
Output: listed: demo.echo invoke result: hi
func (*Registry) List ¶
List returns all registered signatures in lexicographic order of their fully-qualified names.
func (*Registry) Lookup ¶
Lookup retrieves the ProcEntry for (namespace, name). It returns a wrapped ErrProcNotFound when no such procedure is registered.
Example (NotFound) ¶
ExampleRegistry_Lookup_notFound shows the not-found path: Lookup returns a wrapped ErrProcNotFound for an unknown procedure.
package main
import (
"errors"
"fmt"
"github.com/FlavioCFOliveira/GoGraph/cypher/procs"
)
func main() {
reg := procs.NewRegistry()
_, err := reg.Lookup([]string{"db"}, "missing")
fmt.Println("is ErrProcNotFound:", errors.Is(err, procs.ErrProcNotFound))
}
Output: is ErrProcNotFound: true
type Signature ¶
type Signature struct {
// Namespace is the optional namespace path (e.g. ["db"] for db.labels()).
Namespace []string
// Name is the bare procedure name.
Name string
// Inputs lists the expected kinds for each positional argument.
Inputs []expr.Kind
// InputNames lists the declared name of each positional input, parallel
// to Inputs. When populated (len == len(Inputs)) the engine supports the
// openCypher implicit-argument form: a `CALL ns.name` with no argument
// list binds each declared input from the query parameter whose name
// matches the corresponding entry here. Empty / nil leaves the implicit
// form unsupported for this procedure.
InputNames []string
// Outputs lists the named output columns produced by the procedure.
Outputs []NamedType
}
Signature describes the calling contract of a procedure.