jecsand838 commented on code in PR #8433:
URL: https://github.com/apache/arrow-rs/pull/8433#discussion_r2376986569


##########
arrow-avro/src/codec.rs:
##########
@@ -1324,8 +1329,26 @@ impl<'a> Maker<'a> {
                     (None, _) => {}
                 }
                 if !t.attributes.additional.is_empty() {
+                    let mut is_duration = false;
                     for (k, v) in &t.attributes.additional {
-                        field.metadata.insert(k.to_string(), v.to_string());
+                        let key = k.to_string();
+                        if matches!(field.codec, Codec::Int64) && key == 
"arrowDurationUnit" {
+                            let unit = match v.as_str() {
+                                Some("second") => TimeUnit::Second,
+                                Some("millisecond") => TimeUnit::Millisecond,
+                                Some("microsecond") => TimeUnit::Microsecond,
+                                Some("nanosecond") => TimeUnit::Nanosecond,
+                                other => {
+                                    return Err(ArrowError::SchemaError(format!(
+                                        "Unknown arrowDurationUnit value: 
{other:?}"
+                                    )))
+                                }
+                            };
+                            field.codec = Codec::Duration(unit);
+                            is_duration = true;
+                        } else {
+                            field.metadata.insert(key, v.to_string());
+                        }

Review Comment:
   Now we can move this up into `match (t.attributes.logical_type, &mut 
field.codec)` with the other logical types.
   
   ```suggestion
                    field.metadata.insert(k.to_string(), v.to_string());
   ```
   
   i.e. 
   
   ```rust
                   match (t.attributes.logical_type, &mut field.codec) {
                       (Some("decimal"), c @ Codec::Binary) => {
                           let (prec, sc, _) = 
parse_decimal_attributes(&t.attributes, None, false)?;
                           *c = Codec::Decimal(prec, Some(sc), None);
                       }
                       (Some("date"), c @ Codec::Int32) => *c = Codec::Date32,
                       (Some("time-millis"), c @ Codec::Int32) => *c = 
Codec::TimeMillis,
                       (Some("time-micros"), c @ Codec::Int64) => *c = 
Codec::TimeMicros,
                       (Some("timestamp-millis"), c @ Codec::Int64) => {
                           *c = Codec::TimestampMillis(true)
                       }
                       (Some("timestamp-micros"), c @ Codec::Int64) => {
                           *c = Codec::TimestampMicros(true)
                       }
                       (Some("local-timestamp-millis"), c @ Codec::Int64) => {
                           *c = Codec::TimestampMillis(false)
                       }
                       (Some("local-timestamp-micros"), c @ Codec::Int64) => {
                           *c = Codec::TimestampMicros(false)
                       }
                       (Some("uuid"), c @ Codec::Utf8) => *c = Codec::Uuid,
                       #[cfg(feature = "avro_custom_types")]
                       (Some("arrow.duration-nanos"), c @ Codec::Int64) =>  *c 
= Codec::DurationNano,
                       #[cfg(feature = "avro_custom_types")]
                       (Some("arrow.duration-micros"), c @ Codec::Int64) =>  *c 
= Codec::DurationMilcros,
                       #[cfg(feature = "avro_custom_types")]
                       (Some("arrow.duration-millis"), c @ Codec::Int64) =>  *c 
= Codec::DurationMillis,
                       #[cfg(feature = "avro_custom_types")]
                       (Some("arrow.duration-seconds"), c @ Codec::Int64) => *c 
= Codec::DurationSeconds,
                       (Some(logical), _) => {
                           // Insert unrecognized logical type into metadata map
                           field.metadata.insert("logicalType".into(), 
logical.into());
                       }
                       (None, _) => {}
                   }
                   
   ```



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

Reply via email to