-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AVRO-2032: [Java] Add support for NaN, Infinity and -Infinity in JsonDecoder #3066
base: main
Are you sure you want to change the base?
Conversation
JsonEncoder uses special string values to represent NaN, Infinity and -Infinity values for float and double values, but JsonDecoder does not accept these string values. This change adds support for these special values to JsonDecoder.
Similar PR for the Rust SDK: #3051 |
I see that the implementation here also supports |
|
fyi: looks like the C++ implementations also uses the literals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Avro spec doesn't mention how these special cases are handled in JSON
Indeed. I think we should fix that AVRO-4025.
Perhaps we could add some tests to demonstrate the current behavior (the de-facto standard) of schema / JsonEncoder, and them document the behavior into the spec. I will try to have a PR for that soon.
Indeed. But "Except for unions, the JSON encoding is the same as is used to encode field default values (in schema)", so I think they are essentially the same (and SHOULD have the same behavior). https://avro.apache.org/docs/1.11.1/specification/_print/#json-encoding |
The same PR for C# #3070. We should specify the accepted strings. NaN, Infinity, -Infinity makes sense, however if if we need to support INF and -INF and/or case insensitivity, we should add all the supprted strings to the doc. I added tests for all of those cases. |
…Infinity" This is what the Java SDK (via Jackson library) supports (#3066). This is what the C# SDK also would support (#3070) Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
…Infinity" This is what the Java SDK (via Jackson library) supports (#3066). This is what the C# SDK also would support (#3070) Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
…Infinity" This is what the Java SDK (via Jackson library) supports (#3066). This is what the C# SDK also would support (#3070) Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
…Infinity" This is what the Java SDK (via Jackson library) supports (#3066). This is what the C# SDK also would support (#3070) Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
…g numbers with Java and C# (#3073) * AVRO-4024: [Rust] Improve the error messages when parsing unknown String into Value::Float/Double Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * AVRO-4024: [Rust] Accept only "Nan", "INF", "-INF", "Infinity" and "-Infinity" This is what the Java SDK (via Jackson library) supports (#3066). This is what the C# SDK also would support (#3070) Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> --------- Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
…g numbers with Java and C# (#3073) * AVRO-4024: [Rust] Improve the error messages when parsing unknown String into Value::Float/Double Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * AVRO-4024: [Rust] Accept only "Nan", "INF", "-INF", "Infinity" and "-Infinity" This is what the Java SDK (via Jackson library) supports (#3066). This is what the C# SDK also would support (#3070) Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> --------- Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> (cherry picked from commit dffc13a)
…g numbers with Java and C# (#3073) * AVRO-4024: [Rust] Improve the error messages when parsing unknown String into Value::Float/Double Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * AVRO-4024: [Rust] Accept only "Nan", "INF", "-INF", "Infinity" and "-Infinity" This is what the Java SDK (via Jackson library) supports (apache/avro#3066). This is what the C# SDK also would support (apache/avro#3070) Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> --------- Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Hello, Do you know when this pull request will be merged because it would fix a data deserialization problem with an entity containing the NaN value that i have? Thanks |
What is the purpose of the change
JsonEncoder uses special string values to represent NaN, Infinity and -Infinity values for float and double values, but JsonDecoder does not accept these string values. This change adds support for these special values to JsonDecoder.
Verifying this change
This change added tests and can be verified as follows:
NaN
for float fieldsNaN
for double fieldsInfinity
for float fieldsInfinity
for double fields-Infinity
for float fields-Infinity
for double fieldsStdDeserializer
Documentation
NaN
,Infinity
and-Infinity
)JsonEncoder
/JsonDecoder
resemble the behavior of Jackson