Skip to content

JVM: to_json_list() returns a float for every DECIMAL, also of scale 0, as the native wheel does (#452) - #456

Merged
tae898 merged 1 commit into
mainfrom
fix/452-decimal-float
Nov 22, 2026
Merged

tae898 merged 1 commit into
mainfrom
fix/452-decimal-float

Conversation

@tae898

@tae898 tae898 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

The JVM wheel now returns a float for every DECIMAL in to_json_list() and iter_json_batches(), as the docstring says and as the native wheel does, so one column has one Python type on both wheels. Before, the JSON of the JVM wheel printed a DECIMAL of scale 0 without a fraction (3), which Python parsed as an int, and a 20-digit integral value as an int of 20 digits where the native wheel gives the nearest double.

The conversion is in the Java bridge, in RowBatcher.keepNonFinite, the function that already widens a Float and tags NaN and the infinities: a BigDecimal becomes the nearest double (BigDecimal.doubleValue()), at the top level and inside a list or a map, the way json_native does on the native wheel. A value too large for a double takes the existing tag and arrives as inf, as float(Decimal) gives on the native wheel. The fix cannot be in the Python parse: the JSON text of a DECIMAL 3 and of an INTEGER 3 is the same, so only the Java side still knows the type.

tests/test_cross_wheel_golden.py: the case that accepted an int or a float for Decimal("3") and Decimal("-7") now asserts a float (3.0, -7.0) on both wheels, keeps Decimal("2.00"), and adds the 20-digit values Decimal("12345678901234567890") and its negative as floats (1.2345678901234567e+19). It also checks that iter_json_batches(batch_size=1) returns the same rows and that to_list() still returns every digit as a Decimal. The bullet of the module docstring that listed this difference as open is removed.

What each wheel returns, from the probe table of #446 (wheels built from 62195709b7, x86-64 Linux, Python 3.12). The arcadedb-jvm after column is what this change is meant to give, not a measurement: CI asserts it.

Value arcadedb-jvm before arcadedb-jvm after arcadedb (native, unchanged)
Decimal("3") int 3 float 3.0 float 3.0
Decimal("-7") int -7 float -7.0 float -7.0
Decimal("2.00") float 2.0 float 2.0 float 2.0
Decimal("12345678901234567890") int 12345678901234567890 float 1.2345678901234567e+19 float 1.2345678901234567e+19

A DECIMAL that has a fraction already lost exactness as a float on both wheels; this makes the integral case do the same. to_list(), to_columns() and to_arrow() keep the exact Decimal and are not changed.

The Java change was not compiled and the tests were not run on my machine; the CI build of the bridge jar and the test run are the check.

Related issues

Closes #452. Refs #314 (item 1 of the status comment of 2026-11-22).

Docs

The docstring of to_json_list() and the Results list of docs/modules/ROOT/pages/how-to/databases-and-queries.adoc now say that every DECIMAL is a float whatever its scale and that more than about 17 digits are rounded. I searched tests/, docs/, README.md, examples/ and the docstrings for a place that says or asserts that a DECIMAL arrives as an int on the JVM wheel: only tests/test_cross_wheel_golden.py did, and it is fixed here. There is no changelog file in the repository: the release notes are built from the titles and labels of merged pull requests, so the title of this one is the line (label bug).

Checklist

  • A regression test fails on the old code and passes on the new (it passes on the new code in CI; I did not run the old code, the old int is from the probe of Tests: four more cross-wheel golden cases: to_json text, to_arrow float lists, vector distances, integral DECIMAL (refs #314) #446)
  • The test suite that the change can affect passes (CI, run 45079427208 and 45079427042: JVM wheel on Python 3.11 3951 passed and on Python 3.14 3951 passed, 0 skipped, 0 failed; native parity on Python 3.12 4004 passed, 0 failed, 0 error, of which tests/test_cross_wheel_golden.py 24 passed, 0 failed)
  • uvx pre-commit run --files <changed files> passes (second run clean), with compile() and pyflakes on the two Python files

…0, as the native wheel does (#452)

The JSON of the JVM wheel printed a DECIMAL of scale 0 without a fraction ("3"), which Python parsed as an int, and a 20-digit integral value as an int of 20 digits, where the native wheel returns float(Decimal). RowBatcher.keepNonFinite now turns a BigDecimal into the nearest double, at the top level and inside a list or a map, so one column has one Python type on both wheels. A value too large for a double takes the existing tag and arrives as inf, like float(Decimal) on the native wheel.

tests/test_cross_wheel_golden.py asserts a float on both wheels for Decimal("3"), Decimal("-7") and the 20-digit values (1.2345678901234567e+19), and checks iter_json_batches and the exact Decimal of to_list(). The to_json_list() docstring and the Results list of the databases-and-queries page say that every DECIMAL is a float and that more than about 17 digits are rounded. The Java change was not compiled on the machine that wrote it; CI builds the bridge jar.

Closes #452. Refs #314.
@tae898 tae898 added this to the 26.12.1 milestone Nov 22, 2026
@tae898 tae898 added bug Something isn't working python Pull requests that update python code jvm The arcadedb-jvm package (JPype build) labels Nov 22, 2026
@tae898 tae898 self-assigned this Nov 22, 2026
@tae898
tae898 merged commit adad563 into main Nov 22, 2026
26 checks passed
@tae898
tae898 deleted the fix/452-decimal-float branch November 22, 2026 23:06
tae898 added a commit that referenced this pull request Nov 23, 2026
…(#N) after the pull request number (#467)

A dry run for 26.12.1 listed 'fix(#412): the native bytes cache ...' and 'JVM: to_json_list() ... (#452) (#456)'. The prefix carries an issue number and a process word that a reader of a release does not need, and the bare number next to the number of the pull request is an issue reference of the same kind as the (refs #N) notes that are already left out. A title that is nothing but such text is kept as it is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working jvm The arcadedb-jvm package (JPype build) python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JVM wheel: to_json_list() returns an int for a DECIMAL of scale 0, the native wheel a float

1 participant