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 exercises the engine across three families of Cypher work:
Reads — 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); and a directed relationship pattern (the KNOWS friendships, plus a bound-relationship read of the since date). Traversal — shortestPath and allShortestPaths over the undirected KNOWS relation between two seeded users, cross-checked against an independent in-Go oracle. The oracle mirrors the same KNOWS edges into an undirected graph/csr.CSR and searches it with search.BiBFS; a hand-written BFS over that CSR picks the farthest reachable user as the destination. If the engine and the oracle disagree on the path length that is a module bug, so the agreement is asserted as a fact (sp.len_matches_bibfs=1). Writes — the mutation surface via Engine.RunInTx, each effect verified by a follow-up read: a multi-pattern CREATE (a two-hop KNOWS path hung off an existing user); an UNWIND batch create driven by a list-of-maps parameter; MERGE with ON CREATE / ON MATCH run twice to prove idempotency (the second pass creates nothing and takes the ON MATCH branch); SET and REMOVE of a property; and DELETE of a relationship followed by DETACH DELETE of a node.
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 writes ¶
Each run builds a fresh graph, so the write battery's per-step deltas are independent of prior runs and reproducible for a fixed -seed: the multi-pattern CREATE adds two users and two KNOWS edges, the UNWIND adds -batch users, the first MERGE adds one user and the second adds none, and the DELETE / DETACH DELETE remove one relationship and one node (together with that node's remaining edge). The reported deltas and the final counts are therefore fixed facts. Because the writes add two KNOWS edges and later remove two, the final KNOWS count returns to the build total.