Skip to content
This repository was archived by the owner on Nov 21, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions bindings/python/docs/api/results.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,18 @@ first = next(result_set) # Raises StopIteration when exhausted

Convert all results to a list of dictionaries.

Rows come over from the JVM in batches. Java writes each batch as JSON, tags the values
JSON cannot carry exactly (`DECIMAL`, `DATE`, `DATETIME`, sets), and hands everything else
(RIDs, embedded documents, `float[]` arrays, ...) over as the engine's own object, so each
value has the Python type it always had (`date`, `datetime`, `Decimal`, ...) and no value
crosses the JVM boundary on its own. On a 10,000-row, nine-property scan that is 7.1x
faster than it was and within a few percent of `to_json_list()` (261 ms to 37 ms, laptop,
2026-10-08; see the [performance guide](../guide/performance.md)).

**Parameters:**

- `convert_types` (bool): Convert Java types to Python types (default: `True`)
- `convert_types` (bool): Convert Java types to Python types (default: `True`). `False`
reads the rows one at a time without conversion

**Returns:**

Expand All @@ -99,6 +108,11 @@ print(users[0])

Iterate results as dictionaries.

Each row is read when you ask for it, in one crossing into the JVM (the same typed
transport as `to_list()`), so stopping early or changing records inside the loop behaves
as it always did. 3.6x faster than before on a 10,000-row, nine-property scan (279 ms to
79 ms). To take the whole result, `to_list()` is another 2x faster.

**Parameters:**

- `convert_types` (bool): Convert Java types to Python types (default: `True`)
Expand All @@ -115,16 +129,17 @@ Bulk-materialize all rows via batched Java-side JSON serialization.

The fast path for large result sets: rows are serialized to JSON in batches on the Java
side (one JPype crossing per batch instead of several per row) and parsed with the C
json module. Measured ~5.5x faster than `to_list()` on a 10,000-row, nine-property scan
(578 ms against 103 ms, laptop, 2026-09-27).
json module. It was ~5.5x faster than `to_list()` on a 10,000-row, nine-property scan
(578 ms against 103 ms, laptop, 2026-09-27); `to_list()` now reads rows the same way and
keeps the Python types, so the two cost about the same.

**Trade-off:** values carry JSON-native types. Numbers, strings, booleans, lists, and
nested maps convert as expected, but `DATE` and `DATETIME` values arrive as
epoch-millisecond integers (not `datetime`) and DECIMALs as floats. A `DATE` is the
epoch milliseconds of midnight UTC, whatever the JVM's time zone, so it is the same
integer `Result.to_json()` writes and `datetime.fromtimestamp(ms / 1000, timezone.utc)`
gives the right day. Use `to_list()` when full Python-type fidelity matters more than
speed.
gives the right day. Use `to_list()` when you want `date`, `datetime`, and `Decimal`
values: it costs about the same.

It is also the fast path for a small result: a one-row read through `to_json_list()` takes
one Java crossing (a short batch ends the read) and allocates only what the row needs.
Expand Down Expand Up @@ -614,8 +629,8 @@ for person in people:

**Performance note:** `to_dict()` converts the whole row in one call into Java, which
is cheaper than one `get()` per property when you need several fields. For large result
sets, the bulk methods are faster than any per-row access: `to_json_list()`,
`to_columns()`, `to_dataframe()`, or `to_arrow()`.
sets, `to_list()` is the fast way to get row dicts, and `to_columns()`, `to_dataframe()`,
or `to_arrow()` are faster still when you want columns.

---

Expand Down Expand Up @@ -648,14 +663,14 @@ for result in result_set:

### Converting to Lists and Dicts

`ResultSet.to_list()` and `Result.to_dict()` are eager materializers. They are the
right choice when you explicitly want Python-native data, but they are not the
lowest-overhead path for large result sets.
`ResultSet.to_list()` and `Result.to_dict()` are eager materializers. `to_list()` reads
rows in batches and is the fast way to get row dicts with Python-native values; for
columns, `to_columns()`, `to_dataframe()`, and `to_arrow()` are faster still.

```python
# List of dictionaries (most common)
result_set = db.query("sql", "SELECT FROM User")
users = [result.to_dict() for result in result_set]
users = result_set.to_list()

# List of specific property values
result_set = db.query("sql", "SELECT name FROM User")
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/docs/development/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ for row in result:
```

When you do need the whole result materialized, prefer the bulk APIs
(`to_columns()`/`to_dataframe()` or `to_json_list()`) over `list(result)` /
`to_list()`; see the [Performance guide](../guide/performance.md).
(`to_columns()`/`to_dataframe()`) over `list(result)`; `to_list()` is the fast
way to take row dicts. See the [Performance guide](../guide/performance.md).

---

Expand Down
10 changes: 7 additions & 3 deletions bindings/python/docs/development/bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ sources live in `bindings/python/src/java/com/arcadedb/python/`:
| `EdgeBatcher` | Buffers a whole batch of edges into `GraphBatch` from one call (RID strings, or JSON rows for edges with properties) |
| `VertexBatcher` | Creates a whole batch of vertices from one JSON-rows string, returning all RIDs as one joined string |
| `TimeSeriesBatcher` | Fills the engine's primitive `TimeSeriesBatch` one column per call, so numeric samples are never boxed |
| `RowAccess` | Hands a row's names and values to Python in one call (`namesAndValues`), and up to N such rows per call (`nextRows`); the values are the engine's own objects, so Python converts them with full type fidelity. Also the first row of a result set with the set closed (`firstAndClose`, behind `ResultSet.first()`) and a property or null (`propertyOrNull`, behind `Result.get()`), each in one call instead of two or three |
| `RowAccess` | Hands a row's names and values to Python in one call (`namesAndValues`), and up to N such rows per call (`nextRows`, the fallback for `to_list()` when the bridge jar lacks `TypedRows`); the values are the engine's own objects, so Python converts them with full type fidelity. Also the first row of a result set with the set closed (`firstAndClose`, behind `ResultSet.first()`) and a property or null (`propertyOrNull`, behind `Result.get()`), each in one call instead of two or three |
| `TypedRows` | Up to N rows per call as one JSON string, type-faithful (`nextRows`): DECIMAL, BigInteger, DATE, DATETIME, Instant and zoned values, and sets are tagged and restored exactly by Python, and every other value (RIDs, embedded documents, `float[]` and `double[]`, non-finite floats, maps with non-String keys, years Python cannot hold) is returned in a side array as the engine's own object and converted by Python as before. Behind `ResultSet.to_list()` (1,000 rows per call) and `ResultSet.iter_dicts()` (one row per call, so a lazy caller reads rows when it asks) |
| `GraphCalls` | Every edge of `Vertex.getEdges(direction, labels)` in one call (`outEdges`, `inEdges`, `bothEdges`, behind `Vertex.get_out_edges()` and its siblings), and the record and score of every vector search hit in one call (`hits`, behind `LSMVectorIndex` search results) |
| `DbCalls` | One-row statements and lookups in one call: `commandNamed`, `queryNamed`, `commandPositional`, and `queryPositional` take the parameters as the varargs of a single non-overloaded method and build the map Java-side (behind `Database.command()` and `Database.query()`), and `lookupFirst` is the whole of `Database.lookup_by_key()` |

`RowBatcher.nextJsonBatch` and `RowAccess.nextRows` return fewer rows than asked for only when the result set is drained, and they close it before returning. Python therefore stops after a short batch and makes no further call into the bridge, not even `close()`: a one-row `to_list()` or `to_json_list()` costs one call into the bridge.
`RowBatcher.nextJsonBatch`, `TypedRows.nextRows`, and `RowAccess.nextRows` return fewer rows than asked for only when the result set is drained, and they close it before returning. Python therefore stops after a short batch and makes no further call into the bridge, not even `close()`: a one-row `to_list()` or `to_json_list()` costs one call into the bridge.

## Why it exists

Expand All @@ -36,7 +38,9 @@ crossing per batch**, receiving a bulk payload it can decode at C speed: the
| Python API | Bridge class |
|---|---|
| `ResultSet.to_json_list()` / `iter_json_batches()` | `RowBatcher` |
| `ResultSet.to_list()` (rows in batches), `Result.to_dict()` (one row) | `RowAccess` |
| `ResultSet.to_list()` (rows in batches), `ResultSet.iter_dicts()` (one row per call) | `TypedRows` |
| `Result.to_dict()` (one row) | `RowAccess` |
| `Vertex.get_out_edges()` / `get_in_edges()` / `get_both_edges()`, vector search results | `GraphCalls` |
| `ResultSet.to_columns()` / fast `to_dataframe()` / `to_arrow()` | `ColumnBatcher` |
| `Database.insert_many()` | `DocumentBatcher` |
| `Database.insert_columns()` | `DocumentBatcher` |
Expand Down
46 changes: 25 additions & 21 deletions bindings/python/docs/guide/core/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,9 @@ cities = [r.get("city") for r in db.query("sql", "SELECT city FROM Person GROUP

### ResultSet Methods

Use `first()` or direct iteration when you want the lowest-overhead path.
`to_list()` eagerly materializes the full result set into Python dictionaries, so it
is best reserved for smaller results or explicit interop steps.
Use `first()` or direct iteration when you want the lowest-overhead path for one row
or a few. `to_list()` eagerly materializes the full result set into Python
dictionaries, in batches, and is the fast way to take a whole result as row dicts.

```python
# first() - get first result
Expand Down Expand Up @@ -620,21 +620,26 @@ bulk APIs when you're taking everything from a large result.**
- Use `first()` when you only need one row.
- Use direct iteration plus `get()` when you read only some columns, need live
records (`get_element()`), or may stop early. Ideal for small/medium results;
on very large results it pays a per-row boundary cost.
each `get()` is a crossing into the JVM.
- Use `iter_dicts()` to stream rows as dicts: one row per crossing, read when you ask
for it (3.6x faster than it was on a 10,000-row, nine-property scan).
- Use `to_list()` to take the whole result as row dicts with full Python-type
fidelity (`date`, `datetime`, `Decimal`). Rows come over in batches (7.1x faster
than it was on the same scan: 261 ms to 37 ms, laptop, 2026-10-08).
- Use `to_columns()` / `to_dataframe()` to bulk-load large results into
numpy/pandas. This is the fastest path (~12x over `to_list()` on a
10,000-row, nine-property scan, laptop, 2026-09-27), with typed columns
including real `datetime64`.
numpy/pandas. This is the fastest path (about 28 ms against 37 ms for `to_list()` on that
scan), with typed columns including real `datetime64`.
- Use `to_json_list()` (or `iter_json_batches()` when it may not fit in memory)
to bulk-load large results as plain dicts. JSON-native types: `DATE` and
`DATETIME` values arrive as epoch-millisecond integers.
- Use `to_list()` when you need full Python-type fidelity (`datetime`,
`Decimal`) as row dicts and the result is not huge.
only when you want JSON-native values (`DATE` and `DATETIME` as
epoch-millisecond integers, `DECIMAL` as float) or need to bound memory with
batches; it costs about the same as `to_list()`.
- Use wrapper `to_dict()` only when you truly want the full document in Python.

On JPype 1.7.1, the newest release, `to_list()` and `Result.get()` also keep a
Python object for every number they return, which adds up on very large reads;
`to_json_list()` and `to_columns()` do not (see [Known Engine Issues](../known-issues.md)).
On JPype 1.7.1, the newest release, `Result.get()` and the values of an object
that the batched paths hand over as engine objects keep a Python object for every
number they return, which adds up on very large reads; `to_list()`, `iter_dicts()`,
`to_json_list()` and `to_columns()` do not for plain numbers (see
[Known Engine Issues](../known-issues.md)).

A result set closes itself when it is exhausted (by iteration or any `to_*`
method) and when `first()` or `one()` returns. If you stop reading early and keep
Expand All @@ -654,16 +659,15 @@ with db.query("sql", "SELECT name, score FROM Item WHERE score > ?", 100) as res
if row.get("score") > 1000:
break

# Bulk materialization as dicts (~5.5x faster than to_list on a wide scan):
# rows are JSON-serialized in batches on the Java side. Values carry
# JSON-native types (DATE and DATETIME values arrive as epoch-millisecond
# integers, not datetime).
rows = db.query("sql", "SELECT FROM Item").to_json_list()

# Materialize with full Python-type fidelity (datetime, Decimal, ...)
# Bulk materialization as dicts with full Python-type fidelity (date,
# datetime, Decimal, ...): rows come over in batches
result = db.query("sql", "SELECT name, score FROM Item WHERE score > ?", 100)
payload = result.to_list()

# Same shape with JSON-native values (DATE and DATETIME values arrive as
# epoch-millisecond integers, not datetime), in bounded batches
rows = db.query("sql", "SELECT FROM Item").to_json_list()

# For wrappers, prefer field access over full dict conversion in large loops
for doc in db.query("sql", "SELECT FROM Person"):
process(doc.get("name"), doc.get("city"))
Expand Down
19 changes: 11 additions & 8 deletions bindings/python/docs/guide/known-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Tests: `tests/test_sigint.py` covers a Python loop and a Java call that Ctrl-C c
It has no test of the waits above, because the failure is random (humemai/arcadedb-embedded-python#179).


## `to_list()` and `Result.get()` keep a Python object for every number that comes back from Java
## `Result.get()` keeps a Python object for every number that comes back from Java

JPype 1.7.1, the newest release and the one a fresh install gets (the package declares
`jpype1>=1.5.0`; 1.6.0 leaks too, [jpype-project/jpype#1379](https://github.com/jpype-project/jpype/issues/1379));
Expand All @@ -92,13 +92,16 @@ leak in JPype, not in ArcadeDB.
JPype 1.7.1 keeps one Python object (about 32 bytes) for every number that comes back from Java
as a boxed `Long`, `Integer`, `Short`, `Byte`, `Float`, or `Double`, and never frees it before the
process ends. Through the bindings that is about 3.9 objects per row for a scan of nine
properties read with `to_list()`, `Result.get()`, `Result.to_dict()`, or `iter_dicts()`, about
125 bytes per row, or 1.2 GB for 10 million rows. Small integers and booleans are cached by
Python and do not count, so only values above 256 and floats leak. `to_json_list()` and
`to_columns()` did not leak in the same runs (0 objects per row).

Read a large result with `to_json_list()` or `to_columns()`, which also cross the JVM faster,
or upgrade JPype to the release that carries the fix when it ships. Count the live Python
properties read with `Result.get()` or `Result.to_dict()`, about 125 bytes per row, or 1.2 GB
for 10 million rows. Small integers and booleans are cached by Python and do not count, so
only values above 256 and floats leak. `to_list()` and `iter_dicts()` read numbers from
JSON text, as `to_json_list()` and `to_columns()` do, so plain numbers do not leak there
(only a value the transport hands over as the engine's own object, such as a `float[]`,
is a number JPype boxes). The 3.9 objects per row above were measured when `to_list()` and
`iter_dicts()` converted each value in Python.

Read a large result with `to_list()`, `iter_dicts()`, `to_json_list()`, or `to_columns()`
rather than a `get()` per value, or upgrade JPype to the release that carries the fix when it ships. Count the live Python
objects with `sys.getallocatedblocks()` before and after a read to see whether your path is
affected.

Expand Down
Loading
Loading