Query recipes

Run small examples with known results in Cypher, SQL, and Gremlin. All examples use the same transfer model.

On this page

Prepare the example

Use the CSV and JSON Lines sample from Build your first graph. Run these snippets in the published model’s Query workspace. For CLI runs, choose the dialect with --language and set Cypher values with --parameters.

For Cypher snippets that use $account_id, enter {"account_id":1} in Query options.

Follow two transfers in Cypher

Bind a starting account and return a named path. The graph view can draw the path and show the properties of each hop.

Cypher
MATCH p = (a:Account)-[:Transfer]->(:Account)-[:Transfer]->(b:Account)
WHERE a.id = $account_id
RETURN p

Expected result Alice → Bob → Carol, with two transfer edges.

Keep accounts with zero transfers

Use OPTIONAL MATCH to keep the account when it has no outgoing edge. Count the relationship variable to exclude the empty match.

Cypher
MATCH (a:Account)
OPTIONAL MATCH (a)-[t:Transfer]->(:Account)
RETURN a.name AS account, count(t) AS outgoing
ORDER BY account

Expected result Alice has 1, Bob has 1, and Carol has 0.

Aggregate the mapped edges in SQL

Choose SQL and query the mapped relationship type. Double quotes preserve the mixed-case graph table name.

SQL
SELECT count(*) AS transfers, sum(amount) AS total
FROM "Transfer"

Expected result 2 transfers, with a total amount of 37.75.

Traverse outgoing edges in Gremlin

Choose Gremlin, start from the complete business key 1, and take two outgoing Transfer steps.

Gremlin
g.V(1).hasLabel('Account').out('Transfer').out('Transfer').values('name')

Expected result Carol.

For the next step, see Query and explore for result views, pagination, and Arrow export.