Closed
Description
Avro 1.12.0 specifies that UUID logical types annotates to either String or Fixed 16.
The example below serialized the UUID to a String and not a Fixed 16
#[derive(Debug, Serialize, Deserialize)]
struct Comment {
id: Uuid,
}
impl AvroSchema for Comment {
fn get_schema() -> Schema {
Schema::parse_str(
r#"{
"type" : "record",
"name" : "Comment",
"fields" : [ {
"name" : "id",
"type" : {
"type" : "fixed",
"size" : 16,
"logicalType" : "uuid",
"name": "FixedUUID" // if we remove the name attribute schema parsing fail. The name attribute is not in avro 1.12.0 specification
}
} ]
}"#,
)
.expect("Invalid Comment Avro schema")
}
}
let payload = Comment {
id: "de2df598-9948-4988-b00a-a41c0e287398".parse().unwrap(),
};
let mut buffer = Vec::new();
SpecificSingleObjectWriter::<Comment>::with_capacity(10)
.unwrap()
.write_ref(&payload, &mut buffer)
.unwrap();Do you plan to support it in the near future?
Metadata
Metadata
Assignees
Labels
No labels
Activity
martin-g commentedon Nov 14, 2024
I will try to take a look next week!
Any help is welcome! Providing a PR will make sure it is supported in nearest future! ;-)
Issue #53: Add the test to the suite to prevent regressions
martin-g commentedon Nov 19, 2024
Added the test case to the suite - #55
It works just fine locally.
I guess it has been fixed with #9
Issue #53: Add the test to the suite to prevent regressions
Issue #53: Add the test to the suite to prevent regressions (#55)
Tipnos commentedon Nov 21, 2024
I had a look a the test you added, it checks that it serializes successfully but doesn't check the payload content/size to validate that uuid is encoded as 16 bytes.
I just hex dump the content of your test, the payload length is 47 bytes instead of 26.
Why 26:
In the actual 47 bytes, the UUID takes 37 bytes which is its number of characters.
martin-g commentedon Nov 21, 2024
This deserves a new issue.
The bug here is thatThis was not correct. The issue is somewhere else.AvroSchemaderived Schema does not support logical types at all at the moment ...martin-g commentedon Nov 21, 2024
The problem here is that
SpecificSingleObjectWriter::<Comment>::with_capacity(10)?.write_ref(&payload, &mut buffer)uses Serde and Uuid's serde support serializes it to String, i.e. it callsfn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error>and without support for external Schema there is no way for the Avro impl to know that it should createapache_avro::types::Value::Fixedinstead ofapache_avro::types::Value::Stringand this leads to 37 bytes instead of 16.If you have idea how to tell Serde to use an external Schema I'll be glad to explore it!
Otherwise I'd suggest to use the avro way.
Issue #53 - Panic to get the stacktrace of an intermittent test failure
Issue #71 - Use `serial_test` for the test from issue #53
Issue #71 - Use `serial_test` for the test from issue #53
Issue #71 - Use `serial_test` for the test from issue #53 (#72)