Stream query results

Copy Markdown View Source

Use Arcadic.query_stream/4 when you want to process a large read in chunks. Choose paging or a server cursor based on the transport and the consistency the application needs.

Page over HTTP

{:ok, rows} =
  Arcadic.query_stream(conn, "SELECT FROM User", %{}, language: "sql", chunk_size: 500)

Enum.each(rows, &process_row/1)

Keep ORDER BY, SKIP, LIMIT, and comments out of the statement. Arcadic appends its own paging clauses. SQL without a WHERE clause uses an @rid keyset when the result has a readable cursor. SQL with a WHERE clause or a projection without a cursor on page one uses offset paging. A missing cursor after keyset paging starts causes a stream error.

SQL aliases cannot rebind @rid. For Cypher, provide an id(<identifier>) order key, for example order_key: "id(v)". Cypher uses offset paging. HTTP pages are separate reads. A concurrent delete can shift an offset, and HTTP streaming rejects session-scoped connections.

Use a server cursor

Bolt pulls results in batches. To see uncommitted writes, start and consume the Bolt stream inside the transaction callback. Finish or halt the stream before running another command on the same transaction connection.

The gRPC cursor opens on the first enumeration pull. Halting a stream early cancels it. A session-scoped connection passes its transaction ID to the server cursor. Consume the stream before ending the transaction.

Bolt can lose an idle scan cursor if a pause between pulls exceeds the server's parallelScanAbandonedTimeout. Keep per-row work off the pull path if it can cause long pauses. Set explicit bounds as described in Connections and transports.