Skip to content
Archee Docs

Query reference

The ARQL grammar, its meaning, ten common queries and the errors with their fixes.

A query is MATCH a pattern, optionally WHERE a condition, then RETURN columns. The shape follows Cypher.

Grammar

query  = MATCH part {, part} [WHERE expr] {OPTIONAL MATCH part {, part} [WHERE expr]}
         RETURN [ALL] item {, item} [ORDER BY expr [ASC|DESC] {, ...}] [LIMIT n] [USING CONFIDENCE >= x]
part   = node {edge node} | name(var, ...)
node   = "(" [var] [":" kind {"|" kind}] ")"  |  "(" "\"exact.id\"" ")"
edge   = "-[" [var] [":" rel {"|" rel}] ["*" n ".." h] "]" ("->" | "-")  |  "<-[" ... "]-"
expr   = a OR b | a AND b | NOT a | a = b | <> < <= > >= | a = b ± t | a GLOB "bearing.*"
         | a IN [x, y] | a IS [NOT] NULL | EXISTS { path [WHERE expr] } | count(*) min max sum avg abs least greatest
number = 12 | 0.5 mm | 30 deg      units: mm um m in deg rad
  • Statements end with ;. Keywords ignore case. Kinds, relations and attributes are lowercase and case-sensitive. Ids keep their own case (shaft.II).
  • *1..h finds nodes within h hops, with h at most 4.

Meaning

  • Rows are a set. Duplicates vanish. RETURN ALL keeps them. There is no DISTINCT.
  • Aggregates group by the other items: RETURN s.id, count(d) AS dims.
  • Two variables may bind one node. Add WHERE a.id < b.id to list each unordered pair once.
  • *1..2 finds nodes within two hops over the named relations, excluding the start. There are no path variables.
  • NOT EXISTS { ... } is negation. When the sheet was read in part, the result says unknown_coverage: true, and an absence proves nothing.
  • A missing attribute is unknown. The row is dropped and counted in skipped.
  • Units are checked. mm against deg is an error, and mm against in converts. a = b ± t means |a - b| <= t. Tolerances do not chain.
  • OPTIONAL MATCH keeps the row when its pattern finds nothing and binds the new variables to null.
  • USING CONFIDENCE >= 0.9 drops facts below 0.9.

Ten common queries

1  What sits on a shaft?
   MATCH (b:bearing)-[:coaxial]-(s:shaft) RETURN b.id, s.id
2  What touches shaft.II, longest contact first?
   MATCH (p)-[t:touches]-("shaft.II") RETURN p.id, t.measured ORDER BY t.measured DESC
3  How many parts does each housing hold?
   MATCH (h:housing)-[:contains]->(p) RETURN h.id, count(p) AS parts
4  Which faces are close but not touching?
   MATCH (a)-[g:gap]-(b) WHERE g.measured < 0.5 mm RETURN a.id, b.id, g.measured
5  Which notes point at bearings?
   MATCH (n)-[:annotates]->(p) WHERE p.id GLOB "bearing.*" RETURN n.id, p.id
6  How many dimensions does each shaft have?
   MATCH (d:dim)-[:dimensions]->(p:shaft) RETURN p.id, count(d) AS dims
7  What does changing shaft.II affect, within two hops?
   MATCH ("shaft.II")-[:touches|coaxial*1..2]-(n) RETURN n.id
8  Which shafts have no dimension?
   MATCH (p:shaft) WHERE NOT EXISTS { (:dim)-[:dimensions]->(p) } RETURN p.id
9  Which dimensions say something other than they measure?
   MATCH (d:dim)-[:dimensions]->(p) WHERE NOT d.text_value = d.measured_value ± 0.5 mm RETURN d.id, p.id
10 How many nodes of each kind?
   MATCH (p) RETURN p.kind, count(*) AS n ORDER BY n DESC

More shapes:

  • A triangle: MATCH (a)-[:touches]-(b), (b)-[:touches]-(c), (c)-[:touches]-(a) WHERE a.id < b.id AND b.id < c.id RETURN a.id, b.id, c.id.
  • Alternation: -[:coaxial|touches]-.
  • Membership: WHERE p.kind IN ["bolt", "nut"].

Result

A result has columns, rows, skipped, truncated and unknown_coverage. Each row carries its values, evidence (the fact ids it used, at most 20) and confidence (the weakest fact in an AND, the strongest of alternatives). A length shows with its unit.

Errors

A bad query fails with code, line, column, expected (the tokens or names valid there), did_you_mean and, when the fix is unambiguous, hint with the corrected query. An unknown kind lists the known kinds, and an unknown attribute lists the node’s attributes.

MistakeFix
RETURN DISTINCT xDrop DISTINCT; rows are already a set
MATCH p = (a)-[*]-(b)Use *1..h with h at most 4
WHERE g.measured < 0.5Write the unit: 0.5 mm
WHERE a.measured ... on a nodemeasured belongs to the edge variable
id shaft.iiIds keep their case; run MATCH (p:shaft) RETURN p.id first
MINUS, SUBTRACTWrite EXCEPT