mzabaluev-flarion commented on code in PR #9237:
URL: https://github.com/apache/arrow-rs/pull/9237#discussion_r2712893496
##########
arrow-avro/src/codec.rs:
##########
@@ -1529,23 +1529,77 @@ impl<'a> Maker<'a> {
Ok(dt)
}
(writer_non_union, Schema::Union(reader_variants)) => {
- let promo = self.find_best_promotion(
- writer_non_union,
- reader_variants.as_slice(),
- namespace,
- );
- let Some((reader_index, promotion)) = promo else {
- return Err(ArrowError::SchemaError(
- "Writer schema does not match any reader union
branch".to_string(),
- ));
- };
- let mut dt = self.parse_type(reader_schema, namespace)?;
- dt.resolution = Some(ResolutionInfo::Union(ResolvedUnion {
- writer_to_reader: Arc::from(vec![Some((reader_index,
promotion))]),
- writer_is_union: false,
- reader_is_union: true,
- }));
- Ok(dt)
+ let null_position = reader_variants
+ .iter()
+ .position(|x| x ==
&Schema::TypeName(TypeName::Primitive(PrimitiveType::Null)));
+ if let (2, Some(null_idx)) = (reader_variants.len(),
null_position) {
+ let non_null_idx = 1 - null_idx;
+ let non_null_branch = &reader_variants[non_null_idx];
+ let mut dt =
+ self.make_data_type(writer_non_union,
Some(non_null_branch), namespace)?;
+ dt.nullability = Some(if null_idx == 0 {
+ Nullability::NullFirst
+ } else {
+ Nullability::NullSecond
+ });
+ #[cfg(feature = "avro_custom_types")]
+ if let Some(nb) = dt.nullability {
+ Self::propagate_nullability_into_ree(&mut dt, nb);
+ }
Review Comment:
```suggestion
let nullability = if null_idx == 0 {
Nullability::NullFirst
} else {
Nullability::NullSecond
};
#[cfg(feature = "avro_custom_types")]
Self::propagate_nullability_into_ree(&mut dt,
nullability);
dt.nullability = Some(nullability);
```
--
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]