nathaniel-d-ef commented on code in PR #8298:
URL: https://github.com/apache/arrow-rs/pull/8298#discussion_r2341109237


##########
arrow-avro/src/writer/encoder.rs:
##########
@@ -171,15 +246,111 @@ impl<'a> FieldEncoder<'a> {
                 DataType::LargeBinary => {
                     
Encoder::LargeBinary(BinaryEncoder(array.as_binary::<i64>()))
                 }
+                DataType::FixedSizeBinary(len) => {
+                    // Decide between Avro `fixed` (raw bytes) and `uuid` 
logical string
+                    // based on Field metadata, mirroring schema generation 
rules.
+                    let arr = array
+                        .as_any()
+                        .downcast_ref::<FixedSizeBinaryArray>()
+                        .ok_or_else(|| {
+                            ArrowError::SchemaError("Expected 
FixedSizeBinaryArray".into())
+                        })?;
+                    let md = field.metadata();
+                    let is_uuid = md.get("logicalType").is_some_and(|v| v == 
"uuid")
+                        || (*len == 16
+                        && md.get("ARROW:extension:name").is_some_and(|v| v == 
"uuid"));
+                    if is_uuid {
+                        if *len != 16 {
+                            return Err(ArrowError::InvalidArgumentError(
+                                "logicalType=uuid requires 
FixedSizeBinary(16)".into(),
+                            ));
+                        }
+                        Encoder::Uuid(UuidEncoder(arr))
+                    } else {
+                        Encoder::Fixed(FixedEncoder(arr))
+                    }
+                }
                 DataType::Timestamp(TimeUnit::Microsecond, _) => 
Encoder::Timestamp(LongEncoder(
                     array.as_primitive::<TimestampMicrosecondType>(),
                 )),
+                DataType::Interval(unit) => match unit {
+                    IntervalUnit::MonthDayNano => {
+                        
Encoder::IntervalMonthDayNano(IntervalMonthDayNanoEncoder(
+                            array.as_primitive::<IntervalMonthDayNanoType>(),
+                        ))
+                    }
+                    IntervalUnit::YearMonth => {
+                        Encoder::IntervalYearMonth(IntervalYearMonthEncoder(
+                            array.as_primitive::<IntervalYearMonthType>(),
+                        ))
+                    }
+                    IntervalUnit::DayTime => 
Encoder::IntervalDayTime(IntervalDayTimeEncoder(
+                        array.as_primitive::<IntervalDayTimeType>(),
+                    )),
+                }
+                DataType::Duration(_) => {
+                    return Err(ArrowError::NotYetImplemented(
+                        "Avro writer: Arrow Duration(TimeUnit) has no standard 
Avro mapping; cast to Interval(MonthDayNano) to use Avro 'duration'".into(),
+                    ));
+                }
+                // Composite or mismatched types under scalar plan
+                DataType::List(_)
+                | DataType::LargeList(_)
+                | DataType::Map(_, _)
+                | DataType::Struct(_)
+                | DataType::Dictionary(_, _)
+                | DataType::Decimal32(_, _)
+                | DataType::Decimal64(_, _)
+                | DataType::Decimal128(_, _)
+                | DataType::Decimal256(_, _) => {
+                    return Err(ArrowError::SchemaError(format!(
+                        "Avro scalar site incompatible with Arrow type: {:?}",
+                        array.data_type()
+                    )))
+                }
                 other => {
                     return Err(ArrowError::NotYetImplemented(format!(
                         "Avro scalar type not yet supported: {other:?}"
                     )));
                 }
             },
+            FieldPlan::Decimal {size} => match array.data_type() {

Review Comment:
   Yeah, good point. I think having it first is logical.



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