jecsand838 commented on code in PR #8349: URL: https://github.com/apache/arrow-rs/pull/8349#discussion_r2365968500
########## arrow-avro/src/reader/record.rs: ########## @@ -700,6 +1012,65 @@ impl Decoder { "Default for enum must be a symbol".to_string(), )), }, + Self::Union(fields, type_ids, offsets, encodings, encoding_counts, None) => { + if encodings.is_empty() { + return Err(ArrowError::InvalidArgumentError( + "Union default cannot be applied to empty union".to_string(), + )); + } + let type_id = fields + .iter() + .nth(0) + .map(|(type_id, _)| type_id) + .unwrap_or(0_i8); + type_ids.push(type_id); + offsets.push(encoding_counts[0]); + encodings[0].append_default(lit)?; + encoding_counts[0] += 1; + Ok(()) + } + Self::Union( + fields, + type_ids, + offsets, + encodings, + encoding_counts, + Some(union_resolution), + ) => match &mut union_resolution.kind { + UnionResolvedKind::Both { .. } => { + if encodings.is_empty() { + return Err(ArrowError::InvalidArgumentError( + "Union default cannot be applied to empty union".to_string(), + )); + } + let type_id = fields + .iter() + .nth(0) + .map(|(type_id, _)| type_id) + .unwrap_or(0_i8); + type_ids.push(type_id); + offsets.push(encoding_counts[0]); + encodings[0].append_default(lit)?; + encoding_counts[0] += 1; + Ok(()) + } + UnionResolvedKind::ToSingle { target } => target.append_default(lit), + UnionResolvedKind::FromSingle { + target_reader_index, + .. + } => { + let type_id = fields Review Comment: @scovich There's definitely some redundancy here. I tried to abstract it as much as I could without a refactor. I'm leaving these branches separate because the spec is clear there's two different types of resolution as play and I'm unsure how Sparse Unions will fit in here. I planned to follow-up on this. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org