Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

AVRO-2885: [Java] better check int vs float value #2401

Merged
merged 1 commit into from
Aug 17, 2023

Conversation

clesaec
Copy link
Contributor

@clesaec clesaec commented Jul 28, 2023

What is the purpose of the change

AVRO-2885 : check non int value on JsonDecoder (accept only real int or float value as 1.0, when conversion to int doesn't modify the value.

Verifying this change

One new unit test TestJsonDecoder.testIntWithError; to ensure that value -1.2 to read an int will throw an error.

Documentation

  • Does this pull request introduce a new feature? (no)
  • If yes, how is the feature documented? (not applicable)

@github-actions github-actions bot added the Java Pull Requests for Java binding label Jul 28, 2023
@KalleOlaviNiemitalo
Copy link
Contributor

What's the behaviour if you encode 1.2 to Avro binary format using a record schema with a floating-point field, and then decode it with a reader schema that has an int field? Based on Schema Resolution, I'd expect that to be an error: "int is promotable to long, float, or double" but not vice versa. If that indeed is an error, then it makes sense that decoding an int from JSON 1.2 should likewise be an error.

@clesaec
Copy link
Contributor Author

clesaec commented Jul 31, 2023

Indeed, with binary decoder, it sends an AvroTypeException, "Found float, expecting int".
With this JIRA; it's also the case for json decoder. Float value 1.2 generate an error when trying to put it in an avro int field; while 1 or 1.0 json value will succeed to be translated in 1 int value.

@clesaec clesaec merged commit ff0a4d5 into apache:master Aug 17, 2023
12 checks passed
RanbirK pushed a commit to RanbirK/avro that referenced this pull request May 13, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Java Pull Requests for Java binding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants