From 1d03763ae2dcde2d595e3fda4f4cfef472b7e935 Mon Sep 17 00:00:00 2001 From: Taewoon Kim Date: Mon, 30 Nov 2026 09:13:32 +0900 Subject: [PATCH] docs(#453): to_json() does not write every date and time alike on the two builds The how-to said the values of Result.to_json() are the same on both builds. They are not for the DATE and the DATETIME of a SQL projection, or for a DATETIME_MICROS column of a SQL row. A table now states what each build writes, as measured on the CI wheels of main. No code and no output changes; which form to keep stays open in #453. The timing paragraph of iter_json_batches is back under its own list item. Refs #453 --- .../pages/how-to/databases-and-queries.adoc | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/modules/ROOT/pages/how-to/databases-and-queries.adoc b/docs/modules/ROOT/pages/how-to/databases-and-queries.adoc index d5c5456..73d0863 100644 --- a/docs/modules/ROOT/pages/how-to/databases-and-queries.adoc +++ b/docs/modules/ROOT/pages/how-to/databases-and-queries.adoc @@ -273,9 +273,51 @@ A query vector for `vectorNeighbors` can be a numpy array or a list. This sectio * `to_list()` materialises the whole result as a list of dicts, one Python dict per row. Use it for a small result, or when you need the whole result in memory; iterate when you stop early. For a large result, see <>. * `to_json_list(batch_size=10_000)` returns the rows as a list of JSON-native dicts, the same on both builds. A `DATE` or `DATETIME` is a number of epoch milliseconds, a record id is its text, and every `DECIMAL` is a `float` whatever its scale, so `Decimal("3")` is `3.0` and one column has one Python type. A `float` keeps about 17 significant digits, so a `DECIMAL` with more digits is rounded: `to_list()` returns the `Decimal` with every digit. * `iter_json_batches(batch_size=10_000)` yields the rows as lists of JSON-native dicts, `batch_size` rows per list (the last may be shorter), with the same values as `to_json_list()`. On the native build `batch_size` bounds memory: the result set holds one reply of the cursor (2048 rows) and one batch at a time, and reads the next reply only when the next batch is asked for, so a large result is never held whole. On the JVM build a batch is serialised on the Java side one at a time. `to_list()`, `to_json_list()`, `to_dataframe()`, `to_columns()`, `to_arrow()` and `to_polars()` still hold the whole result, because they return it whole. -* `Result.to_json()` returns the text of one row, and the values in it are the same on both builds, but the text is not always. A `FLOAT` or a `float32` array is written as the shortest `float32` text on `arcadedb-jvm` (`0.1`) and as the exact `float64` that the `float32` widens to on `arcadedb` (`0.10000000149011612`). Both read back as the same `float32`. Text in a string is written the same on both: a character outside ASCII as it is, and a `\u` escape only for control characters, U+2028 and U+2029. Parse the text with `json.loads` and compare the numbers, and do not hash, diff or measure the text itself across the two builds. `to_json_list()` has no such difference: both builds return the exact widening. + One laptop study on the native build, 1,000,000 rows read with `batch_size=10_000`, 10 clean pairs of this change against the previous behaviour; each figure is the ratio of the new value to the old one, so below 1 is lower. Peak RSS: 0.286 (95% interval 0.284 to 0.289). Time to the first batch: 0.010 (95% interval 0.009 to 0.010). Wall time of the whole read: 0.958 (95% interval 0.952 to 0.966). This is one machine and one result shape, not a speed promise. +* `Result.to_json()` returns the text of one row. The two builds do not always write the same text, and for some dates and times they do not write the same value either (see the table below and https://github.com/ArcadeData/arcadedb-python/issues/453[#453]). A `FLOAT` or a `float32` array is written as the shortest `float32` text on `arcadedb-jvm` (`0.1`) and as the exact `float64` that the `float32` widens to on `arcadedb` (`0.10000000149011612`). Both read back as the same `float32`. Text in a string is written the same on both: a character outside ASCII as it is, and a `\u` escape only for control characters, U+2028 and U+2029. Parse the text with `json.loads` and compare the numbers, and do not hash, diff or measure the text itself across the two builds. `to_json_list()` has no such difference for floats: both builds return the exact widening. ++ +How `to_json()` writes a date or a time depends on the kind of row and, in some cells, on the build. The table shows a `DATE` of 2026-01-02, a `DATETIME` of 2026-01-02 03:04:05.678 and a `DATETIME_MICROS` of 2026-01-02 03:04:05.678901. Where a cell names no build, both builds write the value shown. `20455` is days since 1970-01-01, and the 13-digit numbers are epoch milliseconds (for a `DATE`, those of its UTC midnight). ++ +[cols="2,3,3,3",options="header"] +|=== +| Value +| SQL record row (`SELECT FROM T`) +| SQL projection (`SELECT day, ts FROM T`) +| openCypher (`RETURN t.day, t.ts`) + +| `DATE` +| `20455` +| `arcadedb-jvm`: `1767312000000` + +`arcadedb`: `20455` +| `+"2026-01-02"+` + +| `DATETIME` +| `1767323045678` +| `arcadedb-jvm`: `+"2026-01-02 03:04:05"+` + +`arcadedb`: `1767323045678` +| `+"2026-01-02T03:04:05.678"+` + +| `DATETIME_MICROS` +| `arcadedb-jvm`: `+"2026-01-02 03:04:05.678901"+` + +`arcadedb`: `1767323045678` +| `arcadedb-jvm`: `+"2026-01-02 03:04:05"+` + +`arcadedb`: `1767323045678` +| `+"2026-01-02T03:04:05.678901"+` + +| `DATE` in a list or a map +| `1767312000000` +| `1767312000000` +| `1767312000000` + +| `DATETIME` in a list or a map +| `1767323045678` +| `arcadedb-jvm`: `+"2026-01-02 03:04:05"+` + +`arcadedb`: `1767323045678` +| `1767323045678` +|=== ++ +The text of a projected `DATETIME` on `arcadedb-jvm` follows the date-time format of the schema, and the default format, used here, has no fraction of a second. `SELECT *, 1 AS one` is a projection too and writes the same date and time values. On `arcadedb`, `to_json()` does not write the microseconds of a `DATETIME_MICROS` column in either SQL row. For both SQL rows, `to_json_list()` returns epoch milliseconds for every value in this table on both builds, so use it when a program must read these dates alike on the two. For the openCypher row, `to_json_list()` also returns ISO text for the top-level values, the same on both builds. On the JVM build, `Document.to_dict()`, `Result.to_dict()` and `get_property_names()` cross into the JVM once per record or row, not once per property, and stepping through a result set takes one crossing per row, not two. The values and their Python types are the same as before. This was timed on the `{jvm-pkg-name}` package, built with the change and without it, one fresh process per run. The time is per record or row, in microseconds, and the table gives the ratio of the time with the change to the time without it (median over 12 clean pairs, 95% interval). Below 1 means less time.