Skip to content

[CALCITE-6792] RelJsonReader failed to read RelJsonWriter output if 'NaN' or 'Infinity' approximate numerics are present - #5220

Merged
mihaibudiu merged 1 commit into
apache:mainfrom
1fanwang:calcite-6792-reljson-nonfinite
Aug 27, 2026
Merged

[CALCITE-6792] RelJsonReader failed to read RelJsonWriter output if 'NaN' or 'Infinity' approximate numerics are present#5220
mihaibudiu merged 1 commit into
apache:mainfrom
1fanwang:calcite-6792-reljson-nonfinite

Conversation

@1fanwang

Copy link
Copy Markdown
Contributor

Jira Link

CALCITE-6792

Changes Proposed

A plan containing NaN or infinity cannot make a RelJson round trip. The writer emits those values as bare tokens, and the reader fails with:

JsonParseException: Non-standard token 'Infinity'

Non-finite approximate literals are now written as JSON strings. When the declared type is approximate, the reader converts those strings back to doubles. Finite numbers remain numeric, and a character literal containing "Infinity" remains a string.

Testing

$ SOURCE=core/src/main/java/org/apache/calcite/rel/externalize/RelJson.java
$ git checkout 5e3326a0a8 -- "$SOURCE"
$ JAVA_HOME=$(/usr/libexec/java_home -v 21) ./gradlew :core:test \
    --tests 'org.apache.calcite.plan.RelWriterTest.testNonFiniteApproxLiteral' \
    --no-daemon --console=plain
Expected: "literal": "Infinity"
     but: "literal": Infinity
1 completed, 1 failed, 0 skipped

$ git checkout 9bace4f2d8 -- "$SOURCE"
$ JAVA_HOME=$(/usr/libexec/java_home -v 21) ./gradlew :core:test \
    --tests 'org.apache.calcite.plan.RelWriterTest.testNonFiniteApproxLiteral' \
    --no-daemon --console=plain
1 completed, 0 failed, 0 skipped
BUILD SUCCESSFUL

@xuzifu666

Copy link
Copy Markdown
Member

please correct your pr title which should be consistent with jira.

@1fanwang 1fanwang changed the title [CALCITE-6792] Round-trip non-finite literals in RelJson [CALCITE-6792] RelJsonReader failed to read RelJsonWriter output if 'NaN' or 'Infinity' approximate numerics are present Aug 25, 2026

@mihaibudiu mihaibudiu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some round-trip tests, where the plan is serialized and deserialized and compared with the original?

Comment thread core/src/main/java/org/apache/calcite/rel/externalize/RelJson.java Outdated
@sonarqubecloud

Copy link
Copy Markdown

@mihaibudiu mihaibudiu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash the commits

…NaN' or 'Infinity' approximate numerics are present

Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang force-pushed the calcite-6792-reljson-nonfinite branch from c99ccb1 to 98929d2 Compare August 26, 2026 05:03
@mihaibudiu
mihaibudiu merged commit 5e694d2 into apache:main Aug 27, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants