Documentation
¶
Overview ¶
Example 19_pattern_query — the fluent graph/query pattern API at scale.
It builds a labelled property graph that models a software package dependency network, freezes it into an immutable CSR snapshot, and then drives a battery of MATCH-style pattern queries through the fluent github.com/FlavioCFOliveira/GoGraph/graph/query API — the same three capabilities the original toy demonstrated, now exercised at a scale where the engine's behaviour is observable:
- label predicates, intersected: (:Package) and (:Package:Deprecated);
- a label predicate combined with a property-equality predicate: (:Package) WHERE p.ecosystem = 'go' and (:Package {license:'MIT'});
- a one-hop directed expansion: (:Deprecated)-->(b), the direct dependencies of every deprecated package.
For a handful of matched packages the example reads the matched properties back out (downloads, ecosystem, license) with a deterministic order so the read-back values are reproducible.
Model ¶
(:Package {id, name, ecosystem, license, downloads})
(:Package:Deprecated {...}) // a deterministic subset
(:Package)-[DEPENDS_ON]->(:Package) // a direct dependency
id is a 16-char hex string; downloads is an int64; ecosystem and license are drawn from small fixed categorical sets. A package may additionally carry the Deprecated label. The fluent query API matches on node labels and node properties and expands one hop along the directed DEPENDS_ON edges, so the model carries exactly the typed fields and the directed topology those three query shapes exercise.
Topology ¶
The dependency graph is generated by Price's model — preferential attachment on a topological order. Nodes are created in index order; every edge runs from a higher index to a lower one (i -> j with j < i), so the graph is a DAG by construction (no dependency cycles). Each new package picks outDegree dependencies, choosing each target with probability proportional to its current in-degree plus one, which reproduces the heavy-tailed in-degree of a real ecosystem: a few foundational libraries are depended on by very many packages while most packages are depended on by few. Out-degree (a package's own direct dependency count) is a small fixed range, faithful to real ecosystems where the heavy tail lives on in-degree, not out-degree. The selection is driven entirely by a single seeded RNG, so fixing -seed fixes the shape exactly.
Scale ¶
Run with no flags, the example builds a small, deterministic default (a few thousand packages) whose fact lines a regression test pins. Every dimension is a flag, so the same binary scales up to a size where per-query latency and live-heap footprint become interesting:
go run ./examples/19_pattern_query -nodes 1000000 -seed 7
The deterministic data shape and the fact lines are reproducible for a fixed -seed; only the telemetry (lines prefixed with "# ") varies between runs and machines.
Why in-memory ¶
The example targets the read-query API and its latency / live-heap footprint, so it builds the graph in memory through the property-graph API and queries it through the in-memory CSR snapshot. It does not exercise the WAL/recovery stack; the persistence path is demonstrated by examples 04, 17, 24 and 25.