Skip to content

JVM wheel: Result.to_json() writes a DATE and a DATETIME of a projection row differently from its own record rows and from the native wheel #453

Open

Description

@tae898

On the JVM wheel the same DATE or DATETIME has two JSON forms in Result.to_json(), depending on whether the row is a record or a projection. On the native wheel it has one. The probe behind #446 gave, for a row with a DATE and a DATETIME:

Row arcadedb-jvm arcadedb (native)
projection {"n":0,"day":1767312000000,"ts":"2026-01-02 03:04:05"} {"n":0,"day":20455,"ts":1767323045678}
record "day":20455,"ts":1767323045678 "day":20455,"ts":1767323045678

So the JVM wheel writes a projection DATE as epoch milliseconds (the record row has days) and a projection DATETIME as a text without the milliseconds (the record row has epoch milliseconds, ...678). The native wheel gives the same value for both kinds of row. Anything that reads to_json() and then switches between SELECT * and SELECT a, b on the JVM wheel gets a different unit or type for the same column.

What I would do: make the projection row of the JVM wheel the same as the record row, which is also what the native wheel does. I have not read where the JVM wheel writes the projection (the glue or the engine's JSON writer), so I do not know yet which side the fix goes in. The golden test then pins the projection case too (today it pins only the record row, where the wheels agree).

Refs #314 (item 3 of the status comment of 2026-11-22).

Activity

  1. added this to the 26.12.1 milestone on Nov 22, 2026
  2. self-assigned this
    on Nov 22, 2026
  3. added
    bug
    python
    jvm
    on Nov 22, 2026
  4. added
    native
    on Nov 22, 2026
  5. tae898 commented on Nov 22, 2026

    @tae898
    CollaboratorAuthor

    I traced where the two forms come from. It is the engine, not this repository: Result.to_json() of the JVM wheel is str(self._java_result.toJSON()) (src/arcadedb/results.py), and no Java file in src/java/ writes the JSON of a result. Read at the tag 26.11.1 of ArcadeData/arcadedb (the same methods on main at d6b48767cb84):

    • A record row (SELECT FROM ...) goes through getElement().get().toJSON() and JsonSerializer.map2json. A DATE column becomes epoch days (20455), other temporals epoch milliseconds (1767323045678).
    • A projection row (SELECT day, ts ...) is a non-element ResultInternal. Its toJSON() calls Result.valueToJSON per property. A LocalDateTime is formatted with the schema's date-time format ("2026-01-02 03:04:05", the milliseconds are gone), and a LocalDate has no branch, so JSONObject writes the epoch milliseconds of its UTC midnight (1767312000000).

    Upstream issues ArcadeData/arcadedb#9037 and #9810 deal with this writer, and tests/test_temporal_writers_agree.py says the bridge keeps no encoder of its own, so I do not want to patch the text in Python for the DATE and DATETIME of the top level only (it would leave a DATETIME inside a list or map, and DATETIME_MICROS and DATETIME_NANOS columns, different anyway). The fix belongs in Result.valueToJSON, where both wheels would get it after an engine release. The native wheel writes the record form for both kinds of row with its own codec, so it is the JVM wheel that follows the engine here.

    Decision: this is not a regression and it needs an engine change, so I moved it from 26.12.1 to 27.1.1. The next step is an upstream issue with a Java repro on the engine API (two rows, the probe table of #446) that proposes the record form for a projection, for the maintainers to decide. Until then the to_json() docstring says the two forms exist, and the golden test pins only the record row.

  6. modified the milestones: 26.12.1, 27.1.1 on Nov 22, 2026
  7. tae898 commented on Nov 23, 2026

    @tae898
    CollaboratorAuthor

    I filed the question upstream with a Java repro on the engine API (JDK 21 and 25, engine 26.11.1): ArcadeData/arcadedb#13129. It asks whether a projection row should write a DATE and a DATETIME the way the record row does, and offers a patch for Result.valueToJSON if the answer is yes. This issue stays in 27.1.1 until they answer.

  8. tae898 commented on Nov 30, 2026

    @tae898
    CollaboratorAuthor

    The question to settle before 26.12.1 (2026-12-02): should Result.to_json() of a projection row on arcadedb-jvm stay as it is for this release (option A, my recommendation), or change now (option B)? I reproduced the difference on main and changed nothing, because every change of the output would alter what the to_json() docstring of arcadedb-jvm has described since 26.11.1.

    One row, day = 2026-01-02, ts = 2026-01-02 03:04:05.678, SELECT n, day, ts FROM T:

    Build to_json() of the projection row
    arcadedb-jvm {"n":0,"day":1767312000000,"ts":"2026-01-02 03:04:05"}
    arcadedb {"n":0,"day":20455,"ts":1767323045678}

    What each route writes today

    What to_json() returned for each value (DATETIME_MICROS holds .678901). A map holds the same values as a list, and SELECT *, 1 AS one writes the same values as the other SQL projection. to_json_list() returns the same values on both builds for the two SQL row shapes (epoch milliseconds).

    Route Build DATE DATETIME DATETIME_MICROS DATE in a list DATETIME in a list
    SQL record row (SELECT FROM T) arcadedb-jvm 20455 1767323045678 "2026-01-02 03:04:05.678901" 1767312000000 1767323045678
    SQL record row (SELECT FROM T) arcadedb 20455 1767323045678 1767323045678 1767312000000 1767323045678
    SQL projection (SELECT day, ts, ... FROM T) arcadedb-jvm 1767312000000 "2026-01-02 03:04:05" "2026-01-02 03:04:05" 1767312000000 "2026-01-02 03:04:05"
    SQL projection (SELECT day, ts, ... FROM T) arcadedb 20455 1767323045678 1767323045678 1767312000000 1767323045678
    openCypher RETURN t.day, t.ts, ... arcadedb-jvm "2026-01-02" "2026-01-02T03:04:05.678" "2026-01-02T03:04:05.678901" 1767312000000 1767323045678
    openCypher RETURN t.day, t.ts, ... arcadedb "2026-01-02" "2026-01-02T03:04:05.678" "2026-01-02T03:04:05.678901" 1767312000000 1767323045678

    Two things go beyond the first report. An openCypher RETURN writes ISO text for a top-level value on both builds, so it is a third form that a change to the SQL projection would not touch. And a DATETIME_MICROS column of a record row also differs: arcadedb-jvm keeps the microseconds as text, arcadedb writes milliseconds.

    What the docs say

    Where What it says Holds today?
    to_json() docstring, arcadedb-jvm (src/arcadedb/results.py, released since 26.11.1) a projection DATE is epoch milliseconds and a projection DATETIME is text in the schema's date-time format; a record row has epoch days and milliseconds (text for microsecond columns) yes for the SQL rows, not for openCypher
    how-to/databases-and-queries.adoc (on main since #469) "the values in it are the same on both builds" no: DATE and DATETIME of a SQL projection, and DATETIME_MICROS of a record row and a SQL projection
    to_json() on arcadedb no docstring

    Options

    What changes arcadedb-jvm projection after it Cost
    A Correct the how-to sentence and name the differences. No output changes. The engine question stays open in ArcadeData/arcadedb#13129. {"n":0,"day":1767312000000,"ts":"2026-01-02 03:04:05"} The builds still differ in 26.12.1.
    B The bindings rewrite the projection row of arcadedb-jvm to the record form now. {"n":0,"day":20455,"ts":1767323045678} A caller who reads a projection DATE as milliseconds gets a number 86,400,000 times smaller, with no error, and a DATETIME turns from text into a number. The bindings get a JSON writer of their own (tests/test_temporal_writers_agree.py says they keep none), which also has to handle nested values.
    C The engine changes Result.valueToJSON (ArcadeData/arcadedb#13129), and the wheel takes it with the engine. {"n":0,"day":20455,"ts":1767323045678} if the engine adopts the record form The same change for callers, decided by the engine maintainers.

    I recommend A for 26.12.1, then C if upstream agrees. The upstream issue is in the engine's 26.12.1 milestone, with no reply yet, and valueToJSON on engine main (54f04e8e1812) still writes the old form. If C lands before the release build, the docstrings and the how-to need an update in the same release, and the golden test can then pin the projection row. B would silently change numbers two days before a release. Under A this issue stays in 27.1.1 and only the docs change goes into 26.12.1.

    Reproduction and method

    Wheels that CI built from main at 0d4b99e6a2 (version 26.12.1.dev0, Linux x86-64, Python 3.12.13 for the table, and the test also on 3.15.0): arcadedb-jvm on engine 26.12.1-SNAPSHOT (d0f3bbbd24), arcadedb on engine 26.11.1 (a3a5d12457). The test fails on arcadedb-jvm and passes on arcadedb:

    AssertionError: assert (176731200000...-02 03:04:05') == (20455, 1767323045678)
    
    """#453: Result.to_json() of one DATE and one DATETIME, record row against projection row.
    
    Runs on both wheels. It fails where a projection row writes another value than the record row.
    """
    
    import json
    from datetime import date, datetime
    
    import arcadedb
    
    DAYS = 20455  # 2026-01-02 as days since the epoch
    MS = 1767323045678  # 2026-01-02T03:04:05.678Z as epoch milliseconds
    
    
    def test_projection_row_writes_date_and_datetime_as_the_record_row_does(tmp_path):
        with arcadedb.create_database(str(tmp_path / "db")) as db:
            db.command("sql", "CREATE VERTEX TYPE T")
            for name, kind in [("n", "LONG"), ("day", "DATE"), ("ts", "DATETIME")]:
                db.command("sql", f"CREATE PROPERTY T.{name} {kind}")
            db.insert_many(
                "T",
                [
                    {
                        "n": 0,
                        "day": date(2026, 1, 2),
                        "ts": datetime(2026, 1, 2, 3, 4, 5, 678000),
                    }
                ],
            )
            record = json.loads(db.query("sql", "SELECT FROM T").first().to_json())
            projection = json.loads(
                db.query("sql", "SELECT n, day, ts FROM T").first().to_json()
            )
            assert (record["day"], record["ts"]) == (DAYS, MS)
            assert (projection["day"], projection["ts"]) == (record["day"], record["ts"])

    Run it with uv run --no-project --with "<wheel>" --with pytest python -m pytest test_repro453.py.

  9. added 2 commits that reference this issue on Nov 30, 2026
  10. tae898 commented on Nov 30, 2026

    @tae898
    CollaboratorAuthor

    Decided on 2026-11-30, as the current decision and open to change: option A. 26.12.1 keeps today's to_json() output on both builds, and the change waits for the engine's answer in ArcadeData/arcadedb#13129 (option C). It rests on the options above: rewriting the projection row in the bindings now (option B) would change the unit of a projection DATE and the type of a projection DATETIME with no error just before the release, and the bindings keep no JSON writer of their own. The docs part of option A is done for 26.12.1: #545 and #546 replaced the how-to sentence that said the values are the same on both builds, with a table of what each build writes. This issue stays in 27.1.1.

    Edit: the docs part is already done (#545, #546); the first version said it was still to do.

  11. tae898 commented on Nov 30, 2026

    @tae898
    CollaboratorAuthor

    I corrected my comment above: the docs part of option A is already done in #545 and #546.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugjvmnativepython

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions