Documentation
¶
Overview ¶
Example 22_cypher — the GoGraph Cypher engine, the module's flagship (100% openCypher TCK compliant at the execution level), driven over a realistic, seeded social graph.
It builds a labelled property graph that models a small social network and then exercises the engine with the four Cypher idioms this example teaches:
- a label scan with a property projection and ORDER BY (the oldest users, with a deterministic name tiebreak);
- a WHERE filter over a node property (users older than a threshold);
- a directed relationship pattern (the KNOWS friendships, plus a bound-relationship read of the since date property);
- a CREATE inside a write transaction, whose effect is verified by a follow-up read (the user count increments by exactly one).
Every value is read back from the result record and rendered in human-readable form — names, ages and dates, never raw node IDs.
Model ¶
(:USER {id, name, age, city}) // id is a 24-char hex string
(:USER)-[:KNOWS {since}]->(:USER) // knowsMin..knowsMax per user
KNOWS is a directed out-edge: every user is given a random out-degree in [knowsMin, knowsMax] to distinct other users (no self-loops, no duplicate targets). Each KNOWS carries exactly one mandatory date property, since, recording when the acquaintance began.
since is stored as an ISO-8601 (YYYY-MM-DD) string — the representation examples 25 and 26 use for Cypher-queryable dates — so the cypher.Engine reads it back as a non-null value and, because ISO-8601 sorts chronologically, ORDER BY and range predicates over since behave as dates. (lpg.TimeValue is not used: the Cypher reader maps it to null, whereas the tagged date string round-trips.) The dates are drawn from the seeded RNG, anchored to a fixed reference date rather than the wall clock, so they are reproducible for a given -seed.
Scale ¶
Run with no flags, the example builds a small, deterministic default — fifty users with three-to-six acquaintances each — so the run is instant and the deterministic facts are pinned by the regression test. Every dimension is a flag, so the same binary scales up to a size where the per-query latency and live-heap telemetry become observable:
go run ./examples/22_cypher -users 200000 -knows-max 30 -seed 7
The deterministic data shape is reproducible for a fixed -seed; only the telemetry (lines prefixed with "# ") varies between runs and machines.
Determinism of the CREATE ¶
The CREATE mutates the graph, so the example reads the :USER count immediately before and after the write and reports the delta as a fact (create.user_delta=1). Each run builds a fresh graph, so re-runs are independent and the delta is always exactly one.