Copilot commented on code in PR #506:
URL: https://github.com/apache/hudi-rs/pull/506#discussion_r2657119639
##########
crates/core/src/avro_to_arrow/arrow_array_reader.rs:
##########
@@ -857,49 +857,42 @@ fn resolve_string(v: &Value) ->
ArrowResult<Option<String>> {
match v {
Value::String(s) => Ok(Some(s.clone())),
Value::Bytes(bytes) => String::from_utf8(bytes.to_vec())
- .map_err(|e| AvroError::new(AvroDetails::ConvertToUtf8(e)))
+ .map_err(|e| AvroError::new(AvroErrorDetails::ConvertToUtf8(e)))
.map(Some),
Value::Enum(_, s) => Ok(Some(s.clone())),
Value::Null => Ok(None),
- other => Err(AvroError::new(AvroDetails::GetString(other.clone()))),
+ other => Err(AvroError::new(AvroErrorDetails::GetString(
+ other.clone().into(),
+ ))),
}
.map_err(|e| SchemaError(format!("expected resolvable string : {e:?}")))
}
-fn resolve_u8(v: &Value) -> AvroResult<u8> {
- let int = match v {
- Value::Int(n) => Ok(Value::Int(*n)),
- Value::Long(n) => Ok(Value::Int(*n as i32)),
- other => Err(AvroError::new(AvroDetails::GetU8(other.clone()))),
- }?;
- if let Value::Int(n) = int {
- if n >= 0 && n <= u8::MAX as i32 {
- return Ok(n as u8);
- }
- }
+fn resolve_u8(v: &Value) -> Option<u8> {
+ let v = match v {
+ Value::Union(_, inner) => inner.as_ref(),
+ _ => v,
+ };
- Err(AvroError::new(AvroDetails::GetU8(int)))
+ match v {
+ Value::Int(n) => u8::try_from(*n).ok(),
+ Value::Long(n) => u8::try_from(*n).ok(),
+ _ => None,
+ }
}
Review Comment:
The function signature changed from returning `AvroResult<u8>` to
`Option<u8>`, which loses error information about why conversion failed (e.g.,
value out of range vs. wrong type). Consider whether callers need to
distinguish between these failure modes, or if silent failure is acceptable for
this use case.
--
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]