Skip to content

fix(importer): preserve JSON number types - #10774

Closed
7487 wants to merge 1 commit into
ArcadeData:mainfrom
7487:fix/issue-10756-the-json-importer-reads-every-number-tok
Closed

7487 wants to merge 1 commit into
ArcadeData:mainfrom
7487:fix/issue-10756-the-json-importer-reads-every-number-tok

Conversation

@7487

@7487 7487 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #10756.

The JSON importer read every numeric token with JsonReader.nextDouble(). As a result, integers were stored as Double values and integers above 2^53 could be silently rounded.

This change reuses JSONObject's existing numeric token decoder in both importer number paths, so imported values retain the same Integer, Long, Double, or BigDecimal representation as the project's JSON reader.

Changes

  • Extract the existing JSONObject number-token decision into JSONObject.parseNumber(String).
  • Use that decoder for both object properties and array entries in JSONImporterFormat.
  • Add an end-to-end importer regression covering integer, long, beyond-long integer, double, and exact decimal values in object and array positions.

No dependency, schema, configuration, or unrelated behavior change is included. Existing records are not rewritten.

Verification

  • TDD red: the new importer regression failed with expected: 42 / actual: 42.0 before the fix.
  • Targeted and connected tests: JSONImporterIT plus Issue9004JsonNumbersBeyondLongAndDoubleTest, 20 tests passed.
  • Full Maven reactor coverage completed in resumable segments with all modules green, including:
    • Engine, Network, gRPC Stubs, Integration, Server, and MCP Server.
    • HA Raft: 3,249 tests passed.
    • Metrics, Tracing, Console, Gremlin, GraphQL, MongoDB, Redis, Postgres, and Bolt.
    • gRpcW: 438 tests passed.
    • gRPC Client, Coverage, Studio, Package, End-to-End, load tests, and E2E HA.
  • uvx pre-commit run --from-ref origin/main --to-ref HEAD passed all applicable hooks.
  • git diff origin/main...HEAD --check passed.

The local network transparently resolves reserved negative-test hostnames. DNS-negative modules were therefore run with -Djdk.net.hosts.file=/etc/hosts; dependency-resolving modules were run without that option. One unrelated HA timing assertion was reproduced on the untouched base and then passed as part of the complete HA class and the final 3,249-test HA run.

Visual verification

Not applicable. This change has no UI surface.

Summary by CodeRabbit

  • Bug Fixes
    • JSON imports now preserve numeric values more accurately, including large integers and decimals with many fractional digits.
    • Numeric values in both object properties and arrays retain appropriate numeric representations, reducing unintended rounding or loss of precision.

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 21ea97eb-a00e-4e3a-9ffb-1ac8a5fd60c8
Commits

Reviewing files that changed from the base of the PR and between dc8cb87 and 7c3c730.

Files selected for processing: 3
  • engine/src/main/java/com/arcadedb/serializer/json/JSONObject.java
  • integration/src/main/java/com/arcadedb/integration/importer/format/JSONImporterFormat.java
  • integration/src/test/java/com/arcadedb/integration/importer/JSONImporterIT.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

The change exposes JSONObject.parseNumber(String) and uses it for JSON importer numeric properties and array entries. The integration test checks imported integers, large integers, doubles, and precise decimals.

Changes: JSON Number Import

Layer / File(s) Summary
Shared number conversion
engine/src/main/java/com/arcadedb/serializer/json/JSONObject.java
elementToObject delegates numeric conversion to the new public parseNumber(String) method, which retains the existing conversion rules.
Importer parsing and validation
integration/src/main/java/com/arcadedb/integration/importer/format/JSONImporterFormat.java, integration/src/test/java/com/arcadedb/integration/importer/JSONImporterIT.java
The importer uses JSONObject.parseNumber for numeric properties and array entries. The integration test checks imported numeric values and Java types.

Priority: High

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: High

Possibly related PRs

  • ArcadeData/arcadedb#9131: It changes JSONObject number decoding, whose conversion rules this PR exposes and reuses in the JSON importer.

Suggested labels: bug, engine

Suggested reviewers: lvca, robfrank

Merge Risk: Minimal · up to 7c3c7

No actionable issue is established; the change is ready to merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the primary change: preserving JSON number types during import.
Description check Passed The description clearly explains the issue, implementation, scope, testing, and verification. It does not use the exact template headings and omits the checklist, but it provides the required informat…
Linked Issues check Passed Issue [#10756] requires JSON importer numbers to preserve the existing JSONObject number-decoding behavior in object and array positions. JSONImporterFormat now calls `JSONObject.parseNumber(reade…
Out of Scope Changes check Passed The changes are limited to the requested shared number decoder, its two importer call sites, and importer regression coverage for issue [#10756]. The test and refactoring directly support the issue. N…
Full details: Description check

Explanation

The description clearly explains the issue, implementation, scope, testing, and verification. It does not use the exact template headings and omits the checklist, but it provides the required information in equivalent sections.

Full details: Linked Issues check

Explanation

Issue [#10756] requires JSON importer numbers to preserve the existing JSONObject number-decoding behavior in object and array positions. JSONImporterFormat now calls JSONObject.parseNumber(reader.nextString()) in both NUMBER paths. JSONObject.elementToObject also uses this extracted decoder, including Integer, Long, Double, BigDecimal, and oversized-number validation branches. JSONImporterIT verifies exact values and types for object properties and array entries, including an integer above 2^53 and a value beyond long.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the requested shared number decoder, its two importer call sites, and importer regression coverage for issue [#10756]. The test and refactoring directly support the issue. No unrelated format, schema, dependency, configuration, or record-rewrite changes appear in the reviewed diff.

Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mergify

mergify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is closed, so it cannot be queued. Reopen it to get the box back.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 449 complexity

Metric Results
Complexity 449

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@robfrank

Copy link
Copy Markdown
Collaborator

@claude review

@claude

claude Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Claude finished @robfrank's task in 21s —— View job


Review of PR #10774 (preserve JSON number types in importer)

Verdict: looks good, no blocking issues.

  • Read the diff (JSONObject, JSONImporterFormat, JSONImporterIT)
  • Checked behavior parity of the extracted decoder

What I checked

  • JSONObject.parseNumber(String) is a faithful extraction of the old inline logic. The only change is primitive.getAsDouble() becoming Double.parseDouble(value). For a LazilyParsedNumber these are equivalent, so elementToObject behavior is unchanged, including the HTTP: a JSON integer parameter beyond the int64 range silently wraps around (18446744073709551617 becomes 1), so a lookup by it returns the record whose id is 1 #9004 guards (isSafeBigNumber, mayLoseDigits, isExactDouble).
  • Both importer NUMBER paths (object property and array entry) now use the same decoder. JsonReader.nextString() is valid for a NUMBER token and returns the raw text, so no precision is lost before parsing.
  • Reusing the existing decoder follows the "reuse existing components" guideline, and it avoids a second copy of the Integer/Long/Double/BigDecimal rules.

Minor, non-blocking notes

  1. Behavior change on hostile input: an oversized number token (over 1000 chars, or an exponent beyond the limit) now throws JSONException during import, where nextDouble() previously returned a double or Infinity. That is consistent with JSONObject and arguably better. It would be worth a one-line mention in the PR or release notes, and optionally a small test that the importer rejects such a token cleanly.
  2. Type change for existing users: integer-valued fields previously stored as Double now arrive as Integer/Long. If a schema already has a DOUBLE property, the type conversion should handle it. If the importer creates properties from the first value seen, new imports will infer integer types. That seems to be the intent of The JSON importer reads every number token with nextDouble, so an integer comes back as a Double and a long past 2^53 comes back wrong, in the one project that already has a reader that gets this right #10756, but the change is visible to users.
  3. Javadoc: the new public parseNumber could say which types it returns (Integer, Long, Double, BigDecimal) and that it throws JSONException for oversized tokens. This would also help the docstring-coverage warning from CodeRabbit.
  4. Tests: I didn't run them here (the checkout has no merge base with origin/main). The PR description reports JSONImporterIT and Issue9004JsonNumbersBeyondLongAndDoubleTest passing, and the added regression covers object and array positions, a value above 2^53, a value beyond long, and an exact decimal.

No security or performance concerns. parseNumber allocates nothing beyond the result, and it is cheaper than the old path.

@github-actions

Copy link
Copy Markdown
Contributor

Triage: triage:lgtm · severity:major · areas: importer, engine · has-issue

The change is small and does what it says. It also follows the project's principle of reusing existing components.

Minor, non-blocking notes:

  • Integers are now stored as Integer/Long instead of Double. That is the intended fix, but it is a visible behavior change for existing import users. A release-note mention would help.
  • A small unit test for JSONObject.parseNumber in the engine module would pin the new public method directly. The existing Issue9004JsonNumbersBeyondLongAndDoubleTest covers it indirectly.

@robfrank robfrank self-assigned this Nov 17, 2026
@robfrank

Copy link
Copy Markdown
Collaborator

Automated review: not finished, will retry

no test in scope could run in the sandbox. Nothing was found against the PR; the next review run tries again.

Why: Automation limit: the review could not finish on its own; nothing was found against the PR.

Next step: Nothing; the next review run tries again.

Step Result
Triage clean
GitHub triage LGTM
Sandbox build and tests on 7c3c730c456c2ca8e09a6376fa6c74894eb0ce4b not run
Fix commits pushed none

Improvements

  • not applied: quality — Widen the inferred id property type so a later larger numeric id does not fail against an INTEGER column (no test in scope could run in the sandbox)

@robfrank robfrank added the needs-changes review-pr label Nov 17, 2026
@robfrank

Copy link
Copy Markdown
Collaborator

Automated review: changes needed

fix incomplete: The PR changes com.arcadedb.serializer.json.JSONObject, which is referenced by far more than 100 test classes across modules, so the scope is too wide for automated review. I did not run any tests. The Bash and Grep tools here would not let me count the references, so this is an inference, not a cou. The contributor has findings to address.

Why: The PR needs changes: the GitHub triage or the tests found problems the automated fixer could not resolve.

Next step: Read the latest classify-pr triage comment on this PR and address its findings.

Step Result
Triage clean
GitHub triage LGTM
Sandbox build and tests on 7c3c730c456c2ca8e09a6376fa6c74894eb0ce4b not run
Fix commits pushed none

@robfrank

Copy link
Copy Markdown
Collaborator

Thank you @7487 for tracking this down and for the clear regression test. Main fixed #10756 independently in #10904 (482cf6fe24), with the same approach you took: one shared JSONObject.parseNumber decoder used by the importer.

Once this branch is merged with main, its only remaining change is the JSONImporterIT test, and Issue10756JsonImporterNumbersTest on main already covers the same cases (integer, long, beyond-long, double and exact decimal values, in object and array positions). Main also covers the points raised in review here:

  • Javadoc on parseNumber, naming the return types and the JSONException it throws for oversized tokens
  • a hostile number token is refused as a row error (aHostileNumberTokenIsRefusedAsARowError)
  • an inferred numeric @id column is declared LONG/DECIMAL, so a later larger id does not fail against an INTEGER column

So I'm closing this as superseded by #10904. The earlier needs-changes label came from our review automation (the change reached too many test classes for it to review), not from a problem with your code. Sorry for the noise.

@robfrank robfrank removed the needs-changes review-pr label Nov 18, 2026
@robfrank robfrank closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine Core engine: document/schema API has-issue The PR links an issue it resolves importer Data import module (CSV/JSON/XML/ZIP) severity:major A feature is broken or returns wrong results, with no practical workaround triage:lgtm PR triage: nothing blocking, ready for a maintainer

Projects

None yet

2 participants