-
Notifications
You must be signed in to change notification settings - Fork 38
Commiting Unit Test with Failing Byte Array Deserialization #293
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
Merged
martin-g
merged 10 commits into
apache:main
from
roofdiver:failing-test-byte-deserialization-issue-285
Oct 28, 2025
+278
−0
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
14d7828
Commiting Unit Test with Failing Byte Array Deserialization
roofdiver 543ccf1
updating readme with solution to byte array deserialization issues
roofdiver 7ad5b2a
adding recommended changes to example and unit tests
roofdiver 0a19913
removing example avro file
roofdiver c56215a
Minor cleanup of the new bytes IT test
martin-g 0fc19a2
Move the new documentation about serde byte arrays from README.md to …
martin-g 40def76
Derive PartialEq to ExampleByteArray
martin-g c3d0349
Update README
martin-g 935e666
Fix grammar
martin-g 8e0b9fa
Fix grammar
martin-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| use apache_avro::{from_value, Reader}; | ||
| use serde::{Serialize,Deserialize}; | ||
| use std::fs::File; | ||
| use std::io::BufReader; | ||
|
|
||
|
|
||
| //UPDATE: For byte deserialization to work, you need to add the serde attribute #[serde(with = "apache_avro::serde_avro_bytes_opt")] in this case. There are a lot of other options as well documented in bytes.rs | ||
|
|
||
|
|
||
| // This is the schema that was used to write | ||
| // schema = { | ||
| // "type": "record", | ||
| // "name": "SimpleRecord", | ||
| // "fields": [ | ||
| // {"name": "data_bytes", "type": ["null", "bytes"], "default": None}, | ||
| // {"name": "description", "type": ["null", "string"], "default": None} | ||
| // ] | ||
| // } | ||
|
|
||
|
|
||
| // Here is an example struct that matches the schema, and another with filtered out byte array field | ||
| // The reason this is very useful is that in extremely large deeply nested avro files, structs mapped to grab fields of interest in deserialization | ||
| // is really effecient and effective. The issue is that when I'm trying to deserialize a byte array field I get the error below no matter how I approach. | ||
| // Bytes enum under value doesn't implement Deserialize in that way so I can't just make it a Value::Bytes | ||
|
|
||
| #[derive(Debug, Deserialize, Serialize, Clone)] | ||
|
|
||
roofdiver marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| struct ExampleByteArray{ | ||
|
|
||
|
|
||
| //update I have discovered that this is the fix | ||
| #[serde(with = "apache_avro::serde_avro_bytes_opt")] | ||
| data_bytes: Option<Vec<u8>>, | ||
| description: Option<String> | ||
| } | ||
|
|
||
|
|
||
| #[derive(Debug, Deserialize, Serialize, Clone)] | ||
| struct ExampleByteArrayFiltered{ | ||
| description: Option<String> | ||
| } | ||
|
|
||
| #[test] | ||
| fn avro_rs_285_bytes_deserialization_failure(){ | ||
|
|
||
| // Load the example file into reader | ||
| let file = File::open("./tests/avro-rs-285-bytes_deserialization.avro".to_string()).unwrap(); | ||
| let reader = BufReader::new(file); | ||
| let avro_reader = Reader::new(reader).unwrap(); | ||
|
|
||
|
|
||
| // attempt to deserialize into struct with byte array field | ||
| for value in avro_reader{ | ||
| let value = value.unwrap(); | ||
| let deserialized = from_value::<ExampleByteArray>(&value).unwrap(); | ||
| println!("{:?}", deserialized); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| #[test] | ||
| fn avro_rs_285_bytes_deserialization_pass_when_filtered(){ | ||
|
|
||
| // Load the example file into reader | ||
| let file = File::open("./tests/avro-rs-285-bytes_deserialization.avro".to_string()).unwrap(); | ||
roofdiver marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let reader = BufReader::new(file); | ||
| let avro_reader = Reader::new(reader).unwrap(); | ||
|
|
||
| // attempt to deserialize into struct with byte array field filtered out, this will be successful | ||
| for value in avro_reader{ | ||
| let value = value.unwrap(); | ||
| let deserialized = from_value::<ExampleByteArrayFiltered>(&value).unwrap(); | ||
| println!("{:?}", deserialized); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.