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


##########
arrow-avro/src/codec.rs:
##########
@@ -356,6 +356,56 @@ impl AvroDataType {
             | Codec::DurationMicros
             | Codec::DurationMillis
             | Codec::DurationSeconds => 
AvroLiteral::Long(parse_json_i64(default_json, "long")?),
+            #[cfg(feature = "avro_custom_types")]
+            Codec::Int8 | Codec::Int16 => {
+                let i = parse_json_i64(default_json, "int")?;
+                if i < i32::MIN as i64 || i > i32::MAX as i64 {
+                    return Err(ArrowError::SchemaError(format!(
+                        "Default int {i} out of i32 range"
+                    )));
+                }
+                AvroLiteral::Int(i as i32)
+            }
+            #[cfg(feature = "avro_custom_types")]
+            Codec::UInt8 | Codec::UInt16 => {
+                let i = parse_json_i64(default_json, "int")?;
+                if i < 0 || i > i32::MAX as i64 {
+                    return Err(ArrowError::SchemaError(format!(
+                        "Default unsigned int {i} out of range"
+                    )));
+                }
+                AvroLiteral::Int(i as i32)
+            }
+            #[cfg(feature = "avro_custom_types")]
+            Codec::UInt32 | Codec::Date64 | Codec::TimeNanos | 
Codec::TimestampSecs(_) => {
+                AvroLiteral::Long(parse_json_i64(default_json, "long")?)

Review Comment:
   > Shouldn't UInt32 also reject negative numbers 🤔
   
   100%. I ended up splitting `UInt32` out from the shared arm (`Date64` | 
`TimeNanos` | `TimestampSecs`) and added explicit validation for `UInt32` 
defaults.
   
   There are some bigger improvements we can make to the default values logic, 
but they are outside the scope of this PR imo. 



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