JosephLenton commented on code in PR #2916:
URL: https://github.com/apache/iceberg-rust/pull/2916#discussion_r4554496197


##########
crates/iceberg/src/spec/values/serde.rs:
##########
@@ -473,8 +485,25 @@ pub(crate) mod _serde {
                 },
                 RawLiteralEnum::String(v) => match ty {
                     Type::Primitive(PrimitiveType::String) => 
Ok(Some(Literal::string(v))),
+                    // apache-avro deserializes a UUID as a hyphenated string.
+                    // UUID values read via `Value` (i.e. 
`read_data_files_from_avro`), land here.
+                    // The hyphenated restriction matches behaviour with Java.
+                    Type::Primitive(PrimitiveType::Uuid) => 
Hyphenated::from_str(&v)
+                        .map(|hyphenated_uuid| 
Some(Literal::uuid(hyphenated_uuid.into_uuid())))
+                        .map_err(|_| {
+                            invalid_err_with_reason(
+                                "string",
+                                "UUID must be a hyphenated 8-4-4-4-12 string",
+                            )
+                        }),
                     _ => Err(invalid_err("string")),
                 },
+                // `Fixed` is only built when writing, so that apache-avro 
gets a fixed value.
+                // Avro fixed values are read back as `Bytes`, and uuid values 
as `String` or `Bytes`.
+                RawLiteralEnum::Fixed(_) => Err(invalid_err_with_reason(

Review Comment:
   The code path is wonky, but correct.
   
   The issue is `serde_json` writes out Fixed and Bytes as the same thing. An 
array of bytes.
   
   When we read it back, the values fall into the List path, because the reader 
doesn't know which one it is. This is obviously not ideal, however I haven't 
found any issues with it.
   
   If it helps:
    - the Json format written out is unchanged,
    - `test_datum_uuid_converts_to_json_byte_array` and 
`test_json_16_byte_array_converts_to_datum_uuid` cover the JSON round trip.
   
   I'm happy to add more tests to prove this is working.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to