martin-g commented on code in PR #2394:
URL: https://github.com/apache/avro/pull/2394#discussion_r1277421056
##########
lang/rust/avro/src/schema.rs:
##########
@@ -4865,4 +4867,128 @@ mod tests {
Ok(())
}
+
+ #[test]
+ fn test_avro_3814_schema_resolution_failure() -> TestResult {
+ // Define a reader schema: a nested record with an optional field.
+ let reader_schema = json!(
+ {
+ "type": "record",
+ "name": "MyOuterRecord",
+ "fields": [
+ {
+ "name": "inner_record",
+ "type": [
+ "null",
+ {
+ "type": "record",
+ "name": "MyRecord",
+ "fields": [
+ {"name": "a", "type": "string"}
+ ]
+ }
+ ],
+ "default": null
+ }
+ ]
+ }
+ );
+
+ // Define a writer schema: a nested record with an optional field,
which
+ // may optionally contain an enum.
+ let writer_schema = json!(
+ {
+ "type": "record",
+ "name": "MyOuterRecord",
+ "fields": [
+ {
+ "name": "inner_record",
+ "type": [
+ "null",
+ {
+ "type": "record",
+ "name": "MyRecord",
+ "fields": [
+ {"name": "a", "type": "string"},
+ {
+ "name": "b",
+ "type": [
+ "null",
+ {
+ "type": "enum",
+ "name": "MyEnum",
+ "symbols": ["A", "B", "C"],
+ "default": "C"
+ }
+ ],
+ "default": null
+ },
+ ]
+ }
+ ]
+ }
+ ],
+ "default": null
+ }
+ );
+
+ // Use different structs to represent the "Reader" and the "Writer"
+ // to mimick two different versions of a producer & consumer
application.
+ #[derive(Serialize, Deserialize, Debug)]
+ struct MyInnerRecordReader {
+ a: String,
+ }
+
+ #[derive(Serialize, Deserialize, Debug)]
+ struct MyRecordReader {
+ inner_record: Option<MyInnerRecordReader>,
+ }
+
+ #[derive(Serialize, Deserialize, Debug)]
+ enum MyEnum {
+ A,
+ B,
+ C,
+ }
+
+ #[derive(Serialize, Deserialize, Debug)]
+ struct MyInnerRecordWriter {
+ a: String,
+ b: Option<MyEnum>,
+ }
+
+ #[derive(Serialize, Deserialize, Debug)]
+ struct MyRecordWriter {
+ inner_record: Option<MyInnerRecordWriter>,
+ }
+
+ let s = MyRecordWriter {
+ inner_record: Some(MyInnerRecordWriter {
+ a: "foo".to_string(),
+ b: None,
+ }),
+ };
+
+ // Serialize using the writer schema (newer).
Review Comment:
Why `newer` ?
The writer schema is the one used to create the datum (the binary).
The reader schema is a modified one that is used to "migrate" the datum from
the old to the new schema.
So, I think `writer` is `old` and `reader` is `new`.
##########
lang/rust/avro/src/types.rs:
##########
@@ -377,11 +377,16 @@ impl Value {
}
}
+ /// Validates the value against the provided schema.
+ ///
+ /// Arguments:
+ /// * `schema_resolution` - whether schema resolution rules should be
applied when validating the `value`.
Review Comment:
Actually `types::resolve()` is supposed to be used for schema resolution. At
least according to its Rustdoc.
So maybe `schema::find_schema_with_known_schemata()` wrongly uses
`validate_internal()` ?!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]