1fanwang commented on code in PR #5220:
URL: https://github.com/apache/calcite/pull/5220#discussion_r3868874017
##########
core/src/main/java/org/apache/calcite/rel/externalize/RelJson.java:
##########
@@ -606,11 +606,18 @@ public Object toJson(RexNode node) {
final RexLiteral literal = (RexLiteral) node;
final Object value = literal.getValue3();
map = jsonBuilder().map();
- //noinspection rawtypes
- map.put("literal",
- value instanceof Enum
- ? RelEnumTypes.fromEnum((Enum) value)
- : toJson(value));
+ if (value instanceof Enum) {
Review Comment:
That branch is gone. The revision after your review replaced it with a small
helper that runs just before a literal is written.
The remaining condition is narrow: a `Double` that is not finite. Those
become strings, because JSON has no syntax for NaN or infinity and the
`BigDecimal` the reader parses numbers into cannot hold one either. Every other
value, finite doubles included, goes down the path it always did.
The reader side needs its own guard, since a plain `CHAR` literal is free to
spell `Infinity` and must not be turned into a double on the way back. It only
converts a string when the literal's declared type is approximate.
The test pins both. It round-trips NaN, positive and negative infinity, a
finite `1.5` that stays a JSON number, and a `CHAR` literal reading `Infinity`
that stays a string.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]