Language briefs / CGQL & XQuery

From FLWOR
to graph paths.

If you know XQuery, you already know the rhythm: iterate, bind, filter, order and return. Here is how that carries into CGQL.

01

One question, two expressions.

Find the accounts in one case and return their handles alphabetically. For XQuery 3.1, $accounts is a supplied sequence of maps with string-valued handle and case entries. For CGQL, accounts is a JSON document collection.

XQuery 3.1
for $a in $accounts
where $a?case eq "CS-0412"
order by $a?handle
return $a?handle
CGQL
FOR a IN accounts
  FILTER a.case == "CS-0412"
  SORT a.handle
  RETURN a.handle

The same three fixture records produce dispatch-04, marla.v and rook_77: a sequence in XQuery, a result array in CGQL.

02

The parts that feel familiar.

Conceptual mapping, not syntax compatibility
IntentXQueryCGQL
Iterate & bindfor, letFOR, LET
Keep rowswhereFILTER
Order resultsorder bySORT
Shape outputreturnRETURN
03

Keep the data model in view.

XQuery works with XML nodes and atomic values; version 3.1 also supports maps and arrays for JSON-oriented work. Its FLWOR expressions explain the familiar clause structure.

CGQL works with JSON documents and graph edges. Its OUTBOUND, INBOUND and ANY traversals follow an edge collection over a bounded depth. XPath axes, XML constructors and XQuery modules have no direct CGQL counterpart.

This is a guide to transferring query habits. CGQL does not execute XQuery, and importing XML requires a separate data transformation.