-
Notifications
You must be signed in to change notification settings - Fork 34
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
Open
roofdiver
wants to merge
10
commits into
apache:main
Choose a base branch
from
roofdiver:failing-test-byte-deserialization-issue-285
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all 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
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
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,112 @@ | ||
use apache_avro_test_helper::TestResult; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Deserialize, PartialEq, Serialize)] | ||
struct ExampleByteArray { | ||
#[serde(with = "apache_avro::serde_avro_bytes_opt")] | ||
data_bytes: Option<Vec<u8>>, | ||
description: Option<String>, | ||
} | ||
|
||
#[derive(Deserialize, Serialize)] | ||
struct ExampleByteArrayFiltered { | ||
description: Option<String>, | ||
} | ||
|
||
#[test] | ||
fn avro_rs_285_bytes_deserialization_round_trip() -> TestResult { | ||
// define schema | ||
let raw_schema = r#" | ||
{ | ||
"type": "record", | ||
"name": "SimpleRecord", | ||
"fields": [ | ||
{"name": "data_bytes", "type": ["null", "bytes"], "default": null}, | ||
{"name": "description", "type": ["null", "string"], "default": null} | ||
] | ||
} | ||
"#; | ||
|
||
let schema = apache_avro::Schema::parse_str(raw_schema)?; | ||
|
||
let records = vec![ | ||
ExampleByteArray { | ||
data_bytes: Some(vec![1, 2, 3, 4, 5]), | ||
description: Some("First record".to_string()), | ||
}, | ||
ExampleByteArray { | ||
data_bytes: None, | ||
description: Some("Second record".to_string()), | ||
}, | ||
ExampleByteArray { | ||
data_bytes: Some(vec![10, 20, 30]), | ||
description: None, | ||
}, | ||
]; | ||
|
||
// serialize records to Avro binary format with schema | ||
let mut writer = apache_avro::Writer::new(&schema, Vec::new()); | ||
for record in &records { | ||
writer.append_ser(record)?; | ||
} | ||
|
||
let avro_data = writer.into_inner()?; | ||
|
||
// deserialize Avro binary data back into ExampleByteArray structs | ||
let reader = apache_avro::Reader::new(&avro_data[..])?; | ||
let deserialized_records: Vec<ExampleByteArray> = reader | ||
.map(|value| apache_avro::from_value::<ExampleByteArray>(&value.unwrap()).unwrap()) | ||
.collect(); | ||
|
||
assert_eq!(records, deserialized_records); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn avro_rs_285_bytes_deserialization_filtered_round_trip() -> TestResult { | ||
let raw_schema = r#" | ||
{ | ||
"type": "record", | ||
"name": "SimpleRecord", | ||
"fields": [ | ||
{"name": "data_bytes", "type": ["null", "bytes"], "default": null}, | ||
{"name": "description", "type": ["null", "string"], "default": null} | ||
] | ||
} | ||
"#; | ||
|
||
let schema = apache_avro::Schema::parse_str(raw_schema)?; | ||
|
||
let records = vec![ | ||
ExampleByteArray { | ||
data_bytes: Some(vec![1, 2, 3, 4, 5]), | ||
description: Some("First record".to_string()), | ||
}, | ||
ExampleByteArray { | ||
data_bytes: None, | ||
description: Some("Second record".to_string()), | ||
}, | ||
ExampleByteArray { | ||
data_bytes: Some(vec![10, 20, 30]), | ||
description: None, | ||
}, | ||
]; | ||
|
||
// serialize records to Avro binary format with schema | ||
let mut writer = apache_avro::Writer::new(&schema, Vec::new()); | ||
for record in &records { | ||
writer.append_ser(record)?; | ||
} | ||
|
||
let avro_data = writer.into_inner()?; | ||
|
||
// deserialize Avro binary data back into ExampleByteArrayFiltered structs | ||
let reader = apache_avro::Reader::new(&avro_data[..])?; | ||
let deserialized_records: Vec<ExampleByteArrayFiltered> = reader | ||
.map(|value| apache_avro::from_value::<ExampleByteArrayFiltered>(&value.unwrap()).unwrap()) | ||
.collect(); | ||
|
||
assert_eq!(records.len(), deserialized_records.len()); | ||
|
||
Ok(()) | ||
} |
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.