Skip to content

3.18 Asking the spine for a key — canonicalize

MATCH (b:LagoBooks {scope:'all'})-[:HAS_INVOICE]->(i:LagoInvoice)
MATCH (a:CustomerAccount {accountKey: canonicalize(i.customerUrl, 'CustomerAccount')})
RETURN a.name, sum(i.amountDueCents) / 100.0 AS owed

Means: “What does each customer owe?”, joining invoices to accounts by the customer’s website.

A spine’s normalize is the single definition of “the same account”. Normalising by hand — split(i.customerUrl, '//')[1] — strips the scheme and nothing else, so https://www.Acme.com/ joins nothing while the same company’s customer record, keyed through hub:, joins fine: the invoices just vanish. canonicalize applies the spine’s own rules, the same ones hub: uses, so the two cannot disagree. canonicalize(n) reads a node’s hub: property; canonicalization(v, 'Spine') says why a value is not a key (excluded for a freemail address, invalid for one with no domain). It reads nothing: it says what the key would be, and the MATCH decides whether that account exists. See §5.4.4.