Documentation
¶
Overview ¶
Example 02_property_graph — build a labelled property graph (LPG) with an optional type schema, then run label- and property-indexed MATCH-style queries and read the typed properties back out.
This example is the property-graph counterpart to the scale benchmark in example 26: it models a realistic employee directory at a configurable scale, drives it through the graph/query engine's index-backed predicates, and reports the evidence that matters for an LPG — build throughput, index-backed query latency, live heap and bytes per node — while pinning the deterministic shape with a regression test.
Model ¶
(:Person {id, name, age, salary, active, dept}) // id is a stable "p<NNN>" key
(:Person:Manager {…}) // a fraction of persons are managers
(:Org {id, name, founded, revenue}) // id is a stable "o<NNN>" key
(:Person)-[:WORKS_AT]->(:Org) // every person works at one org
Each :Person carries five typed properties spanning the four scalar kinds: a string name, an int64 age, a float64 salary, a bool active flag, and a string dept (one of a fixed set of departments). A configurable fraction of persons additionally carry the :Manager label. Each :Org carries a string name, an int64 founded year, and a float64 revenue. All values are drawn from a seeded RNG, so fixing -seed fixes the data shape — and therefore every indexed match count and every read-back value — exactly.
Schema ¶
An optional schema.Schema is declared (the labels and the typed property keys) and installed as the graph's validator, so every property write is type-checked at the boundary: writing a value whose kind disagrees with its declaration is rejected before it lands. The schema is the optional half of the LPG contract this example demonstrates; disable it with -schema=false to see the same data built without validation.
Queries ¶
The label index (Roaring bitmaps over labels) and the per-property value index back four representative point lookups, each reported as a deterministic match count plus a volatile latency line:
MATCH (p:Person) -> count of persons
MATCH (p:Person:Manager) -> count of managers (label intersection)
MATCH (p:Person {dept:'Engineering'}) -> count by string property
MATCH (p:Person {active:true}) -> count by bool property
MATCH (m:Manager)-->(o:Org) -> orgs reachable one hop from a manager
For a fixed sample person the example then reads its five typed properties back out through lpg.Graph.GetNodeProperty, demonstrating typed property RETRIEVAL — the other half of the round trip.
Scale ¶
Run with no flags the example builds a small, deterministic default (2000 persons, 50 orgs) that the regression test pins and that builds in well under a second. Every dimension is a flag, so the same binary scales up to a size where the heap and latency figures become interesting:
go run ./examples/02_property_graph -persons 2000000 -orgs 5000 -seed 7
The deterministic data shape is reproducible for a fixed -seed; only the telemetry (lines prefixed with "# ") varies between runs and machines.