-
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-4024: [Rust] support nan/inf/-inf as float/double default #3051
Conversation
The "field default values" table at https://avro.apache.org/docs/1.11.1/specification/#schema-record does not mention that the default value for the "float,double" Avro types could be specified as a JSON string, so, this seems a new feature to me. |
Co-authored-by: Xiangjin <[email protected]> Signed-off-by: xxchan <[email protected]>
Thanks for your reply
Therefore, I would say this is not a "new feature", but it's vagueness in the spec. We should fix the spec instead of the Rust implementation. I just created a separate Jira ticket to update the spec https://issues.apache.org/jira/browse/AVRO-4025 |
The code you linked to is in the Java implementation of Avro IDL. The Java code that parses Avro schemas from JSON does not allow For Avro IDL, the Java implementation seems to expect So, this part of the Avro IDL specification at https://avro.apache.org/docs/1.11.1/idl-language/#default-values
fails to describe the de-facto support for those non-JSON syntaxes. Now if you change the Avro specification to allow |
More specific link: avro/lang/java/avro/src/main/java/org/apache/avro/Schema.java Lines 1763 to 1765 in 42c54e6
|
Thanks for these information! This problem seems more complex than I expected. Let me do more research on it. |
@KalleOlaviNiemitalo I've tested with the java lib. And final String schemaString = "{\"type\" : \"record\", \"name\" : \"R\",\n"
+ " \"fields\" : [ \n {\"name\" : \"f\", \"type\" : \"float\", \"default\": \"NaN\"}]}";
final Schema schema = new Schema.Parser().parse(schemaString); Note that this is handled inside jackason:
Anyway, thanks for pointing out that Avro IDL is a different thing. I should have tested with the java lib directly at the beginning :) |
@xxchan Did you intentionally disable "Maintainers are allowed to edit this pull request." ? |
@martin-g It seems that if a PR is created from a fork living under an organisation (rather than an individual) it's not possible to allow edits by maintainers: https://github.com/orgs/community/discussions/5634 🤦 So I just invited you to our fork, so that you can commit directly. Thank you! |
I will do the improvements in a follow up! |
/// So they are represented in JSON as strings. | ||
fn parse_special_float(s: &str) -> Option<f32> { | ||
match s.trim().to_ascii_lowercase().as_str() { | ||
"nan" | "+nan" | "-nan" => Some(f32::NAN), |
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.
Signed-off-by: xxchan <[email protected]> Co-authored-by: Xiangjin <[email protected]> (cherry picked from commit 7701526)
What is the purpose of the change
As title
[AVRO-4024] [Rust]: Fix default value support for double and float as "NaN", "Infinity" and "-Infinity" - ASF JIRA
Verifying this change
CI must pass
Documentation