Skip to content

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

Open
1fanwang wants to merge 1 commit into
apache:mainfrom
1fanwang:calcite-6792-reljson-nonfinite
Open

[CALCITE-6792] RelJsonReader failed to read RelJsonWriter output if 'NaN' or 'Infinity' approximate numerics are present#5220
1fanwang wants to merge 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

…NaN' or 'Infinity' approximate numerics are present

RelJson emitted IEEE 754 special values as bare tokens, which are invalid JSON and cannot be parsed through the readers BigDecimal mode. Encode them as typed strings so plans containing approximate literals round-trip.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

@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?

value instanceof Enum
? RelEnumTypes.fromEnum((Enum) value)
: toJson(value));
if (value instanceof Enum) {

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.

What case is this branch covering?

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